Search in sources :

Example 36 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class AMCommonNameGenerator method addFormats.

/**
     * Adds format by retrieving the globalization service
     * attributes to get the list of formats and add them
     * accordingly.
     *
     * @param realm Realm Name
     * @return map of locale to formats
     */
private Map addFormats(String realm) {
    Set values = null;
    Map map = null;
    try {
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignedServices();
        if (servicesFromIdRepo.contains(G11N_SERVICE_NAME)) {
            map = realmIdentity.getServiceAttributes(G11N_SERVICE_NAME);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(adminSSOToken, realm);
            map = orgCfgMgr.getServiceAttributes(G11N_SERVICE_NAME);
        }
    } catch (SSOException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    } catch (SMSException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    } catch (IdRepoException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    }
    if ((map != null) && !map.isEmpty()) {
        values = (Set) map.get(G11N_SERIVCE_COMMON_NAME_FORMAT);
    }
    if ((values == null) || values.isEmpty()) {
        if (serviceSchemaManager != null) {
            try {
                values = AMAdminUtils.getAttribute(serviceSchemaManager, SchemaType.ORGANIZATION, G11N_SERIVCE_COMMON_NAME_FORMAT);
            } catch (SMSException e) {
                debug.error("AMCommonNameGenerator.addFormats", e);
            }
        } else {
            debug.error("AMCommonNameGenerator.addFormats: " + "formats are not added because Console cannot get " + "an instance of service schema manager.");
        }
    }
    Map mapFormats = getFormatMap(values);
    synchronized (mapRealmToFormat) {
        mapRealmToFormat.put(realm, mapFormats);
    }
    return mapFormats;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class OATH method getIdentity.

/**
     * Gets the AMIdentity of a user with username equal to uName.
     *
     * @param uName username of the user to get.
     * @return The AMIdentity of user with username equal to uName or null
     * if error while trying to find user.
     */
private AMIdentity getIdentity(String uName) {
    AMIdentity theID = null;
    AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
    IdSearchControl idsc = new IdSearchControl();
    idsc.setRecursive(true);
    idsc.setAllReturnAttributes(true);
    // search for the identity
    Set<AMIdentity> results = Collections.EMPTY_SET;
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, uName, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results == null || results.isEmpty()) {
            throw new IdRepoException("OATH.getIdentity : User " + userName + " is not found");
        } else if (results.size() > 1) {
            throw new IdRepoException("OATH.getIdentity: More than one user found for the userName: " + userName);
        }
        theID = results.iterator().next();
    } catch (IdRepoException e) {
        debug.error("OATH.getIdentity: error searching Identities with username : " + userName, e);
    } catch (SSOException e) {
        debug.error("OATH.getIdentity: AuthOATH module exception : ", e);
    }
    return theID;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 38 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class Membership method userExists.

/** check if user exists */
private boolean userExists(String userID) throws IdRepoException, SSOException {
    AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
    IdSearchControl idsc = new IdSearchControl();
    idsc.setRecursive(true);
    idsc.setTimeOut(0);
    idsc.setAllReturnAttributes(true);
    // search for the identity
    Set results = Collections.EMPTY_SET;
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userID, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
    } catch (IdRepoException e) {
        if (debug.messageEnabled()) {
            debug.message("IdRepoException : Error searching " + " Identities with username : " + e.getMessage());
        }
    }
    return !results.isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException)

Example 39 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class Membership method loginUser.

private ModuleState loginUser(Callback[] callbacks) throws AuthLoginException {
    String password = null;
    Callback[] idCallbacks = new Callback[2];
    try {
        if (callbacks != null && callbacks.length == 0) {
            userName = (String) sharedState.get(getUserKey());
            password = (String) sharedState.get(getPwdKey());
            if (userName == null || password == null) {
                return ModuleState.LOGIN_START;
            }
            getCredentialsFromSharedState = true;
            NameCallback nameCallback = new NameCallback("dummy");
            nameCallback.setName(userName);
            idCallbacks[0] = nameCallback;
            PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
            passwordCallback.setPassword(password.toCharArray());
            idCallbacks[1] = passwordCallback;
        } else {
            idCallbacks = callbacks;
            //callbacks is not null
            userName = ((NameCallback) callbacks[0]).getName();
            password = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());
        }
        if (password == null || password.length() == 0) {
            if (debug.messageEnabled()) {
                debug.message("Membership.loginUser: Password is null/empty");
            }
            throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
        }
        //store username password both in success and failure case
        storeUsernamePasswd(userName, password);
        initAuthConfig();
        AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
        boolean success = idrepo.authenticate(idCallbacks);
        if (success) {
            validatedUserID = userName;
            return ModuleState.COMPLETE;
        } else {
            throw new AuthLoginException(amAuthMembership, "authFailed", null);
        }
    } catch (IdRepoException ex) {
        if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
            getCredentialsFromSharedState = false;
            return ModuleState.LOGIN_START;
        }
        if (debug.warningEnabled()) {
            debug.warning("idRepo Exception");
        }
        setFailureID(userName);
        throw new AuthLoginException(amAuthMembership, "authFailed", null, ex);
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) PasswordCallback(javax.security.auth.callback.PasswordCallback) InvalidPasswordException(com.sun.identity.authentication.spi.InvalidPasswordException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Example 40 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class ConfigMonitoring method getAgentGroups.

private void getAgentGroups(String realm) {
    String classMethod = "ConfigMonitoring.getAgentGroups: ";
    /*
         *  given a realm, search the AMIdentityRepository for
         *  IdType.AGENTGROUP.
         *  this is similar to AgentsModelImpl.java:getAgentGroupNames(...)
         */
    StringBuffer sb = new StringBuffer(classMethod);
    try {
        IdSearchControl isc = new IdSearchControl();
        isc.setMaxResults(0);
        // should use set value, but for now...
        isc.setTimeOut(3000);
        isc.setAllReturnAttributes(false);
        AMIdentityRepository airepo = new AMIdentityRepository(ssoToken, realm);
        IdSearchResults isr = airepo.searchIdentities(IdType.AGENTGROUP, "*", isc);
        // set of AMIdentitys
        Set results = isr.getSearchResults();
        sb = new StringBuffer("AgentGroups for realm ");
        sb.append(realm).append("; size = ").append(results.size()).append(":\n");
        for (Iterator it = results.iterator(); it.hasNext(); ) {
            AMIdentity aid = (AMIdentity) it.next();
            processAgentIdentity(aid, sb);
        }
        debug.error(classMethod + sb.toString());
    } catch (IdRepoException e) {
        debug.error(classMethod + "idrepo error getting agents: " + e.getMessage());
    } catch (SSOException e) {
        debug.error(classMethod + "sso error getting agents: " + e.getMessage());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdSearchControl(com.sun.identity.idm.IdSearchControl) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Aggregations

AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)138 IdRepoException (com.sun.identity.idm.IdRepoException)103 SSOException (com.iplanet.sso.SSOException)94 AMIdentity (com.sun.identity.idm.AMIdentity)85 Set (java.util.Set)82 HashSet (java.util.HashSet)58 SSOToken (com.iplanet.sso.SSOToken)56 IdSearchControl (com.sun.identity.idm.IdSearchControl)36 IdSearchResults (com.sun.identity.idm.IdSearchResults)36 Iterator (java.util.Iterator)32 CLIException (com.sun.identity.cli.CLIException)29 HashMap (java.util.HashMap)29 IdType (com.sun.identity.idm.IdType)28 Map (java.util.Map)27 IOutput (com.sun.identity.cli.IOutput)26 SMSException (com.sun.identity.sm.SMSException)24 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)20 List (java.util.List)13 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)12 Callback (javax.security.auth.callback.Callback)6