Skip to content

Instantly share code, notes, and snippets.

@tansuaksan
Last active March 18, 2021 00:07
Show Gist options
  • Save tansuaksan/3de9f7939fa6cf9939fde478bdc598bc to your computer and use it in GitHub Desktop.
Save tansuaksan/3de9f7939fa6cf9939fde478bdc598bc to your computer and use it in GitHub Desktop.
Custom Authentication Via JSON login request in Spring Security
@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;
}
}
@ravichechani961
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment