Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.keycloak.authentication.picketlink;
  
 
 import java.util.List;
 import java.util.Map;

AuthenticationProvider, which delegates authentication to picketlink

Author(s):
Marek Posolda
 
 
     private static final Logger logger = Logger.getLogger(PicketlinkAuthenticationProvider.class);
 
 
     public PicketlinkAuthenticationProvider(IdentityManagerProvider identityManagerProvider) {
         this. = identityManagerProvider;
     }
 
     @Override
     public String getName() {
     }
 
     @Override
     public List<StringgetAvailableOptions() {
         return .;
     }
 
     @Override
     public AuthUser getUser(RealmModel realmMap<StringStringconfigurationString usernamethrows AuthenticationProviderException {
         IdentityManager identityManager = getIdentityManager(realm);
 
         try {
             User picketlinkUser = BasicModel.getUser(identityManagerusername);
             return picketlinkUser == null ? null : new AuthUser(picketlinkUser.getId(), picketlinkUser.getLoginName(), getName())
                     .setName(picketlinkUser.getFirstName(), picketlinkUser.getLastName())
                     .setEmail(picketlinkUser.getEmail())
                     .setProviderName(getName());
         } catch (IdentityManagementException ie) {
             throw convertIDMException(ie);
         }
     }
 
     @Override
     public String registerUser(RealmModel realmMap<StringStringconfigurationString usernamethrows AuthenticationProviderException {
         IdentityManager identityManager = getIdentityManager(realm);
 
         try {
             User picketlinkUser = new User(username);
             identityManager.add(picketlinkUser);
             return picketlinkUser.getId();
         } catch (IdentityManagementException ie) {
             throw convertIDMException(ie);
         }
     }
 
     @Override
     public AuthProviderStatus validatePassword(RealmModel realmMap<StringStringconfigurationString usernameString passwordthrows AuthenticationProviderException {
         IdentityManager identityManager = getIdentityManager(realm);
 
         try {
             UsernamePasswordCredentials credential = new UsernamePasswordCredentials();
             credential.setUsername(username);
             credential.setPassword(new Password(password.toCharArray()));
             identityManager.validateCredentials(credential);
             if (credential.getStatus() == ..) {
                 return .;
             } else {
                 return .;
             }
         } catch (IdentityManagementException ie) {
             throw convertIDMException(ie);
         }
     }
 
     @Override
     public boolean updateCredential(RealmModel realmMap<StringStringconfigurationString usernameString passwordthrows AuthenticationProviderException {
         IdentityManager identityManager = getIdentityManager(realm);
 
         try {
            User picketlinkUser = BasicModel.getUser(identityManagerusername);
            if (picketlinkUser == null) {
                .debugf("User '%s' doesn't exists. Skip password update"username);
                return false;
            }
            identityManager.updateCredential(picketlinkUsernew Password(password.toCharArray()));
            return true;
        } catch (IdentityManagementException ie) {
            throw convertIDMException(ie);
        }
    }
    @Override
    public void close() {
    }
        return .getIdentityManager(realm);
    }
        Throwable realCause = ie;
        while (realCause.getCause() != null) {
            realCause = realCause.getCause();
        }
        // Use the message from the realCause
        return new AuthenticationProviderException(realCause.getMessage(), ie);
    }
New to GrepCode? Check out our FAQ X