Search in sources :

Example 46 with IdRepoException

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

the class EntitiesModelImpl method getAttributeValues.

/**
     * Returns attribute values of an entity object.
     *
     * @param universalId Universal ID of the entity.
     * @param bCreate true for creation page
     * @return attribute values of an entity object.
     * @throws AMConsoleException if object cannot located.
     */
public Map getAttributeValues(String universalId, boolean bCreate) throws AMConsoleException {
    String[] param = { universalId, "*" };
    logEvent("ATTEMPT_READ_IDENTITY_ATTRIBUTE_VALUE", param);
    try {
        AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
        Map tempMap = new CaseInsensitiveHashMap();
        tempMap.putAll(amid.getAttributes());
        validateUserStatusEntry(tempMap);
        Map values = new HashMap();
        String agentType = null;
        boolean webJ2EEagent = false;
        Set agentTypes = amid.getAttribute("AgentType");
        if ((agentTypes != null) && !agentTypes.isEmpty()) {
            agentType = (String) agentTypes.iterator().next();
            webJ2EEagent = agentType.equals(AgentConfiguration.AGENT_TYPE_J2EE) || agentType.equals(AgentConfiguration.AGENT_TYPE_WEB) || agentType.equals(AgentConfiguration.AGENT_TYPE_AGENT_AUTHENTICATOR);
        }
        Set attributeSchemas = getAttributeSchemas(amid.getType().getName(), agentType, bCreate);
        Set attributeNames = new HashSet();
        for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
            AttributeSchema as = (AttributeSchema) iter.next();
            String name = as.getName();
            if (!tempMap.containsKey(name)) {
                values.put(name, Collections.EMPTY_SET);
            } else {
                if (webJ2EEagent && name.equals(AGENT_ATTRIBUTE_LIST)) {
                    Set newValues = new HashSet();
                    Set temp = (Set) tempMap.get(name);
                    for (Iterator i = temp.iterator(); i.hasNext(); ) {
                        String val = (String) i.next();
                        if (val.startsWith(AGENT_ROOT_URL)) {
                            val = val.substring(AGENT_ROOT_URL.length());
                        }
                        newValues.add(val);
                    }
                    values.put(name, newValues);
                } else {
                    values.put(name, tempMap.get(name));
                }
            }
            attributeNames.add(name);
        }
        for (Iterator iter = values.keySet().iterator(); iter.hasNext(); ) {
            String name = (String) iter.next();
            if (!attributeNames.contains(name)) {
                iter.remove();
            }
        }
        logEvent("SUCCEED_READ_IDENTITY_ATTRIBUTE_VALUE", param);
        return values;
    } catch (IdRepoException e) {
        String[] paramsEx = { universalId, "*", getErrorString(e) };
        logEvent("IDM_EXCEPTION_READ_IDENTITY_ATTRIBUTE_VALUE", paramsEx);
        debug.warning("EntitiesModelImpl.getAttributeValues", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SMSException e) {
        String[] paramsEx = { universalId, "*", getErrorString(e) };
        logEvent("SMS_EXCEPTION_READ_IDENTITY_ATTRIBUTE_VALUE", paramsEx);
        debug.warning("EntitiesModelImpl.getAttributeValues", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] paramsEx = { universalId, "*", getErrorString(e) };
        logEvent("SSO_EXCEPTION_READ_IDENTITY_ATTRIBUTE_VALUE", paramsEx);
        debug.warning("EntitiesModelImpl.getAttributeValues", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Example 47 with IdRepoException

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

the class EntitiesModelImpl method getMembership.

/**
     * Returns membership of an entity.
     *
     * @param realmName Name of Realm.
     * @param universalId Universal ID of the entity.
     * @param type Type of membership.
     * @return membership of an entity.
     * @throws AMConsoleException if members cannot be returned.
     */
public Set getMembership(String realmName, String universalId, String type) throws AMConsoleException {
    String[] params = { universalId, type };
    logEvent("ATTEMPT_READ_IDENTITY_MEMBERSHIP", params);
    try {
        AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
        Set results = amid.getMemberships(IdUtils.getType(type));
        logEvent("SUCCEED_READ_IDENTITY_MEMBERSHIP", params);
        return results;
    } catch (SSOException e) {
        String[] paramsEx = { universalId, type, getErrorString(e) };
        logEvent("SSO_EXCEPTION_READ_IDENTITY_MEMBERSHIP", paramsEx);
        debug.warning("EntitiesModelImpl.getMembership", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (IdRepoException e) {
        String[] paramsEx = { universalId, type, getErrorString(e) };
        logEvent("IDM_EXCEPTION_READ_IDENTITY_MEMBERSHIP", paramsEx);
        debug.warning("EntitiesModelImpl.getMembership", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 48 with IdRepoException

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

the class EntitiesModelImpl method addMembers.

/**
     * Adds an entities to a membership.
     *
     * @param universalId Universal ID of the membership.
     * @param names Set of Universal ID of entities.
     * @throws AMConsoleException if membership addition fails.
     */
public void addMembers(String universalId, Set names) throws AMConsoleException {
    if ((names == null) || names.isEmpty()) {
        throw new AMConsoleException("entities.members.add.no.selection.message");
    }
    SSOToken ssoToken = getUserSSOToken();
    String currentId = "";
    try {
        AMIdentity amid = IdUtils.getIdentity(ssoToken, universalId);
        String[] params = new String[2];
        params[0] = universalId;
        for (Iterator iter = names.iterator(); iter.hasNext(); ) {
            String id = (String) iter.next();
            AMIdentity amidentity = IdUtils.getIdentity(ssoToken, id);
            currentId = id;
            params[1] = id;
            logEvent("ATTEMPT_ADD_IDENTITY_MEMBER", params);
            amid.addMember(amidentity);
            logEvent("SUCCEED_ADD_IDENTITY_MEMBER", params);
        }
    } catch (SSOException e) {
        String[] paramsEx = { universalId, currentId, getErrorString(e) };
        logEvent("SSO_EXCEPTION_ADD_IDENTITY_MEMBER", paramsEx);
        debug.warning("EntitiesModelImpl.addMembers", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (IdRepoException e) {
        String[] paramsEx = { universalId, currentId, getErrorString(e) };
        logEvent("IDM_EXCEPTION_ADD_IDENTITY_MEMBER", paramsEx);
        debug.warning("EntitiesModelImpl.addMembers", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 49 with IdRepoException

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

the class EntitiesModelImpl method modifyEntity.

/**
     * Modifies profile of entity.
     *
     * @param realmName Name of Realm.
     * @param universalId Universal ID of the entity.
     * @param values Map of attribute name to set of attribute values.
     * @throws AMConsoleException if entity cannot be located or modified.
     */
public void modifyEntity(String realmName, String universalId, Map values) throws AMConsoleException {
    if ((values != null) && !values.isEmpty()) {
        String attrNames = AMAdminUtils.getString(values.keySet(), ",", false);
        try {
            AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
            validateAttributes(amid, values);
            String[] param = { universalId, attrNames };
            logEvent("ATTEMPT_MODIFY_IDENTITY_ATTRIBUTE_VALUE", param);
            String entityName = amid.getName();
            String idType = amid.getType().getName();
            // values must be merged
            if (amid.getType().equals(IdType.AGENT) && values.containsKey(AGENT_ATTRIBUTE_LIST) && (amid.getAttribute(AGENT_ATTRIBUTE_LIST) != null)) {
                Set newDeviceKeyValue = (Set) values.get(AGENT_ATTRIBUTE_LIST);
                Set origDeviceKeyValue = amid.getAttribute(AGENT_ATTRIBUTE_LIST);
                for (Iterator items = origDeviceKeyValue.iterator(); items.hasNext(); ) {
                    String olValue = (String) items.next();
                    String[] olValues = olValue.split("=");
                    // Check if this attribute exists in new values
                    boolean found = false;
                    for (Iterator nt = newDeviceKeyValue.iterator(); nt.hasNext(); ) {
                        String ntValue = (String) nt.next();
                        String[] ntValues = ntValue.split("=");
                        if (ntValues[0].equalsIgnoreCase(olValues[0])) {
                            if ((ntValues.length > 1) && (ntValues[1].trim().length() == 0)) {
                                // Remove the entry
                                nt.remove();
                            }
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        newDeviceKeyValue.add(olValue);
                    }
                }
            }
            beforeModify(idType, entityName, values);
            amid.setAttributes(values);
            amid.store();
            logEvent("SUCCEED_MODIFY_IDENTITY_ATTRIBUTE_VALUE", param);
        } catch (IdRepoException e) {
            String[] paramsEx = { universalId, attrNames, getErrorString(e) };
            logEvent("IDM_EXCEPTION_MODIFY_IDENTITY_ATTRIBUTE_VALUE", paramsEx);
            if (e.getErrorCode().equals(IdRepoErrorCode.LDAP_EXCEPTION)) {
                throw new AMConsoleException(e.getConstraintViolationDetails());
            }
            throw new AMConsoleException(getErrorString(e));
        } catch (SSOException e) {
            String[] paramsEx = { universalId, attrNames, getErrorString(e) };
            logEvent("SSO_EXCEPTION_MODIFY_IDENTITY_ATTRIBUTE_VALUE", paramsEx);
            throw new AMConsoleException(getErrorString(e));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 50 with IdRepoException

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

the class EntitiesModelImpl method setServiceAttributeValues.

/**
     * Set service attribute values to an entity.
     *
     * @param universalId Universal ID of the entity.
     * @param serviceName Name of service name.
     * @param values Attribute values.
     * @throws AMConsoleException if values cannot be set.
     */
public void setServiceAttributeValues(String universalId, String serviceName, Map values) throws AMConsoleException {
    if ((values != null) && !values.isEmpty()) {
        try {
            String[] params = { universalId, serviceName };
            logEvent("ATTEMPT_IDENTITY_WRITE_SERVICE_ATTRIBUTE_VALUES", params);
            AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
            amid.modifyService(serviceName, values);
            logEvent("SUCCEED_IDENTITY_WRITE_SERVICE_ATTRIBUTE_VALUES", params);
        } catch (SSOException e) {
            String[] paramsEx = { universalId, serviceName, getErrorString(e) };
            logEvent("SSO_EXCEPTION_IDENTITY_WRITE_SERVICE_ATTRIBUTE_VALUES", paramsEx);
            debug.warning("EntitiesModelImpl.setServiceAttributeValues", e);
            throw new AMConsoleException(getErrorString(e));
        } catch (IdRepoException e) {
            String[] paramsEx = { universalId, serviceName, getErrorString(e) };
            logEvent("IDM_EXCEPTION_IDENTITY_WRITE_SERVICE_ATTRIBUTE_VALUES", paramsEx);
            debug.warning("EntitiesModelImpl.setServiceAttributeValues", e);
            throw new AMConsoleException(getErrorString(e));
        }
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

IdRepoException (com.sun.identity.idm.IdRepoException)403 SSOException (com.iplanet.sso.SSOException)275 Set (java.util.Set)224 AMIdentity (com.sun.identity.idm.AMIdentity)221 HashSet (java.util.HashSet)183 Map (java.util.Map)121 Iterator (java.util.Iterator)118 SSOToken (com.iplanet.sso.SSOToken)112 HashMap (java.util.HashMap)110 SMSException (com.sun.identity.sm.SMSException)103 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)96 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)67 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)58 IdType (com.sun.identity.idm.IdType)57 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)51 CLIException (com.sun.identity.cli.CLIException)48 IOutput (com.sun.identity.cli.IOutput)45 IdSearchResults (com.sun.identity.idm.IdSearchResults)44 IdSearchControl (com.sun.identity.idm.IdSearchControl)39 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)35