Search in sources :

Example 1 with IdRepo

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

the class IdServicesImpl method setAttributes.

public void setAttributes(SSOToken token, IdType type, String name, Map attributes, boolean isAdd, String amOrgName, String amsdkDN, boolean isString) throws IdRepoException, SSOException {
    IdRepoException origEx = null;
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, amOrgName, name, attributes.keySet(), IdOperation.EDIT, type);
    if (type.equals(IdType.USER)) {
        IdRepoAttributeValidator attrValidator = IdRepoAttributeValidatorManager.getInstance().getIdRepoAttributeValidator(amOrgName);
        attrValidator.validateAttributes(attributes, IdOperation.EDIT);
    }
    // Get the list of plugins that service/edit the create operation.
    Set configuredPluginClasses = (attributes.containsKey("objectclass")) ? idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.SERVICE, type) : idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.EDIT, type);
    if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    IdRepo idRepo;
    while (it.hasNext()) {
        idRepo = (IdRepo) it.next();
        try {
            Map cMap = idRepo.getConfiguration();
            // do stuff to map attr names.
            Map mappedAttributes = mapAttributeNames(attributes, cMap);
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
                if (isString) {
                    idRepo.setAttributes(token, type, amsdkDN, mappedAttributes, isAdd);
                } else {
                    idRepo.setBinaryAttributes(token, type, amsdkDN, mappedAttributes, isAdd);
                }
            } else {
                if (isString) {
                    idRepo.setAttributes(token, type, name, mappedAttributes, isAdd);
                } else {
                    idRepo.setBinaryAttributes(token, type, name, mappedAttributes, isAdd);
                }
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (idRepo != null && DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl.setAttributes: " + "Unable to set attributes in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IdServicesImpl.setAttributes: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.setAttributes: " + "Unable to modify identity in the " + "following repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            // all the ds and this entry might exist in one of the other ds.
            if (!IdRepoErrorCode.UNABLE_FIND_ENTRY.equalsIgnoreCase(ide.getErrorCode()) || (origEx == null)) {
                origEx = ide;
            }
        }
    }
    if (noOfSuccess == 0) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdServicesImpl.setAttributes: " + "Unable to set attributes  for identity " + type.getName() + "::" + name + " in any configured data" + " store", origEx);
        }
        throw origEx;
    }
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException)

Example 2 with IdRepo

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

the class IdServicesImpl method changePassword.

public void changePassword(SSOToken token, IdType type, String name, String oldPassword, String newPassword, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
    String attrName = "userPassword";
    Set attrNames = new HashSet();
    attrNames.add(attrName);
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, amOrgName, name, attrNames, IdOperation.EDIT, type);
    if (type.equals(IdType.USER)) {
        IdRepoAttributeValidator attrValidator = IdRepoAttributeValidatorManager.getInstance().getIdRepoAttributeValidator(amOrgName);
        HashMap attributes = new HashMap();
        Set values = new HashSet();
        values.add(newPassword);
        attributes.put(attrName, values);
        attrValidator.validateAttributes(attributes, IdOperation.EDIT);
    }
    Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.EDIT, type);
    if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    IdRepoException origEx = null;
    IdRepo idRepo;
    while (it.hasNext()) {
        idRepo = (IdRepo) it.next();
        Map cMap = idRepo.getConfiguration();
        Set mappedAttributeNames = mapAttributeNames(attrNames, cMap);
        if ((mappedAttributeNames != null) && (!mappedAttributeNames.isEmpty())) {
            attrName = (String) mappedAttributeNames.iterator().next();
        }
        try {
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && (amsdkDN != null)) {
                idRepo.changePassword(token, type, amsdkDN, attrName, oldPassword, newPassword);
            } else {
                idRepo.changePassword(token, type, name, attrName, oldPassword, newPassword);
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl.changePassword: " + "Unable to change password in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IdServicesImpl.changePassword: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.changePassword: " + "Unable to change password " + "following repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            // all the ds and this entry might exist in one of the other ds.
            if (!ide.getErrorCode().equalsIgnoreCase(IdRepoErrorCode.UNABLE_FIND_ENTRY) || (origEx == null)) {
                origEx = ide;
            }
        }
    }
    if (noOfSuccess == 0) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdServicesImpl.changePassword: " + "Unable to change password  for identity " + type.getName() + "::" + name + " in any configured data" + " store", origEx);
        }
        throw origEx;
    }
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 3 with IdRepo

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

the class IdServicesImpl method assignService.

