Skip to content

Instantly share code, notes, and snippets.

View tansuaksan's full-sized avatar

Tansu Aksan tansuaksan

View GitHub Profile
@tansuaksan
tansuaksan / SpringSecurityConfig.java
Last active March 18, 2021 00:07
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)
@tansuaksan
tansuaksan / CustomUsernamePasswordAuthenticationFilter.java
Last active January 12, 2023 07:58
Custom Authentication Via JSON login request in Spring Security
@Slf4j
public class CustomUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException(
"Authentication method not supported: " + request.getMethod());
}