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));
}
}
}
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));
}
}
}
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);
}
}
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();
}
}
}
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));
}
}
}
}
Aggregations