|
@@ -24,6 +24,7 @@ import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.security.authentication.AuthenticationEventPublisher;
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
+import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
@@ -43,7 +44,6 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
*/
|
|
|
public class MobileAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
|
|
private static final String SPRING_SECURITY_FORM_MOBILE_KEY = "mobile";
|
|
|
- private AuthenticationEventPublisher eventPublisher = new MobileAuthenticationFilter.NullEventPublisher();
|
|
|
private AuthenticationEntryPoint authenticationEntryPoint = new MobileAuthenticationEntryPoint();
|
|
|
@Getter
|
|
|
@Setter
|
|
@@ -51,6 +51,9 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
|
|
@Getter
|
|
|
@Setter
|
|
|
private boolean postOnly = true;
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ private AuthenticationEventPublisher eventPublisher;
|
|
|
|
|
|
public MobileAuthenticationFilter() {
|
|
|
super(new AntPathRequestMatcher(SecurityConstants.MOBILE_TOKEN_URL, "POST"));
|
|
@@ -76,8 +79,13 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
|
|
|
|
|
setDetails(request, mobileAuthenticationToken);
|
|
|
|
|
|
+ Authentication authResult = null;
|
|
|
try {
|
|
|
- return this.getAuthenticationManager().authenticate(mobileAuthenticationToken);
|
|
|
+ authResult = this.getAuthenticationManager().authenticate(mobileAuthenticationToken);
|
|
|
+
|
|
|
+ logger.debug("Authentication success: " + authResult);
|
|
|
+ eventPublisher.publishAuthenticationSuccess(authResult);
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authResult);
|
|
|
|
|
|
} catch (Exception failed) {
|
|
|
SecurityContextHolder.clearContext();
|
|
@@ -93,7 +101,8 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
|
|
logger.error("authenticationEntryPoint handle error:{}", failed);
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ return authResult;
|
|
|
}
|
|
|
|
|
|
private String obtainMobile(HttpServletRequest request) {
|
|
@@ -104,15 +113,5 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
|
|
MobileAuthenticationToken authRequest) {
|
|
|
authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
|
|
|
}
|
|
|
-
|
|
|
- private static final class NullEventPublisher implements AuthenticationEventPublisher {
|
|
|
- @Override
|
|
|
- public void publishAuthenticationFailure(AuthenticationException exception, Authentication authentication) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void publishAuthenticationSuccess(Authentication authentication) {
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|