Войти как гость - PullRequest
       42

Войти как гость

0 голосов
/ 31 мая 2018

Я использую Spirng Security для авторизации.С основного сайта у меня есть две ссылки - одна на форму авторизации для зарегистрированных пользователей, вторая на страницу, где пользователь будет авторизован как гость.Я не мог найти решение, как войти в систему как гость с пружинной безопасностью (без ввода пароля, но все еще вошел в систему как GUEST ROLE. Есть ли что-то, что нужно изменить в классе WebSecurityConfigurerAdapter, или мне нужно как-то добавить имя пользователя и пароль для "GUEST""в методе POST и отправить на авторизацию?

WebSecurityConfigurerAdapter

@Configuration
@EnableWebSecurity
public class ConsumingRestAppSecurityConfig extends WebSecurityConfigurerAdapter {@Autowired
private DataSource securityDataSource;
@Autowired
private SimpleAuthenticationSuccessHandler successHandler;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth.jdbcAuthentication().dataSource(securityDataSource);
    }

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests()
.antMatchers("/loggedIn/guest").hasRole("GUEST")
.antMatchers("/loggedIn/user").hasRole("USER")
.antMatchers("/loggedIn/admin").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.successHandler(successHandler)
.loginPage("/logginProcess/login-page")
.loginProcessingUrl("/logginProcess/authenticateTheUser")
.permitAll()
.and()
.logout()
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/home/access-denied");
}

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/home/**", "/");
}}
...