/**
* The MessageFormat object associated with the current
+ * <code>roleBase</code>.
+ */
+ protected MessageFormat roleBaseFormat = null;
+
+
+ /**
+ * The MessageFormat object associated with the current
* <code>roleSearch</code>.
*/
protected MessageFormat roleFormat = null;
public void setRoleBase(String roleBase) {
this.roleBase = roleBase;
+ if (roleBase == null)
+ roleBaseFormat = null;
+ else
+ roleBaseFormat = new MessageFormat(roleBase);
}
controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
controls.setReturningAttributes(new String[] {roleName});
+ String base = null;
+ if (roleBaseFormat != null) {
+ NameParser np = context.getNameParser("");
+ Name name = np.parse(dn);
+ String nameParts[] = new String[name.size()];
+ for (int i = 0; i < name.size(); i++) {
+ nameParts[i] = name.get(i);
+ }
+ base = roleBaseFormat.format(nameParts);
+ }
+
// Perform the configured search and process the results
NamingEnumeration<SearchResult> results = null;
try {
if (roleSearchAsUser) {
userCredentialsAdd(context, dn, user.getPassword());
}
- results = context.search(roleBase, filter, controls);
+ results = context.search(base, filter, controls);
} finally {
if (roleSearchAsUser) {
userCredentialsRemove(context);
<bug>19444</bug>: Add an option to the JNDI realm to allow role searches
to be performed by the authenticated user. (markt)
</add>
+ <add>
+ <bug>21669</bug>: Add the ability to specify the roleBase for the JNDI
+ Realm as relative to the users DN. Based on a patch by Art W. (markt)
+ </add>
<fix>
<bug>48863</bug>: Better logging when specifying an invalid directory
for a class loader. Based on a patch by Ralf Hauser. (markt)
</attribute>
<attribute name="roleBase" required="false">
- <p>The base directory entry for performing role searches. If
- not specified the top-level element in the directory context
- will be used.</p>
+ <p>The base directory entry for performing role searches. If not
+ specified the top-level element in the directory context will be used.
+ If specified it may optionally include pattern replacements
+ "{0}".."{n}" corrosponding to the name parts of the
+ user's distinguished name (as returned by
+ <code>javax.naming.Name.get()</code>).</p>
</attribute>
<attribute name="roleName" required="false">