Last active
March 18, 2021 00:07
-
-
Save tansuaksan/3de9f7939fa6cf9939fde478bdc598bc to your computer and use it in GitHub Desktop.
Custom Authentication Via JSON login request in Spring Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableWebSecurity | |
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests() | |
.antMatchers("/", "/login", "/logout").permitAll() | |
.anyRequest().authenticated() | |
.and().addFilterAt(customAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) | |
.formLogin().loginProcessingUrl("/login") | |
.and() | |
.csrf().disable(); | |
} | |
private CustomUsernamePasswordAuthenticationFilter customAuthenticationFilter() throws Exception { | |
CustomUsernamePasswordAuthenticationFilter filter = new CustomUsernamePasswordAuthenticationFilter(); | |
filter.setAuthenticationManager(authenticationManager()); | |
return filter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My requirement was to accept json body for login . Without this filter I was using formlogin and with success login, i was able to redirect on the oauth redirect URL configured at client Database. After this filter redirect stopped working . Any idea?