Search in sources :

Example 41 with AMConsoleException

use of com.sun.identity.console.base.model.AMConsoleException 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 42 with AMConsoleException

use of com.sun.identity.console.base.model.AMConsoleException 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)

Example 43 with AMConsoleException

use of com.sun.identity.console.base.model.AMConsoleException in project OpenAM by OpenRock.

the class EntityResourceOfferingModelImpl method assignService.

/**
     * Assigns service to an entity.
     *
     * @param universalId Universal ID of the entity.
     * @throws AMConsoleException if service cannot be assigned.
     */
public void assignService(String universalId) throws AMConsoleException {
    String[] params = { universalId, AMAdminConstants.DISCOVERY_SERVICE };
    logEvent("ATTEMPT_IDENTITY_ASSIGN_SERVICE", params);
    try {
        AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
        amid.assignService(AMAdminConstants.DISCOVERY_SERVICE, Collections.EMPTY_MAP);
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { universalId, AMAdminConstants.DISCOVERY_SERVICE, strError };
        logEvent("SSO_EXCEPTION_IDENTITY_ASSIGN_SERVICE", paramsEx);
        throw new AMConsoleException(strError);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { universalId, AMAdminConstants.DISCOVERY_SERVICE, strError };
        logEvent("IDM_EXCEPTION_IDENTITY_ASSIGN_SERVICE", paramsEx);
        throw new AMConsoleException(strError);
    }
}
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)

Example 44 with AMConsoleException

use of com.sun.identity.console.base.model.AMConsoleException in project OpenAM by OpenRock.

the class ServicesSelectViewBean method handleButton2Request.

/**
     * Handles assigned button request.
     *
     * @param event Request invocation event.
     */
public void handleButton2Request(RequestInvocationEvent event) throws ModelControlException {
    submitCycle = true;
    String serviceName = (String) getDisplayFieldValue(ATTR_SERVICE_LIST);
    String universalId = (String) getPageSessionAttribute(EntityEditViewBean.UNIVERSAL_ID);
    EntitiesModel model = (EntitiesModel) getModel();
    if (model.hasUserAttributeSchema(serviceName)) {
        unlockPageTrailForSwapping();
        fowardToAddServiceViewBean(model, universalId, serviceName);
    } else {
        try {
            model.assignService(universalId, serviceName, Collections.EMPTY_MAP);
            forwardToEntityServiceViewBean();
        } catch (AMConsoleException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
            forwardTo();
        }
    }
}
Also used : AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) EntitiesModel(com.sun.identity.console.idm.model.EntitiesModel)

Example 45 with AMConsoleException

use of com.sun.identity.console.base.model.AMConsoleException in project OpenAM by OpenRock.

the class EntitiesModelImpl method validateAttributes.

private void validateAttributes(Map values) throws AMConsoleException {
    for (Iterator iter = values.keySet().iterator(); iter.hasNext(); ) {
        String attrName = (String) iter.next();
        if (requiredAttributeNames.keySet().contains(attrName)) {
            if (!reqValidator.validate((Set) values.get(attrName))) {
                AttributeSchema as = (AttributeSchema) requiredAttributeNames.get(attrName);
                String serviceName = as.getServiceSchema().getServiceName();
                String expMsg = getLocalizedString("entity-values-missing");
                ResourceBundle rb = getServiceResourceBundle(serviceName);
                String[] arg = { Locale.getString(rb, as.getI18NKey(), debug) };
                throw new AMConsoleException(MessageFormat.format(expMsg, (Object[]) arg));
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) ResourceBundle(java.util.ResourceBundle) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)701 Map (java.util.Map)255 Set (java.util.Set)206 HashMap (java.util.HashMap)193 HashSet (java.util.HashSet)148 SSOException (com.iplanet.sso.SSOException)126 Iterator (java.util.Iterator)122 List (java.util.List)97 SMSException (com.sun.identity.sm.SMSException)83 ArrayList (java.util.ArrayList)78 AMPropertySheet (com.sun.identity.console.base.AMPropertySheet)76 IdRepoException (com.sun.identity.idm.IdRepoException)58 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)47 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)46 AMIdentity (com.sun.identity.idm.AMIdentity)44 SAMLv2Model (com.sun.identity.console.federation.model.SAMLv2Model)41 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)41 CCActionTable (com.sun.web.ui.view.table.CCActionTable)40 TreeSet (java.util.TreeSet)39 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)38