@@ -0,0 +1,2255 @@
+package com.github.sbugat.samplerest.web.security;%0D%0A%0D%0Aimport java.io.IOException;%0D%0A%0D%0Aimport javax.annotation.PostConstruct;%0D%0Aimport javax.inject.Inject;%0D%0Aimport javax.inject.Named;%0D%0Aimport javax.servlet.http.HttpServletRequest;%0D%0Aimport javax.servlet.http.HttpServletResponse;%0D%0A%0D%0Aimport org.springframework.security.authentication.AuthenticationManager;%0D%0Aimport org.springframework.security.authentication.AuthenticationServiceException;%0D%0Aimport org.springframework.security.authentication.UsernamePasswordAuthenticationToken;%0D%0Aimport org.springframework.security.core.Authentication;%0D%0Aimport org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;%0D%0A%0D%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0D%0A%0D%0A@Named%0D%0Apublic class JSONUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter %7B%0D%0A%0D%0A%09@Inject%0D%0A%09private LoginAuthenticationSuccessHandler loginAuthenticationSuccessHandler;%0D%0A%0D%0A%09@Inject%0D%0A%09private AuthenticationManager authenticationManagerBean;%0D%0A%0D%0A%09public JSONUsernamePasswordAuthenticationFilter() %7B%0D%0A%09%09setFilterProcessesUrl(%22/auth/login%22);%0D%0A%09%7D%0D%0A%0D%0A%09@PostConstruct%0D%0A%09public void postConstruct() %7B%0D%0A%09%09setAuthenticationManager(authenticationManagerBean);%0D%0A%09%09setAuthenticationSuccessHandler(loginAuthenticationSuccessHandler);%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) %7B%0D%0A%0D%0A%09%09if (!request.getMethod().equals(%22POST%22)) %7B%0D%0A%09%09%09throw new AuthenticationServiceException(%22Authentication method not supported: %22 + request.getMethod());%0D%0A%09%09%7D%0D%0A%0D%0A%09%09final UserData userData;%0D%0A%09%09try %7B%0D%0A%09%09%09final ObjectMapper mapper = new ObjectMapper();%0D%0A%09%09%09userData = mapper.readValue(request.getInputStream(), UserData.class);%0D%0A%09%09%7D catch (final IOException e) %7B%0D%0A%09%09%09throw new AuthenticationServiceException(%22Authentication method not supported: %22 + request.getMethod());%0D%0A%09%09%7D%0D%0A%0D%0A%09%09final UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(userData.username, userData.password);%0D%0A%09%09setDetails(request, authRequest);%0D%0A%09%09return this.getAuthenticationManager().authenticate(authRequest);%0D%0A%09%7D%0D%0A%0D%0A%09private static final class UserData %7B%0D%0A%0D%0A%09%09public String username;%0D%0A%09%09public String password;%0D%0A%09%7D%0D%0A%7D%0D%0A

Add username/password filter