Answer the question
In order to leave comments, you need to log in
Two types of authorization. Login, password + oAuth2 in spring security. How to do?
There is a Spring boot project with authorization: login + password.
@Configuration
@EnableWebSecurity
//@EnableOAuth2Sso
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthUserService authUserService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/admin", "/user", "/new-event", "/dict/**", "/data/**").authenticated() // только для зарегистрированных
.antMatchers("/**", "/static/**", "/publish/**").permitAll() // общий доступ
.anyRequest().authenticated() // только для зарегистрированных
.and();
http.formLogin()
.loginPage("/login")
.failureUrl("/login?error")
.permitAll()
.and();
http.logout()
.permitAll()
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.invalidateHttpSession(true);
}
@Override
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder.userDetailsService(authUserService)
.passwordEncoder(NoOpPasswordEncoder.getInstance());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question