Search in sources :

Example 1 with ServerConfigMgr

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);
    }
}
Also used : Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AdminPasswordAction(com.sun.identity.security.AdminPasswordAction) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) LoginException(javax.security.auth.login.LoginException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) ServerConfigMgr(com.iplanet.services.ldap.ServerConfigMgr)

Aggregations

ServerConfigMgr (com.iplanet.services.ldap.ServerConfigMgr)1 SSOException (com.iplanet.sso.SSOException)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 IdRepoFatalException (com.sun.identity.idm.IdRepoFatalException)1 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)1 AdminPasswordAction (com.sun.identity.security.AdminPasswordAction)1 SMSException (com.sun.identity.sm.SMSException)1 ServiceConfig (com.sun.identity.sm.ServiceConfig)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 LoginException (javax.security.auth.login.LoginException)1