Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2018 00:42
Show Gist options
  • Save anonymous/8935730334e2b3eb07c8d5ba85d07a19 to your computer and use it in GitHub Desktop.
Save anonymous/8935730334e2b3eb07c8d5ba85d07a19 to your computer and use it in GitHub Desktop.
public class JWTLoginFilter extends AbstractAuthenticationProcessingFilter {
protected JWTLoginFilter(String url, AuthenticationManager authManager) {
super(new AntPathRequestMatcher(url));
setAuthenticationManager(authManager);
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
return getAuthenticationManager().authenticate(
new UsernamePasswordAuthenticationToken(
request.getParameter("username"),
request.getParameter("password"),
Collections.emptyList()
)
);
}
@Override
protected void successfulAuthentication(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain,
Authentication auth) throws IOException, ServletException {
response.setStatus(200);
TokenAuthenticationService.addAuthentication(response, auth.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment