|
@ -88,6 +88,14 @@ public class WlyyTokenGranter implements TokenGranter {
|
|
|
requestFactory,
|
|
|
userDetailsService
|
|
|
));
|
|
|
tokenGranters.put(IhealthDoctorOwnerCodeTokenGranter.GRANT_TYPE,
|
|
|
new IhealthDoctorOwnerCodeTokenGranter(
|
|
|
authenticationManager,
|
|
|
tokenServices,
|
|
|
clientDetailsService,
|
|
|
requestFactory,
|
|
|
userDetailsService
|
|
|
));
|
|
|
}
|
|
|
|
|
|
public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
|
|
@ -388,6 +396,54 @@ public class WlyyTokenGranter implements TokenGranter {
|
|
|
if (!userDetails.isAccountNonLocked()) {
|
|
|
throw new InvalidGrantException("User account is locked");
|
|
|
}
|
|
|
// parameters.put("password",userDetails.getPassword());
|
|
|
Authentication userAuth = new UsernamePasswordAuthenticationToken(username,userDetails.getPassword(), this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()));
|
|
|
((AbstractAuthenticationToken) userAuth).setDetails(parameters);
|
|
|
OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
|
|
|
return new OAuth2Authentication(storedOAuth2Request, userAuth);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static class IhealthDoctorOwnerCodeTokenGranter extends AbstractTokenGranter {
|
|
|
private static final String GRANT_TYPE = "ihealthDcotor";
|
|
|
|
|
|
private final AuthenticationManager authenticationManager;
|
|
|
private final UserDetailsService userDetailsService;
|
|
|
private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
|
|
|
|
|
|
public IhealthDoctorOwnerCodeTokenGranter(AuthenticationManager authenticationManager,
|
|
|
AuthorizationServerTokenServices tokenServices,
|
|
|
ClientDetailsService clientDetailsService,
|
|
|
OAuth2RequestFactory requestFactory,
|
|
|
UserDetailsService userDetailsService) {
|
|
|
this(authenticationManager, tokenServices, clientDetailsService, requestFactory, userDetailsService, GRANT_TYPE);
|
|
|
}
|
|
|
|
|
|
protected IhealthDoctorOwnerCodeTokenGranter(AuthenticationManager authenticationManager,
|
|
|
AuthorizationServerTokenServices tokenServices,
|
|
|
ClientDetailsService clientDetailsService,
|
|
|
OAuth2RequestFactory requestFactory,
|
|
|
UserDetailsService userDetailsService,
|
|
|
String grantType) {
|
|
|
super(tokenServices, clientDetailsService, requestFactory, grantType);
|
|
|
this.authenticationManager = authenticationManager;
|
|
|
this.userDetailsService = userDetailsService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
|
|
|
|
|
|
Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
|
|
|
String username = parameters.get("username");
|
|
|
|
|
|
SaltUser userDetails = (SaltUser)userDetailsService.loadUserByUsername(username);
|
|
|
if (!userDetails.isEnabled()) {
|
|
|
throw new InvalidGrantException("User is disabled");
|
|
|
}
|
|
|
if (!userDetails.isAccountNonLocked()) {
|
|
|
throw new InvalidGrantException("User account is locked");
|
|
|
}
|
|
|
|
|
|
// parameters.put("password",userDetails.getPassword());
|
|
|
Authentication userAuth = new UsernamePasswordAuthenticationToken(username,userDetails.getPassword(), this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()));
|
|
|
((AbstractAuthenticationToken) userAuth).setDetails(parameters);
|