public void assignService(SSOToken token, IdType type, String name, String serviceName, SchemaType stype, Map attrMap, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
    IdRepoException origEx = null;
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, amOrgName, name, null, IdOperation.SERVICE, type);
    // Get the list of plugins that support the service operation.
    Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.SERVICE, type);
    if (configuredPluginClasses == null || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    IdRepo idRepo = null;
    while (it.hasNext()) {
        IdRepo repo = (IdRepo) it.next();
        Map cMap = repo.getConfiguration();
        try {
            Map mappedAttributes = mapAttributeNames(attrMap, cMap);
            if (repo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
                repo.assignService(token, type, amsdkDN, serviceName, stype, mappedAttributes);
            } else {
                repo.assignService(token, type, name, serviceName, stype, mappedAttributes);
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (idRepo != null && DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl.assignService: " + "Assign Services not supported for repository " + repo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IdServicesImpl.assignService: FatalException ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.assignService: " + "Unable to assign Service identity in " + "the following repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        }
    }
    if (noOfSuccess == 0) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdServicesImpl.assignService: " + "Unable to assign service for identity " + type.getName() + "::" + name + " in any configured data store ", origEx);
        }
        throw origEx;
    }
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException)

Example 4 with IdRepo

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

the class IdServicesImpl method setActiveStatus.

/*
    * (non-Javadoc)
    */
public void setActiveStatus(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN, boolean active) throws SSOException, IdRepoException {
    IdRepoException origEx = null;
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, amOrgName, name, null, IdOperation.EDIT, type);
    // First get the list of plugins that support the edit operation.
    Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.EDIT, type);
    if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    while (it.hasNext()) {
        IdRepo idRepo = (IdRepo) it.next();
        try {
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
                idRepo.setActiveStatus(token, type, amsdkDN, active);
            } else {
                idRepo.setActiveStatus(token, type, name, active);
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl:setActiveStatus: " + "Unable to set attributes in the following " + "repository" + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IsActive: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("Unable to setActiveStatus in the " + "following repository" + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            // the ds and this entry might exist in one of the other ds.
            if (!ide.getErrorCode().equalsIgnoreCase(IdRepoErrorCode.UNABLE_FIND_ENTRY) || (origEx == null)) {
                origEx = ide;
            }
        }
    }
    if (noOfSuccess == 0) {
        DEBUG.error("Unable to setActiveStatus for identity " + type.getName() + "::" + name + " in any configured " + "datastore", origEx);
        throw origEx;
    }
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException)

Example 5 with IdRepo

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

the class IdServicesImpl method delete.

/*
    * (non-Javadoc)
    */
public void delete(SSOToken token, IdType type, String name, String orgName, String amsdkDN) throws IdRepoException, SSOException {
    if (type.equals(IdType.REALM)) {
        deleteRealmIdentity(token, name, orgName);
        return;
    }
    IdRepoException origEx = null;
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, orgName, name, null, IdOperation.DELETE, type);
    // Get the list of plugins that support the delete operation.
    Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(orgName, IdOperation.DELETE, type);
    if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    if (!name.equalsIgnoreCase(IdConstants.ANONYMOUS_USER)) {
        noOfSuccess--;
    }
    IdRepo idRepo;
    while (it.hasNext()) {
        idRepo = (IdRepo) it.next();
        try {
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
                idRepo.delete(token, type, amsdkDN);
            } else {
                idRepo.delete(token, type, name);
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.delete: " + "Unable to delete identity in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IdServicesImpl.delete: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.delete: " + "Unable to delete identity in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            if (!ide.getErrorCode().equalsIgnoreCase(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
                origEx = ide;
            }
        }
    }
    if ((noOfSuccess <= 0) && (origEx != null)) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdServicesImpl.delete: " + "Unable to delete identity " + type.getName() + " :: " + name + " in any of the configured data stores", origEx);
        }
        throw origEx;
    }
    removeIdentityFromPrivileges(name, type, amsdkDN, orgName);
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException)

Aggregations

IdRepo (com.sun.identity.idm.IdRepo)34 HashSet (java.util.HashSet)30 IdRepoException (com.sun.identity.idm.IdRepoException)29 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)28 Iterator (java.util.Iterator)28 Set (java.util.Set)28 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)25 IdRepoFatalException (com.sun.identity.idm.IdRepoFatalException)19 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 AMHashMap (com.iplanet.am.sdk.AMHashMap)11 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)11 SMSException (com.sun.identity.sm.SMSException)11 SSOException (com.iplanet.sso.SSOException)10 LinkedHashMap (java.util.LinkedHashMap)8 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)7 DelegationException (com.sun.identity.delegation.DelegationException)6 IdRepoListener (com.sun.identity.idm.IdRepoListener)4 RepoSearchResults (com.sun.identity.idm.RepoSearchResults)3