Author: bdaw
Date: 2009-11-10 13:07:03 -0500 (Tue, 10 Nov 2009)
New Revision: 13812
Modified:
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/IdentityConfiguration.java
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
Log:
- Some configuration tweaks to support user creation and password update in MSAD
Modified:
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/IdentityConfiguration.java
===================================================================
---
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/IdentityConfiguration.java 2009-10-14
07:32:35 UTC (rev 13811)
+++
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/IdentityConfiguration.java 2009-11-10
18:07:03 UTC (rev 13812)
@@ -63,6 +63,14 @@
public static final String USER_PASSWORD_ATTRIBUTE_ID =
"passwordAttributeID";
+ public static final String USER_PASSWORD_ENCLOSE_WITH =
"enclosePasswordWith";
+
+ public static final String USER_PASSWORD_ENCODING = "passwordEncoding";
+
+ public static final String USER_PASSWORD_UPDATE_ATTRIBUTES =
"passwordUpdateAttributeValues";
+
+ public static final String USER_SET_PASSWORD_AFTER_USER_CREATE =
"setPasswordAfterUserCreate";
+
public static final String USER_CONTEXT_DN = "userCtxDN";
public static final String USER_CONTAINER_DN = USER_CONTEXT_DN;
Modified:
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java
===================================================================
---
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java 2009-10-14
07:32:35 UTC (rev 13811)
+++
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java 2009-11-10
18:07:03 UTC (rev 13812)
@@ -44,6 +44,8 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Set;
+import java.io.UnsupportedEncodingException;
/**
* Abstract LDAPUserModule that should be extended to provide compabitibility across
identity modules
@@ -81,19 +83,74 @@
public void updatePassword(LDAPUserImpl ldapu, String password) throws
IdentityException
{
+ if ((password == null || password.length() == 0) &&
!isAllowEmptyPasswords())
+ {
+ throw new IdentityException("Cannot update password with empty value -
please set proper option to allow this");
+ }
+
String attributeName = getPasswordAttributeId();
LdapContext ldapContext = getConnectionContext().createInitialContext();
+ String passwordString = password;
+
+ if (getEnclosePasswordWith() != null)
+ {
+ String enc = getEnclosePasswordWith();
+ passwordString = enc + passwordString + enc;
+ }
+
+ byte[] encodedPassword = null;
+
+ if (getPasswordEncoding() != null && passwordString != null)
+ {
+ try
+ {
+ encodedPassword = passwordString.getBytes(getPasswordEncoding());
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new IdentityException("Error while encoding password with
configured setting: " + getPasswordEncoding(),
+ e);
+ }
+ }
+
+
+
+
+
try
{
//TODO: maybe perform a schema check if this attribute is allowed for such
entry
Attributes attrs = new BasicAttributes(true);
Attribute attr = new BasicAttribute(attributeName);
- attr.add(password);
+ if (encodedPassword != null)
+ {
+
+ attr.add(encodedPassword);
+ }
+ else
+ {
+ attr.add(passwordString);
+ }
attrs.put(attr);
+ if(getUpdatePasswordAttributeValues().size() > 0)
+ {
+ Map<String, Set<String>> attributesToAdd =
getUpdatePasswordAttributeValues();
+ for (Map.Entry<String, Set<String>> entry :
attributesToAdd.entrySet())
+ {
+ Attribute additionalAttr = new BasicAttribute(entry.getKey());
+ for (String val : entry.getValue())
+ {
+ additionalAttr.add(val);
+ }
+ attrs.put(additionalAttr);
+ }
+
+ }
+
ldapContext.modifyAttributes(ldapu.getDn(),
DirContext.REPLACE_ATTRIBUTE,attrs);
}
catch (NamingException e)
@@ -114,6 +171,8 @@
}
+
+
public boolean validatePassword(LDAPUserImpl ldapu, String password) throws
IdentityException
{
@@ -434,20 +493,17 @@
return Boolean.FALSE.booleanValue();
}
-
- /*protected String getEmailAttributeId() throws IdentityException
+ protected boolean isSetPasswordAfterUserCreate()
{
- String email =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_EMAIL_ATTRIBUTE_ID);
- if (email == null)
+ String userNameToLowerCase =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_SET_PASSWORD_AFTER_USER_CREATE);
+ if (userNameToLowerCase != null &&
userNameToLowerCase.equalsIgnoreCase("true"))
{
- return "mail";
+ return Boolean.TRUE.booleanValue();
}
- else
- {
- return email;
- }
- }*/
+ return Boolean.FALSE.booleanValue();
+ }
+
protected Map getAttributesToAdd() throws IdentityException
{
Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
@@ -462,5 +518,41 @@
{
this.connectionContext = connectionContext;
}
+
+ protected String getPasswordEncoding() throws IdentityException
+ {
+ String encoding =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ENCODING);
+ if (encoding == null)
+ {
+ throw new IdentityException(IdentityConfiguration.USER_PASSWORD_ENCODING +
" missing in configuration");
+ }
+ else
+ {
+ return encoding;
+ }
+ }
+
+ protected Map getUpdatePasswordAttributeValues() throws IdentityException
+ {
+ Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.USER_PASSWORD_UPDATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new
IdentityException(IdentityConfiguration.USER_PASSWORD_UPDATE_ATTRIBUTES + " missing
in configuration");
+ }
+ return attributesToAdd;
+ }
+
+ protected String getEnclosePasswordWith() throws IdentityException
+ {
+ String enc =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ENCLOSE_WITH);
+ if (enc == null)
+ {
+ throw new IdentityException(IdentityConfiguration.USER_PASSWORD_ENCLOSE_WITH +
" missing in configuration");
+ }
+ else
+ {
+ return enc;
+ }
+ }
}
Modified:
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
===================================================================
---
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2009-10-14
07:32:35 UTC (rev 13811)
+++
modules/identity/branches/JBP_IDENTITY_BRANCH_1_1/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2009-11-10
18:07:03 UTC (rev 13812)
@@ -180,6 +180,10 @@
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
{
String attributeName = (String)it1.next();
+ if (getUidAttributeID().equals(attributeName))
+ {
+ continue;
+ }
log.debug("adding attribute: " + attributeName);
Attribute attr = new BasicAttribute(attributeName);
Set attributeValues = (Set)attributesToAdd.get(attributeName);
@@ -194,15 +198,19 @@
attrs.put(attr);
}
- attrs.put(getPasswordAttributeId(), password);
+ if (!isSetPasswordAfterUserCreate())
+ {
+ attrs.put(getPasswordAttributeId(), password);
+ }
-
String validUserName = LDAPTools.encodeRfc2253Name(userName);
String dn = getUidAttributeID().concat("=").concat(validUserName);
log.debug("creating ldap entry for: " + dn + "; " + attrs);
ctx.createSubcontext(dn, attrs);
+
+
}
catch (Exception e)
{
@@ -219,13 +227,21 @@
throw new IdentityException("Failed to close LDAP connection", e);
}
}
- User u = findUserByUserName(userName);
+ LDAPUserImpl u = (LDAPUserImpl)findUserByUserName(userName);
+ if (isSetPasswordAfterUserCreate())
+ {
+ updatePassword(u, password);
+ }
+
+
fireUserCreatedEvent(u.getId(), u.getUserName());
return u;
}
+
+
//TODO: remove user assignments before?
public void removeUser(Object id) throws IdentityException, IllegalArgumentException
{
Show replies by date