Skip to content

Instantly share code, notes, and snippets.

@ugurcemozturk
Last active December 6, 2017 11:56
Show Gist options
  • Save ugurcemozturk/3061c1ef65c9b540eca0e7cdea9e9fb5 to your computer and use it in GitHub Desktop.
Save ugurcemozturk/3061c1ef65c9b540eca0e7cdea9e9fb5 to your computer and use it in GitHub Desktop.
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