List of usage examples for javax.naming.directory Attributes remove
Attribute remove(String attrID);
From source file:ldap.ActiveLoginImpl.java
/** * This updates the UserAccount.//w w w .ja v a 2 s.com * It requires at a minimum a name; * and optionally any other attributes. * * Note that this will REPLACE any attributes passed, deleting any existing values * for the specified attribute (e.g. if the attribute is userPassword, the old userPassword will * be discarded, rather than there being two userPasswords in the entry). * * Modifying the naming attribute will probably result in an error (depending on the directory). * * @param account * @throws Exception */ public void updateAccount(UserAccount account, DirContext context, String userDN) throws Exception { //if (account.get(Config.USER_NAMING_ATT) == null) if (account.get(LdapConstants.ldapDnAttrType) == null) throw new NamingException("UpdateAccount(), UserAccount has no naming Attribute"); // should not be used //logger.info("Updating: \n" + account.getUserDN() + "\n" + account.toString()); logger.info("Updating: \n" + userDN + "\n" + account.toString()); // remove the naming attribute from the account before adding Attributes atts = copyAttributes(account); // create a local copy //atts.remove(Config.USER_NAMING_ATT); // we can't modify the naming attribute this way, so don't try... //atts.remove(LdapConstants.ldapAttrUid); // we can't modify the naming attribute this way, so don't try... atts.remove(LdapConstants.ldapDnAttrType); // we can't modify the naming attribute this way, so don't try... atts = hashPasswordAttribute(atts); // context.modifyAttributes(account.getUserDN(), DirContext.REPLACE_ATTRIBUTE, atts); context.modifyAttributes(userDN, DirContext.REPLACE_ATTRIBUTE, atts); }
From source file:ldap.ActiveLoginImpl.java
public Attributes hashPasswordAttribute(Attributes account) throws NamingException { Attribute pwdAtt = account.get(LdapConstants.ldapAttrUserPassword); if (pwdAtt == null || pwdAtt.get() == null) throw new NamingException("user password attribute missing!"); logger.info("entered hashPassword()" + pwdAtt); Object o = pwdAtt.get();/*from w ww. ja v a 2 s .com*/ logger.info("entered hashPassword()"); byte[] hash = hashPassword(o); logger.info("completed hashPassword()"); account.remove(LdapConstants.ldapAttrUserPassword); logger.info("adding the ldapAttrUserPassword, " + hash); account.put(LdapConstants.ldapAttrUserPassword, hash); byte[] pwd = (byte[]) account.get("userPassword").get(); if (pwd != null) { logger.info("getting the ldapAttrUserPassword, " + pwd); } else { logger.info("hash pwd is null when tried to retrieve it"); } return account; }