use of com.sun.identity.idm.IdRepoFatalException in project OpenAM by OpenRock.
the class AMSDKRepo method setAttributes.
/**
* Sets the Attributes of the named identity. the single sign on
* token must have the necessary permission to set the attributes.
*
* @param token
* single sign on token for this operation.
* @param type
* type of the identity
* @param name
* name of the identity
* @param attributes
* attributes to set.
* @param isAdd
* should attributes values be added to existing values.
* @throws IdRepoException
* if there are repository related error conditions.
* @throws SSOException
* if user's single sign on token is invalid.
*/
public void setAttributes(SSOToken token, IdType type, String name, Map attributes, boolean isAdd) throws IdRepoException, SSOException {
if (debug.messageEnabled()) {
if (attributes.containsKey("userpassword")) {
AMHashMap removedPasswd = new AMHashMap();
removedPasswd.copy(attributes);
removedPasswd.remove("userpassword");
removedPasswd.put("userpassword", "xxx...");
debug.message("AMSDKRepo: setAttributes called" + type + ": " + name + ": " + removedPasswd);
} else {
debug.message("AMSDKRepo: setAttributes called" + type + ": " + name + ": " + attributes);
}
}
if (attributes == null || attributes.isEmpty()) {
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ILLEGAL_ARGUMENTS, null);
}
String dn = getDN(type, name);
int profileType = getProfileType(type);
try {
if (adminToken != null) {
token = adminToken;
}
IDirectoryServices dsServices = AMDirectoryAccessFactory.getDirectoryServices();
dsServices.setAttributes(token, dn, profileType, attributes, null, false);
} catch (AMException ame) {
debug.error("AMSDKRepo.setAttributes: Unable to set attributes", ame);
String ldapError = ame.getLDAPErrorCode();
String errorMessage = ame.getMessage();
int errCode = Integer.parseInt(ldapError);
if (ResultCode.CONSTRAINT_VIOLATION.equals(ResultCode.valueOf(errCode))) {
Object[] args = { this.getClass().getName(), ldapError, errorMessage };
//as it breaks password policy for password length.
throw new IdRepoFatalException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.LDAP_EXCEPTION, ResultCode.CONSTRAINT_VIOLATION, args);
} else {
throw IdUtils.convertAMException(ame);
}
}
}
use of com.sun.identity.idm.IdRepoFatalException in project OpenAM by OpenRock.
the class EntitiesModelImpl method getAssignedServiceNames.
/**
* Returns assigned services. Map of service name to its display name.
*
* @param universalId Universal ID of the entity.
* @return assigned services.
* @throws AMConsoleException if service information cannot be determined.
*/
public Map getAssignedServiceNames(String universalId) throws AMConsoleException {
Map assigned = null;
String[] param = { universalId };
logEvent("ATTEMPT_READ_IDENTITY_ASSIGNED_SERVICE", param);
try {
AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
Set serviceNames = amid.getAssignedServices();
// don't show auth config or user services in the user profile.
IdType type = amid.getType();
if (type.equals(IdType.USER)) {
serviceNames.remove(AMAdminConstants.USER_SERVICE);
serviceNames.remove(AMAdminConstants.AUTH_CONFIG_SERVICE);
}
assigned = getLocalizedServiceNames(serviceNames);
logEvent("SUCCEED_READ_IDENTITY_ASSIGNED_SERVICE", param);
} catch (SSOException e) {
String[] paramsEx = { universalId, getErrorString(e) };
logEvent("SSO_EXCEPTION_READ_IDENTITY_ASSIGNED_SERVICE", paramsEx);
debug.warning("EntitiesModelImpl.getAssignedServiceNames", e);
throw new AMConsoleException(getErrorString(e));
} catch (IdRepoFatalException e) {
String[] paramsEx = { universalId, getErrorString(e) };
logEvent("IDM_EXCEPTION_READ_IDENTITY_ASSIGNED_SERVICE", paramsEx);
debug.warning("EntitiesModelImpl.getAssignedServiceNames", e);
// exception is too cryptic
if (e.getErrorCode().equals(IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED)) {
isServicesSupported = false;
throw new AMConsoleException(getLocalizedString("idrepo.sevices.not.supported"));
} else {
throw new AMConsoleException(getErrorString(e));
}
} catch (IdRepoException e) {
String[] paramsEx = { universalId, getErrorString(e) };
logEvent("IDM_EXCEPTION_READ_IDENTITY_ASSIGNED_SERVICE", paramsEx);
debug.warning("EntitiesModelImpl.getAssignedServiceNames", e);
throw new AMConsoleException(getErrorString(e));
}
return (assigned != null) ? assigned : Collections.EMPTY_MAP;
}
use of com.sun.identity.idm.IdRepoFatalException 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;
}
}
use of com.sun.identity.idm.IdRepoFatalException 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;
}
}
use of com.sun.identity.idm.IdRepoFatalException 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;
}
}
Aggregations