Last active
December 6, 2017 11:56
-
-
Save ugurcemozturk/3061c1ef65c9b540eca0e7cdea9e9fb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
public JWTLoginFilter(String defaultFilterProcessesUrl, AuthenticationManager authManager) { | |
super(defaultFilterProcessesUrl); | |
setAuthenticationManager(authManager); | |
} | |
@Override | |
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { | |
AccountCredentials credentials = new ObjectMapper() | |
.readValue(request.getInputStream(), AccountCredentials.class); | |
return getAuthenticationManager().authenticate( | |
new UsernamePasswordAuthenticationToken( | |
credentials.getUsername(), | |
credentials.getPassword(), | |
emptyList() | |
)); | |
} | |
@Override | |
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { | |
TokenAuthenticationService.addAuth(response, authResult.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment