Search in sources :

Example 16 with AMIdentityRepository

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

the class EntitiesModelImpl method createEntity.

/**
     * Creates an entity.
     *
     * @param realmName Name of Realm.
     * @param entityName Name of Entity.
     * @param idType Type of Entity.
     * @param values Map of attribute name to Set of attribute values.
     * @throws AMConsoleException if entity cannot be created.
     */
public void createEntity(String realmName, String entityName, String idType, Map values) throws AMConsoleException {
    if (entityName.trim().length() == 0) {
        String msg = getLocalizedString("entities.missing.entityName");
        String[] param = { getLocalizedString(idType) };
        throw new AMConsoleException(MessageFormat.format(msg, (Object[]) param));
    }
    if (realmName == null) {
        realmName = "/";
    }
    validateAttributes(values);
    setAgentDefaultValues(values);
    try {
        String[] params = { entityName, idType, realmName };
        logEvent("ATTEMPT_IDENTITY_CREATION", params);
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        beforeCreate(idType, entityName, values);
        repo.createIdentity(IdUtils.getType(idType), entityName, values);
        logEvent("IDENTITY_CREATED", params);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] params = { entityName, idType, realmName, strError };
        logEvent("IDM_EXCEPTION_IDENTITY_CREATION", params);
        throw new AMConsoleException(strError);
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] params = { entityName, idType, realmName, strError };
        logEvent("SSO_EXCEPTION_IDENTITY_CREATION", params);
        throw new AMConsoleException(strError);
    }
}
Also used : AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 17 with AMIdentityRepository

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

the class EntitiesModelImpl method deleteEntities.

/**
     * Deletes entities.
     *
     * @param realmName Name of Realm.
     * @param names Name of Entities to be deleted.
     * @throws AMConsoleException if entity cannot be deleted.
     */
public void deleteEntities(String realmName, Set names) throws AMConsoleException {
    if ((names != null) && !names.isEmpty()) {
        String idNames = AMFormatUtils.toCommaSeparatedFormat(names);
        String[] params = { realmName, idNames };
        logEvent("ATTEMPT_DELETE_IDENTITY", params);
        try {
            AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
            repo.deleteIdentities(getAMIdentity(names));
            logEvent("SUCCEED_DELETE_IDENTITY", params);
        } catch (IdRepoException e) {
            String[] paramsEx = { realmName, idNames, getErrorString(e) };
            logEvent("IDM_EXCEPTION_DELETE_IDENTITY", paramsEx);
            throw new AMConsoleException(getErrorString(e));
        } catch (SSOException e) {
            String[] paramsEx = { realmName, idNames, getErrorString(e) };
            logEvent("SSO_EXCEPTION_DELETE_IDENTITY", paramsEx);
            throw new AMConsoleException(getErrorString(e));
        }
    }
}
Also used : AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 18 with AMIdentityRepository

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

the class IdRepoUtils method createUser.

public static AMIdentity createUser(String realm, String id, Map<String, Set<String>> properties) throws SSOException, IdRepoException {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    AMIdentityRepository amir = new AMIdentityRepository(adminToken, realm);
    Map<String, Set<String>> attrValues = new HashMap<String, Set<String>>();
    Set<String> set = new HashSet<String>();
    set.add(id);
    attrValues.put("givenname", set);
    attrValues.put("sn", set);
    attrValues.put("cn", set);
    attrValues.put("userpassword", set);
    if (properties != null) {
        attrValues.putAll(properties);
    }
    return amir.createIdentity(IdType.USER, id, attrValues);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) HashSet(java.util.HashSet)

Example 19 with AMIdentityRepository

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

the class MetaDataTest method deleteUser.

private void deleteUser(SSOToken adminToken) throws IdRepoException, SSOException {
    AMIdentityRepository amir = new AMIdentityRepository(adminToken, "/");
    Set<AMIdentity> identities = new HashSet<AMIdentity>();
    identities.add(testUser);
    amir.deleteIdentities(identities);
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) HashSet(java.util.HashSet)

Example 20 with AMIdentityRepository

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

the class PolicyEvaluatorTest method cleanup.

@AfterClass
public void cleanup() throws PolicyException, SSOException, IdRepoException {
    try {
        lc.logout();
    } catch (Exception e) {
    //ignore
    }
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    PolicyManager pm = new PolicyManager(adminToken, "/");
    pm.removePolicy(POLICY_NAME1);
    pm.removePolicy(POLICY_NAME2);
    pm.removePolicy(POLICY_NAME3);
    pm.removePolicy(POLICY_NAME4);
    AMIdentityRepository amir = new AMIdentityRepository(adminToken, "/");
    Set<AMIdentity> identities = new HashSet<AMIdentity>();
    identities.add(testGroup);
    identities.add(testUser);
    amir.deleteIdentities(identities);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) AfterClass(org.testng.annotations.AfterClass)

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