Created
February 16, 2018 00:42
-
-
Save anonymous/8935730334e2b3eb07c8d5ba85d07a19 to your computer and use it in GitHub Desktop.
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
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