use of com.iplanet.services.ldap.ServerConfigMgr in project OpenAM by OpenRock.
the class SpecialRepo method setAttributes.
/*
* (non-Javadoc)
*
* @see com.sun.identity.idm.IdRepo#setAttributes(com.iplanet.sso.SSOToken,
* com.sun.identity.idm.IdType, java.lang.String, java.util.Map,
* boolean)
*/
public void setAttributes(SSOToken token, IdType type, String name, Map attributes, boolean isAdd) throws IdRepoException, SSOException {
if (isSpecialUser(type, name)) {
boolean isUrlAccessAgent = isUrlAccessAgent(type, name);
String urlAccessAgentCryptPwd = null;
if (!isAmAdminUser(token)) {
Object[] args = { name };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PERMISSION_DENIED_SETTING_ATTRIBUTES, args);
}
try {
ServiceConfig userConfig = getUserConfig();
// For performance reason check if the user entry
// is present before getting the subConfig
CaseInsensitiveHashSet userSet = new CaseInsensitiveHashSet();
userSet.addAll(userConfig.getSubConfigNames());
if (userSet.contains(name)) {
ServiceConfig usc1 = userConfig.getSubConfig(name);
Map attrs = usc1.getAttributes();
// can only set "userpassword" and "inetUserStatus"
String newPassword = null;
Set vals = (Set) attributes.get("userPassword");
if ((vals != null) || (vals = (Set) attributes.get("userpassword")) != null) {
Set hashedVals = new HashSet();
Iterator it = vals.iterator();
while (it.hasNext()) {
String val = (String) it.next();
hashedVals.add(Hash.hash(val));
newPassword = val;
// urlAccessAgentCryptPwd will be null.
if (isUrlAccessAgent) {
urlAccessAgentCryptPwd = Crypt.encode(val);
}
}
attrs.put("userPassword", hashedVals);
}
if ((vals = (Set) attributes.get(statusAttribute)) != null || (vals = (Set) attributes.get(statusAttribute)) != null) {
attrs.put(statusAttribute, vals);
}
if ((vals = (Set) attributes.get(cnAttribute)) != null || (vals = (Set) attributes.get(cnAttribute)) != null) {
attrs.put(cnAttribute, vals);
}
if ((vals = (Set) attributes.get(snAttribute)) != null || (vals = (Set) attributes.get(snAttribute)) != null) {
attrs.put(snAttribute, vals);
}
if ((vals = (Set) attributes.get(gnAttribute)) != null || (vals = (Set) attributes.get(gnAttribute)) != null) {
attrs.put(gnAttribute, vals);
}
if ((vals = (Set) attributes.get(empNumAttribute)) != null || (vals = (Set) attributes.get(empNumAttribute)) != null) {
attrs.put(empNumAttribute, vals);
}
if ((vals = (Set) attributes.get(aliasAttribute)) != null || (vals = (Set) attributes.get(aliasAttribute)) != null) {
attrs.put(aliasAttribute, vals);
}
if ((vals = (Set) attributes.get(successAttribute)) != null || (vals = (Set) attributes.get(successAttribute)) != null) {
attrs.put(successAttribute, vals);
}
if ((vals = (Set) attributes.get(failureAttribute)) != null || (vals = (Set) attributes.get(failureAttribute)) != null) {
attrs.put(failureAttribute, vals);
}
if ((vals = (Set) attributes.get(mailAttribute)) != null || (vals = (Set) attributes.get(mailAttribute)) != null) {
attrs.put(mailAttribute, vals);
}
if ((vals = (Set) attributes.get(addrAttribute)) != null || (vals = (Set) attributes.get(addrAttribute)) != null) {
attrs.put(addrAttribute, vals);
}
if ((vals = (Set) attributes.get(msisdnAttribute)) != null || (vals = (Set) attributes.get(msisdnAttribute)) != null) {
attrs.put(msisdnAttribute, vals);
}
if ((vals = (Set) attributes.get(phoneAttribute)) != null || (vals = (Set) attributes.get(phoneAttribute)) != null) {
attrs.put(phoneAttribute, vals);
}
usc1.setAttributes(attrs);
// update serverconfig.xml and directory
if (name.equalsIgnoreCase("dsameuser")) {
String op = (String) AccessController.doPrivileged(new AdminPasswordAction());
try {
ServerConfigMgr sscm = new ServerConfigMgr();
sscm.setAdminUserPassword(op, newPassword);
sscm.save();
} catch (Exception e) {
debug.error("SpecialRepo: error in " + "changing password", e);
}
}
updateServiceConfiguration(urlAccessAgentCryptPwd);
} else {
Object[] args = { name };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NOT_VALID_ENTRY, args);
}
} catch (SMSException smse) {
debug.error("SpecialRepo: Unable to set user attributes ", smse);
Object[] args = { NAME, type.getName(), name };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ERROR_SETTING_ATTRIBUTES, args);
}
} else {
Object[] args = { NAME, IdOperation.EDIT.getName() };
throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
}
}
Aggregations