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) |
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
@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()); | |
} |