All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.healthy.common.security.authentication.mobile.SmsCodeAuthenticationProvider Maven / Gradle / Ivy

There is a newer version: 1.2.1.RELEASE
Show newest version
package com.healthy.common.security.authentication.mobile;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * An {@link AuthenticationProvider} implementation that validates
 * {@link SmsCodeAuthenticationToken}s.
 * 

* Since the verification of the SMS verification code has been completed in the filter, * Here you can read the user information directly. * * @author xiaomingzhang */ public class SmsCodeAuthenticationProvider implements AuthenticationProvider { private MobileUserDetailsService userDetailsService; @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { SmsCodeAuthenticationToken token = (SmsCodeAuthenticationToken) authentication; UserDetails user = userDetailsService.loadUserByMobile((String) token.getPrincipal()); if (user == null) { throw new InternalAuthenticationServiceException("无法获取用户信息"); } SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(user, user.getAuthorities()); // You need to copy some information from the uncertified to the certified token authenticationResult.setDetails(token); return authenticationResult; } @Override public boolean supports(Class authentication) { return SmsCodeAuthenticationToken.class.isAssignableFrom(authentication); } public MobileUserDetailsService getUserDetailsService() { return userDetailsService; } public void setUserDetailsService(MobileUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy