Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/.classpath
===================================================================
--- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/.classpath (revision 446621)
+++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/.classpath (working copy)
@@ -3,7 +3,6 @@
- * Returns the default suffix dn. + * Returns the default Group suffix dn. *
* * @return The defaultDnSuffix. @@ -351,21 +368,34 @@ * * @return The defaultDnSuffix. */ - protected String getDefaultDnSuffix() + protected String getGroupFilterBase() { - return this.ldapBindingConfig.getDefaultDnSuffix(); + return this.ldapBindingConfig.getGroupFilterBase(); } + + /** + *+ * Returns the default Group suffix dn. + *
+ * + * @return The defaultDnSuffix. + */ + protected String[] getGroupObjectClasses() + { + return this.ldapBindingConfig.getGroupObjectClasses(); + } + /** *- * Returns the groups organization unit. + * Returns the default Group suffix dn. *
* - * @return The groupsOu. + * @return The defaultDnSuffix. */ - protected String getGroupsOu() + protected String getRoleFilterBase() { - return this.ldapBindingConfig.getGroupsOu(); + return this.ldapBindingConfig.getRoleFilterBase(); } /** @@ -370,27 +400,54 @@ /** *- * Returns the roles . + * Returns the default Group suffix dn. *
* - * @return The rolesOu. + * @return The defaultDnSuffix. */ - protected String getRolesOu() + protected String[] getRoleObjectClasses() { - return this.ldapBindingConfig.getRolesOu(); + return this.ldapBindingConfig.getRoleObjectClasses(); } - + /** *- * Returns the users organization unit. + * Returns the default Group suffix dn. *
* - * @return The usersOu. + * @return The defaultDnSuffix. */ - protected String getUsersOu() + protected String getUserFilterBase() { - return this.ldapBindingConfig.getUsersOu(); - } + return this.ldapBindingConfig.getUserFilterBase(); + } + + /** + *+ * Returns the default Group suffix dn. + *
+ * + * @return The defaultDnSuffix. + */ + protected String getGroupFilter() + { + return this.ldapBindingConfig.getGroupFilter(); + } + + + /** + *+ * Returns the default Group suffix dn. + *
+ * + * @return The defaultDnSuffix. + */ + protected String getRoleFilter() + { + return this.ldapBindingConfig.getRoleFilter(); + } + + /** *@@ -403,16 +460,17 @@ { return this.ldapBindingConfig.getRootContext(); } - + /** *
- * A template method that returns the LDAP object class of the concrete DAO. + * A template method that returns the LDAP entry prefix of the concrete DAO. *
* - * @return a String containing the LDAP object class name. - */ - protected abstract String getObjectClass(); - + * TODO : this should be in spring config + * + * @return a String containing the LDAP entry prefix name. + */ + protected abstract String getEntryPrefix(); /** *@@ -423,6 +481,82 @@ * * @return a String containing the LDAP entry prefix name. */ - protected abstract String getEntryPrefix(); + protected abstract String getSearchSuffix(); + + /** + *
+ * The domain in wich to perform a search + *
+ * + * TODO : this should be in spring config + * + * @return a String containing the LDAP entry prefix name. + */ + protected abstract String getSearchDomain(); + + protected String getUserFilter() + { + return this.ldapBindingConfig.getUserFilter(); + } + + /** + *+ * Returns the default Group suffix dn. + *
+ * + * @return The defaultDnSuffix. + */ + protected String[] getUserObjectClasses() + { + return this.ldapBindingConfig.getUserObjectClasses(); + } + + protected String getGroupMembershipAttribute() + { + return this.ldapBindingConfig.getGroupMembershipAttributes(); + } + + protected String getUserGroupMembershipAttribute() + { + return this.ldapBindingConfig.getUserGroupMembershipAttributes(); + } + + + protected String getGroupMembershipForRoleAttribute() + { + return this.ldapBindingConfig.getGroupMembershipForRoleAttributes(); + } + + protected String getRoleGroupMembershipForRoleAttribute() + { + return this.ldapBindingConfig.getRoleGroupMembershipForRoleAttributes(); + } + + protected String getRoleMembershipAttribute() + { + return this.ldapBindingConfig.getRoleMembershipAttributes(); + } + protected String getUserRoleMembershipAttribute() + { + return this.ldapBindingConfig.getUserRoleMembershipAttributes(); + } + + protected String getRoleIdAttribute() + { + return this.ldapBindingConfig.getRoleIdAttribute(); + } + + protected String getGroupIdAttribute() + { + return this.ldapBindingConfig.getGroupIdAttribute(); + } + + protected String getUserIdAttribute() + { + return this.ldapBindingConfig.getUserIdAttribute(); + } + + protected abstract String[] getObjectClasses(); + } \ No newline at end of file Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/InitLdapSchema.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/InitLdapSchema.java (revision 446621) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/InitLdapSchema.java (working copy) @@ -1,125 +1,158 @@ -/* - * Copyright 2000-2001,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.security.spi.impl.ldap; - -import javax.naming.NamingException; -import javax.naming.directory.Attributes; -import javax.naming.directory.BasicAttribute; -import javax.naming.directory.BasicAttributes; - -import org.apache.commons.lang.StringUtils; -import org.apache.jetspeed.security.SecurityException; - -public class InitLdapSchema extends AbstractLdapDao -{ - - /** - *- * Default constructor. - *
- * - * @throws SecurityException A {@link SecurityException}. - */ - public InitLdapSchema() throws SecurityException - { - super(); - } - - /** - *- * Initializes the LDAP schema. - *
- * - * @param ldapConfig Holds the ldap binding configuration. - * @throws SecurityException A {@link SecurityException}. - */ - public InitLdapSchema(LdapBindingConfig ldapConfig) throws SecurityException - { - super(ldapConfig); - init(); - } - - /** - * @see org.apache.jetspeed.security.spi.impl.ldap.AbstractLdapDao#getObjectClass() - */ - protected String getObjectClass() - { - // Implementation not required for initializing the ldap schema. - return null; - } - - /** - * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#create(java.lang.String) - */ - public void init() throws SecurityException - { - initOu(getUsersOu()); - initOu(getGroupsOu()); - initOu(getRolesOu()); - } - - /** - *- * Inits a given ou. - *
- * - * @param ou The org unit. - * @throws SecurityException - */ - public void initOu(String ou) throws SecurityException - { - if (!StringUtils.isEmpty(ou)) - { - Attributes attrs = defineLdapAttributes(ou); - try - { - String dn = "ou=" + ou; - ctx.createSubcontext(dn, attrs); - } - catch (NamingException e) - { - throw new SecurityException(e); - } - } - } - - /** - *- * A template method for defining the attributes for a particular LDAP class. - *
- * - * @param principalUid The principal uid. - * @return the LDAP attributes object for the particular class. - */ - protected Attributes defineLdapAttributes(String ou) - { - Attributes attrs = new BasicAttributes(true); - BasicAttribute classes = new BasicAttribute("objectclass"); - - classes.add("top"); - classes.add("organizationalUnit"); - attrs.put(classes); - attrs.put("ou", ou); - - return attrs; - } - - protected String getEntryPrefix() - { - return null; - } - -} +/* + * Copyright 2000-2001,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.spi.impl.ldap; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; + +import org.apache.commons.lang.StringUtils; +import org.apache.jetspeed.security.SecurityException; + +public class InitLdapSchema extends AbstractLdapDao +{ + + /** + *+ * Default constructor. + *
+ * + * @throws SecurityException A {@link SecurityException}. + */ + public InitLdapSchema() throws SecurityException + { + super(); + } + + /** + *+ * Initializes the LDAP schema. + *
+ * + * @param ldapConfig Holds the ldap binding configuration. + * @throws SecurityException A {@link SecurityException}. + */ + public InitLdapSchema(LdapBindingConfig ldapConfig) throws SecurityException + { + super(ldapConfig); + init(); + } + + /** + * @see org.apache.jetspeed.security.spi.impl.ldap.AbstractLdapDao#getObjectClass() + */ + protected String getObjectClass() + { + // Implementation not required for initializing the ldap schema. + return null; + } + + /** + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#create(java.lang.String) + */ + public void init() throws SecurityException + { + initOu("OrgUnit1"); + initOu("People","ou=OrgUnit1"); + initOu("Groups","ou=OrgUnit1"); + initOu("Roles","ou=OrgUnit1"); +// initOu(getUsersOu()); +// initOu(getGroupsOu()); +// initOu(getRolesOu()); + } + + /** + *+ * Inits a given ou. + *
+ * + * @param ou The org unit. + * @throws SecurityException + */ + public void initOu(String ou) throws SecurityException + { + if (!StringUtils.isEmpty(ou)) + { + Attributes attrs = defineLdapAttributes(ou); + try + { + String dn = "ou=" + ou; // + "," + getDefaultSearchBase(); + ctx.createSubcontext(dn, attrs); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } + } + + public void initOu(String ou,String folder) throws SecurityException + { + if (!StringUtils.isEmpty(ou)) + { + Attributes attrs = defineLdapAttributes(ou); + try + { + ctx.createSubcontext("ou=" + ou + "," + folder, attrs); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } + } + + /** + *+ * A template method for defining the attributes for a particular LDAP class. + *
+ * + * @param principalUid The principal uid. + * @return the LDAP attributes object for the particular class. + */ + protected Attributes defineLdapAttributes(String ou) + { + Attributes attrs = new BasicAttributes(true); + BasicAttribute classes = new BasicAttribute("objectclass"); + + classes.add("top"); + classes.add("organizationalUnit"); + attrs.put(classes); + attrs.put("ou", ou); + + return attrs; + } + + protected String getEntryPrefix() + { + return null; + } + + protected String getSearchSuffix() { + return null; + } + + protected String getSearchDomain() { + return null; + } + + protected String[] getObjectClasses() { + return null; + } + + +} Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapBindingConfig.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapBindingConfig.java (revision 446621) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapBindingConfig.java (working copy) @@ -1,294 +1,504 @@ -/* Copyright 2004 Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.security.spi.impl.ldap; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.jetspeed.security.SecurityException; - -/** - *- * Holds the configuration for ldap binding. - *
- * - * @author David Le Strat - */ -public class LdapBindingConfig -{ - /** The logger. */ - private static final Log logger = LogFactory.getLog(LdapBindingConfig.class); - - /** The initial context factory for the LDAP provider. */ - private String initialContextFactory; - - /** The server name. */ - private String ldapServerName; - - /** The server port. */ - private String ldapServerPort; - - /** The root distinguished name. */ - private String rootDn; - - /** The root password. */ - private String rootPassword; - - /** The root context. */ - private String rootContext; - - /** The default suffix. */ - private String defaultDnSuffix; - - /** The users ou. */ - private String usersOu; - - /** The groups ou. */ - private String groupsOu; - - /** The roles ou. */ - private String rolesOu; - - /** The ldap properties. */ - private PropertiesConfiguration props = null; - - /** - * @param factory The initial context factory. - * @param name The ldap server name. - * @param port The ldap server port. - * @param suffix The default dn suffix. - * @param context The root context. - * @param dn The root dn. - * @param password The root password. - * @param uou The users organization unit. - * @param gou The groups organization unit. - */ - public LdapBindingConfig(String factory, String name, String port, String suffix, String context, String dn, - String password, String uou, String goups,String roles) - { - try - { - initialContextFactory = factory; - ldapServerName = name; - ldapServerPort = port; - defaultDnSuffix = suffix; - rootContext = context; - rootDn = dn; - rootPassword = password; - usersOu = uou; - groupsOu = goups; - rolesOu = roles; - new InitLdapSchema(this); - } - catch (SecurityException se) - { - if (logger.isWarnEnabled()) - { - logger.warn("The LDAP directory should already be initialized. If this is not the case, an exception" - + "occured during initialization."); - } - } - } - - /** - *- * Default constructor. By default instantiates LdapBindingConfig from - * JETSPEED-INF/ldap/ldap.properties in the classpath. - *
- */ - public LdapBindingConfig() - { - try - { - props = new PropertiesConfiguration("JETSPEED-INF/ldap/ldap.properties"); - initialContextFactory = props.getString("org.apache.jetspeed.ldap.initialContextFactory"); - ldapServerName = props.getString("org.apache.jetspeed.ldap.ldapServerName"); - ldapServerPort = props.getString("org.apache.jetspeed.ldap.ldapServerPort"); - defaultDnSuffix = props.getString("org.apache.jetspeed.ldap.defaultDnSuffix"); - rootContext = props.getString("org.apache.jetspeed.ldap.rootContext"); - rootDn = props.getString("org.apache.jetspeed.ldap.rootDn"); - rootPassword = props.getString("org.apache.jetspeed.ldap.rootPassword"); - usersOu = props.getString("org.apache.jetspeed.ldap.ou.users"); - groupsOu = props.getString("org.apache.jetspeed.ldap.ou.groups"); - rolesOu = props.getString("org.apache.jetspeed.ldap.ou.roles"); - new InitLdapSchema(this); - } - catch (ConfigurationException ce) - { - logger.error("Could not configure LdapBindingConfig: " + ce); - } - catch (SecurityException se) - { - if (logger.isWarnEnabled()) - { - logger.warn("The LDAP directory should already be initialized. If this is not the case, an exception" - + "occured during initialization."); - } - } - } - - /** - * @return Returns the defaultDnSuffix. - */ - public String getDefaultDnSuffix() - { - return defaultDnSuffix; - } - - /** - * @param defaultDnSuffix The defaultDnSuffix to set. - */ - public void setDefaultDnSuffix(String defaultDnSuffix) - { - this.defaultDnSuffix = defaultDnSuffix; - } - - /** - * @return Returns the groupsOu. - */ - public String getGroupsOu() - { - return groupsOu; - } - - /** - * @param groupsOu The groupsOu to set. - */ - public void setGroupsOu(String groupsOu) - { - this.groupsOu = groupsOu; - } - - /** - * @return Returns the initialContextFactory. - */ - public String getInitialContextFactory() - { - return initialContextFactory; - } - - /** - * @param initialContextFactory The initialContextFactory to set. - */ - public void setInitialContextFactory(String initialContextFactory) - { - this.initialContextFactory = initialContextFactory; - } - - /** - * @return Returns the ldapServerName. - */ - public String getLdapServerName() - { - return ldapServerName; - } - - /** - * @param ldapServerName The ldapServerName to set. - */ - public void setLdapServerName(String ldapServerName) - { - this.ldapServerName = ldapServerName; - } - - /** - * @return Returns the ldapServerPort. - */ - public String getLdapServerPort() - { - return ldapServerPort; - } - - /** - * @param ldapServerPort The ldapServerPort to set. - */ - public void setLdapServerPort(String ldapServerPort) - { - this.ldapServerPort = ldapServerPort; - } - - /** - * @return Returns the rootContext. - */ - public String getRootContext() - { - return rootContext; - } - - /** - * @param rootContext The rootContext to set. - */ - public void setRootContext(String rootContext) - { - this.rootContext = rootContext; - } - - /** - * @return Returns the rootDn. - */ - public String getRootDn() - { - return rootDn; - } - - /** - * @param rootDn The rootDn to set. - */ - public void setRootDn(String rootDn) - { - this.rootDn = rootDn; - } - - /** - * @return Returns the rootPassword. - */ - public String getRootPassword() - { - return rootPassword; - } - - /** - * @param rootPassword The rootPassword to set. - */ - public void setRootPassword(String rootPassword) - { - this.rootPassword = rootPassword; - } - - /** - * @return Returns the usersOu. - */ - public String getUsersOu() - { - return usersOu; - } - - /** - * @param usersOu The usersOu to set. - */ - public void setUsersOu(String usersOu) - { - this.usersOu = usersOu; - } - - public String getRolesOu() { - return rolesOu; - } - - public void setRolesOu(String rolesOu) { - this.rolesOu = rolesOu; - } -} +/* Copyright 2004 Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.spi.impl.ldap; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.security.SecurityException; + +/** + *+ * Holds the configuration for ldap binding. + *
+ * + * @author David Le Strat + */ +public class LdapBindingConfig +{ + /** The logger. */ + private static final Log logger = LogFactory.getLog(LdapBindingConfig.class); + + private String initialContextFactory; + private String ldapServerName; + private String ldapServerPort; + private String rootDn; + private String rootPassword; + private String rootContext; + + private String defaultDnSuffix; + + private PropertiesConfiguration props = null; + + private String roleFilter; + private String groupFilter; + private String userFilter; + + private String userAuthenticationFiler; + + private String roleMembershipAttributes; + private String userRoleMembershipAttributes; + + private String groupMembershipAttributes; + private String userGroupMembershipAttributes; + + private String defaultSearchBase; + + private String roleFilterBase; + private String groupFilterBase; + private String userFilterBase; + + private String roleIdAttribute; + private String groupIdAttribute; + private String userIdAttribute; + + private String[] roleObjectClasses; + + private String[] groupObjectClasses; + + private String[] userObjectClasses; + + private String roleGroupMembershipForRoleAttributes; + + private String groupMembershipForRoleAttributes; + + /** + * @param factory The initial context factory. + * @param name The ldap server name. + * @param port The ldap server port. + * @param suffix The default dn suffix. + * @param context The root context. + * @param dn The root dn. + * @param password The root password. + * @param uou The users organization unit. + * @param gou The groups organization unit. + */ + public LdapBindingConfig(String factory, + String name, + String port, + String suffix, + String context, + String dn, + String password, + String roleFilter, + String groupFilter, + String userFilter, + String userAuthenticationFiler, + String roleMembershipAttributes, + String userRoleMembershipAttributes, + String groupMembershipAttributes, + String userGroupMembershipAttributes, + String groupMembershipForRoleAttributes, + String roleGroupMembershipForRoleAttributes, + String defaultSearchBase, + String roleFilterBase, + String groupFilterBase, + String userFilterBase, + String roleObjectClasses, + String groupObjectClasses, + String userObjectClasses, + String roleIdAttribute, + String groupIdAttribute, + String userIdAttribute) + { + try + { + initialContextFactory = factory; + ldapServerName = name; + ldapServerPort = port; + defaultDnSuffix = suffix; + rootContext = context; + rootDn = dn; + rootPassword = password; + + this.roleFilter=roleFilter; + this.groupFilter=groupFilter; + this.userFilter=userFilter; + this.userAuthenticationFiler=userAuthenticationFiler; + + this.roleMembershipAttributes=roleMembershipAttributes; + this.userRoleMembershipAttributes=userRoleMembershipAttributes; + + this.groupMembershipAttributes=groupMembershipAttributes; + this.userGroupMembershipAttributes=userGroupMembershipAttributes; + + this.groupMembershipForRoleAttributes=groupMembershipForRoleAttributes; + this.roleGroupMembershipForRoleAttributes=roleGroupMembershipForRoleAttributes; + this.defaultSearchBase=defaultSearchBase; + + this.roleFilterBase=roleFilterBase; + this.groupFilterBase=groupFilterBase; + this.userFilterBase=userFilterBase; + + + this.roleObjectClasses=StringUtils.split(roleObjectClasses,","); + this.groupObjectClasses=StringUtils.split(groupObjectClasses,","); + this.userObjectClasses=StringUtils.split(userObjectClasses,","); + + this.roleIdAttribute=roleIdAttribute; + this.groupIdAttribute=groupIdAttribute; + this.userIdAttribute=userIdAttribute; + + new InitLdapSchema(this); + } + catch (SecurityException se) + { + if (logger.isWarnEnabled()) + { + logger.warn("The LDAP directory should already be initialized. If this is not the case, an exception" + + "occured during initialization."); + } + } + } + + /** + *+ * Default constructor. By default instantiates LdapBindingConfig from + * JETSPEED-INF/ldap/ldap.properties in the classpath. + *
+ */ + public LdapBindingConfig(String ldapType) + { + try + { + props = new PropertiesConfiguration("JETSPEED-INF/ldap/" + ldapType + "/ldap.properties"); + initialContextFactory = props.getString("org.apache.jetspeed.ldap.initialContextFactory"); + ldapServerName = props.getString("org.apache.jetspeed.ldap.ldapServerName"); + ldapServerPort = props.getString("org.apache.jetspeed.ldap.ldapServerPort"); + defaultDnSuffix = props.getString("org.apache.jetspeed.ldap.defaultDnSuffix"); + rootContext = props.getString("org.apache.jetspeed.ldap.rootContext"); + rootDn = props.getString("org.apache.jetspeed.ldap.rootDn"); + rootPassword = props.getString("org.apache.jetspeed.ldap.rootPassword"); + + roleFilter=props.getString("org.apache.jetspeed.ldap.RoleFilter"); + groupFilter=props.getString("org.apache.jetspeed.ldap.GroupFilter"); + userFilter=props.getString("org.apache.jetspeed.ldap.UserFilter"); + + userAuthenticationFiler=props.getString("org.apache.jetspeed.ldap.UserAuthenticationFiler"); + + roleMembershipAttributes=props.getString("org.apache.jetspeed.ldap.RoleMembershipAttributes"); + userRoleMembershipAttributes=props.getString("org.apache.jetspeed.ldap.UserRoleMembershipAttributes"); + + groupMembershipAttributes=props.getString("org.apache.jetspeed.ldap.GroupMembershipAttributes"); + userGroupMembershipAttributes=props.getString("org.apache.jetspeed.ldap.UserGroupMembershipAttributes"); + + groupMembershipForRoleAttributes=props.getString("org.apache.jetspeed.ldap.GroupMembershipForRoleAttributes"); + roleGroupMembershipForRoleAttributes=props.getString("org.apache.jetspeed.ldap.RoleGroupMembershipForRoleAttributes"); + + defaultSearchBase=props.getString("org.apache.jetspeed.ldap.DefaultSearchBase"); + + roleFilterBase=props.getString("org.apache.jetspeed.ldap.RoleFilterBase"); + groupFilterBase=props.getString("org.apache.jetspeed.ldap.GroupFilterBase"); + userFilterBase=props.getString("org.apache.jetspeed.ldap.UserFilterBase"); + + this.roleObjectClasses=StringUtils.split(props.getString("org.apache.jetspeed.ldap.RoleObjectClasses"),","); + this.groupObjectClasses=StringUtils.split(props.getString("org.apache.jetspeed.ldap.GroupObjectClasses"),","); + this.userObjectClasses=StringUtils.split(props.getString("org.apache.jetspeed.ldap.UserObjectClasses"),","); + + roleIdAttribute=props.getString("org.apache.jetspeed.ldap.RoleIdAttribute"); + groupIdAttribute=props.getString("org.apache.jetspeed.ldap.GroupIdAttribute"); + userIdAttribute=props.getString("org.apache.jetspeed.ldap.UserIdAttribute"); + + new InitLdapSchema(this); + } + catch (ConfigurationException ce) + { + logger.error("Could not configure LdapBindingConfig: " + ce); + } + catch (SecurityException se) + { + if (logger.isWarnEnabled()) + { + logger.warn("The LDAP directory should already be initialized. If this is not the case, an exception" + + "occured during initialization."); + } + } + } + + /** + * @return Returns the defaultDnSuffix. + */ + public String getDefaultDnSuffix() + { + return defaultDnSuffix; + } + + /** + * @param defaultDnSuffix The defaultDnSuffix to set. + */ + public void setDefaultDnSuffix(String defaultDnSuffix) + { + this.defaultDnSuffix = defaultDnSuffix; + } + /** + * @return Returns the initialContextFactory. + */ + public String getInitialContextFactory() + { + return initialContextFactory; + } + + /** + * @param initialContextFactory The initialContextFactory to set. + */ + public void setInitialContextFactory(String initialContextFactory) + { + this.initialContextFactory = initialContextFactory; + } + + /** + * @return Returns the ldapServerName. + */ + public String getLdapServerName() + { + return ldapServerName; + } + + /** + * @param ldapServerName The ldapServerName to set. + */ + public void setLdapServerName(String ldapServerName) + { + this.ldapServerName = ldapServerName; + } + + /** + * @return Returns the ldapServerPort. + */ + public String getLdapServerPort() + { + return ldapServerPort; + } + + /** + * @param ldapServerPort The ldapServerPort to set. + */ + public void setLdapServerPort(String ldapServerPort) + { + this.ldapServerPort = ldapServerPort; + } + + /** + * @return Returns the rootContext. + */ + public String getRootContext() + { + return rootContext; + } + + /** + * @param rootContext The rootContext to set. + */ + public void setRootContext(String rootContext) + { + this.rootContext = rootContext; + } + + /** + * @return Returns the rootDn. + */ + public String getRootDn() + { + return rootDn; + } + + /** + * @param rootDn The rootDn to set. + */ + public void setRootDn(String rootDn) + { + this.rootDn = rootDn; + } + + /** + * @return Returns the rootPassword. + */ + public String getRootPassword() + { + return rootPassword; + } + + /** + * @param rootPassword The rootPassword to set. + */ + public void setRootPassword(String rootPassword) + { + this.rootPassword = rootPassword; + } + + public String getRoleFilter() { + return roleFilter; + } + + public void setRoleFilter(String roleFilter) { + this.roleFilter = roleFilter; + } + + public String getRoleFilterBase() { + return roleFilterBase; + } + + public void setRoleFilterBase(String roleFilterBase) { + this.roleFilterBase = roleFilterBase; + } + + public String getRoleMembershipAttributes() { + return roleMembershipAttributes; + } + + public void setRoleMembershipAttributes(String roleMembershipAttributes) { + this.roleMembershipAttributes = roleMembershipAttributes; + } + + public String getUserAuthenticationFiler() { + return userAuthenticationFiler; + } + + public void setUserAuthenticationFiler(String userAuthenticationFiler) { + this.userAuthenticationFiler = userAuthenticationFiler; + } + + public String getUserFilter() { + return userFilter; + } + + public void setUserFilter(String userFilter) { + this.userFilter = userFilter; + } + + public String getUserFilterBase() { + return userFilterBase; + } + + public void setUserFilterBase(String userFilterBase) { + this.userFilterBase = userFilterBase; + } + + public String getUserGroupMembershipAttributes() { + return userGroupMembershipAttributes; + } + + public void setUserGroupMembershipAttributes( + String userGroupMembershipAttributes) { + this.userGroupMembershipAttributes = userGroupMembershipAttributes; + } + + public String getUserRoleMembershipAttributes() { + return userRoleMembershipAttributes; + } + + public void setUserRoleMembershipAttributes(String userRoleMembershipAttributes) { + this.userRoleMembershipAttributes = userRoleMembershipAttributes; + } + + public String getDefaultSearchBase() { + return defaultSearchBase; + } + + public void setDefaultSearchBase(String defaultSearchBase) { + this.defaultSearchBase = defaultSearchBase; + } + + public String getGroupFilter() { + return groupFilter; + } + + public void setGroupFilter(String groupFilter) { + this.groupFilter = groupFilter; + } + + public String getGroupFilterBase() { + return groupFilterBase; + } + + public void setGroupFilterBase(String groupFilterBase) { + this.groupFilterBase = groupFilterBase; + } + + public String getGroupMembershipAttributes() { + return groupMembershipAttributes; + } + + public void setGroupMembershipAttributes(String groupMembershipAttributes) { + this.groupMembershipAttributes = groupMembershipAttributes; + } + + public String getGroupIdAttribute() { + return groupIdAttribute; + } + + public void setGroupIdAttribute(String groupIdAttribute) { + this.groupIdAttribute = groupIdAttribute; + } + + public String getRoleIdAttribute() { + return roleIdAttribute; + } + + public void setRoleIdAttribute(String roleIdAttribute) { + this.roleIdAttribute = roleIdAttribute; + } + + public String getUserIdAttribute() { + return userIdAttribute; + } + + public void setUserIdAttribute(String userIdAttribute) { + this.userIdAttribute = userIdAttribute; + } + + public String[] getGroupObjectClasses() { + return groupObjectClasses; + } + + public void setGroupObjectClasses(String[] groupObjectClasses) { + this.groupObjectClasses = groupObjectClasses; + } + + public String[] getRoleObjectClasses() { + return roleObjectClasses; + } + + public void setRoleObjectClasses(String[] roleObjectClasses) { + this.roleObjectClasses = roleObjectClasses; + } + + public String[] getUserObjectClasses() { + return userObjectClasses; + } + + public void setUserObjectClasses(String[] userObjectClasses) { + this.userObjectClasses = userObjectClasses; + } + + public String getRoleGroupMembershipForRoleAttributes() { + return this.roleGroupMembershipForRoleAttributes; + } + + public String getGroupMembershipForRoleAttributes() { + return this.groupMembershipForRoleAttributes; + } + + public void setRoleGroupMembershipForRoleAttributes(String roleGroupMembershipForRoleAttributes) { + this.roleGroupMembershipForRoleAttributes=roleGroupMembershipForRoleAttributes; + } + + public void setGroupMembershipForRoleAttributes(String groupMembershipForRoleAttributes) { + this.groupMembershipForRoleAttributes=groupMembershipForRoleAttributes; + } + +} Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapGroupDaoImpl.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapGroupDaoImpl.java (revision 446621) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapGroupDaoImpl.java (working copy) @@ -17,13 +17,10 @@ import java.security.Principal; -import javax.naming.NamingException; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; -import javax.naming.directory.DirContext; -import org.apache.commons.lang.StringUtils; import org.apache.jetspeed.security.SecurityException; import org.apache.jetspeed.security.impl.GroupPrincipalImpl; @@ -76,13 +73,10 @@ Attributes attrs = new BasicAttributes(true); BasicAttribute classes = new BasicAttribute("objectclass"); - classes.add("top"); - classes.add("uidObject"); - classes.add("jetspeed-2-group"); + for (int i=0 ; i+// * Search user by group. +// *
+// * +// * @param groupPrincipalUid +// * @param cons +// * @return +// * @throws NamingException A {@link NamingException}. +// */ +// private NamingEnumeration searchRolesByGroup(final String rolePrincipalUid, SearchControls cons) +// throws NamingException +// { +// String query = "(&(cn=" + (rolePrincipalUid) + ")" + getRoleFilter() + ")"; +// +// if (logger.isDebugEnabled()) +// { +// logger.debug("query[" + query + "]"); +// } +// NamingEnumeration searchResults = ((DirContext) ctx).search("",query , cons); +// +// return searchResults; +// } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao#searchUsersFromGroupByGroup(java.lang.String, javax.naming.directory.SearchControls) + */ + public String[] searchUsersFromGroupByGroup(final String groupPrincipalUid, SearchControls cons) + throws NamingException + { + + String query = "(&(" + getGroupIdAttribute() + "=" + (groupPrincipalUid) + ")" + getGroupFilter() + ")"; + + if (logger.isDebugEnabled()) + { + logger.debug("query[" + query + "]"); + } + + ArrayList userPrincipalUids=new ArrayList(); + + NamingEnumeration results = ((DirContext) ctx).search("",query , cons); + + while (results.hasMore()) + { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + List newAttrs = new ArrayList(); + + Attribute userPrincipalUid = getAttribute(getGroupMembershipAttribute(), answer); + List attrs = getAttributes(userPrincipalUid); + Iterator it = attrs.iterator(); + while(it.hasNext()) { + String uidfull = (String)it.next(); + String uid = extractUid(uidfull); + if (uidfull.indexOf(getUserFilterBase())!=-1) + newAttrs.add(uid); + } + userPrincipalUids.addAll(newAttrs); + } + return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao#searchUsersFromGroupByUser(java.lang.String, javax.naming.directory.SearchControls) + */ + public String[] searchUsersFromGroupByUser(final String groupPrincipalUid, SearchControls cons) + throws NamingException + { + + String subfilter = getGroupIdAttribute() + "=" + getGroupFilterBase(); + if (getGroupFilterBase()!=null && !getGroupFilterBase().equals("")) subfilter+="," + getGroupFilterBase(); + subfilter+="," + getRootContext(); + String query = "(&(" + getUserGroupMembershipAttribute() + "=" + subfilter + ")" + getUserFilter() + ")"; + if (logger.isDebugEnabled()) + { + logger.debug("query[" + query + "]"); + } + NamingEnumeration results = ((DirContext) ctx).search("", query, cons); + + ArrayList userPrincipalUids = new ArrayList(); + + while (results.hasMore()) + { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + userPrincipalUids.addAll(getAttributes(getAttribute("uid", answer))); + } + return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); + } + + public String[] searchRolesFromGroupByGroup(final String groupPrincipalUid, + SearchControls cons) throws NamingException { + + String query = "(&(" + getGroupIdAttribute() + "=" + (groupPrincipalUid) + ")" + getGroupFilter() + + ")"; + + if (logger.isDebugEnabled()) { + logger.debug("query[" + query + "]"); + } + + ArrayList rolePrincipalUids = new ArrayList(); + + NamingEnumeration results = ((DirContext) ctx).search("", query, cons); + + while (results.hasMore()) { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + List newAttrs = new ArrayList(); + + Attribute userPrincipalUid = getAttribute( + getGroupMembershipForRoleAttribute(), answer); + List attrs = getAttributes(userPrincipalUid); + Iterator it = attrs.iterator(); + while (it.hasNext()) { + String uidfull = (String) it.next(); + String uid = extractUid(uidfull); + if (uidfull.indexOf(getRoleFilterBase())!=-1) + newAttrs.add(uid); + } + rolePrincipalUids.addAll(newAttrs); + } + return (String[]) rolePrincipalUids + .toArray(new String[rolePrincipalUids.size()]); + } + + /* + * (non-Javadoc) + * + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao#searchUsersFromGroupByUser(java.lang.String, + * javax.naming.directory.SearchControls) + */ + public String[] searchRolesFromGroupByRole(final String groupPrincipalUid, + SearchControls cons) throws NamingException { + + String subfilter = getGroupIdAttribute() + "=" + groupPrincipalUid; + if (getGroupFilterBase() != null && !getGroupFilterBase().equals("")) + subfilter += "," + getGroupFilterBase() + "," + getRootContext(); + String query = "(&(" + getRoleGroupMembershipForRoleAttribute() + "=" + + subfilter + ")" + getUserFilter() + ")"; + if (logger.isDebugEnabled()) { + logger.debug("query[" + query + "]"); + } + NamingEnumeration results = ((DirContext) ctx).search("", query, cons); + + ArrayList userPrincipalUids = new ArrayList(); + + while (results.hasMore()) { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + userPrincipalUids + .addAll(getAttributes(getAttribute("uid", answer))); + } + return (String[]) userPrincipalUids + .toArray(new String[userPrincipalUids.size()]); + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao#searchUsersFromRoleByRole(java.lang.String, javax.naming.directory.SearchControls) + */ + public String[] searchUsersFromRoleByRole(final String rolePrincipalUid, SearchControls cons) + throws NamingException + { + + String query = "(&(" + getRoleIdAttribute() + "=" + (rolePrincipalUid) + ")" + getRoleFilter() + ")"; + + if (logger.isDebugEnabled()) + { + logger.debug("query[" + query + "]"); + } + + ArrayList userPrincipalUids=new ArrayList(); + + NamingEnumeration results = ((DirContext) ctx).search("",query , cons); + + while (results.hasMore()) + { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + //List cUserPrincipalUid = getAttributes(getAttribute(getRoleMembershipAttribute(), answer)); + //TODO: better implementtion + List newAttrs = new ArrayList(); + + Attribute userPrincipalUid = getAttribute(getRoleMembershipAttribute(), answer); + List attrs = getAttributes(userPrincipalUid); + Iterator it = attrs.iterator(); + while(it.hasNext()) { + String uidfull = (String)it.next(); + String uid = extractUid(uidfull); + newAttrs.add(uid); + } + userPrincipalUids.addAll(newAttrs); + + + //userPrincipalUids.addAll(cUserPrincipalUid); + } + return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao#searchUsersFromRoleByUser(java.lang.String, javax.naming.directory.SearchControls) + */ + public String[] searchUsersFromRoleByUser(final String rolePrincipalUid, SearchControls cons) + throws NamingException + { + + //TODO: rename params / vars !!! + String subfilter = getRoleIdAttribute() + "=" + rolePrincipalUid; + if (getRoleFilterBase()!=null && !getRoleFilterBase().equals("")) subfilter+="," + getRoleFilterBase(); + subfilter+="," + getRootContext(); + String query = "(&(" + getUserRoleMembershipAttribute() + "=" + subfilter + ")" + getUserFilter() + ")"; + if (logger.isDebugEnabled()) + { + logger.debug("query[" + query + "]"); + } + NamingEnumeration results = ((DirContext) ctx).search("", query, cons); + + ArrayList userPrincipalUids = new ArrayList(); + + while (results.hasMore()) + { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + userPrincipalUids.addAll(getAttributes(getAttribute("uid", answer))); + } + return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); + } + + + /** + * @param attr + * @return + * @throws NamingException + */ + protected List getAttributes(Attribute attr) throws NamingException + { + List uids = new ArrayList(); + if (attr != null) + { + Enumeration groupUidEnum = attr.getAll(); + while (groupUidEnum.hasMoreElements()) + { + uids.add(groupUidEnum.nextElement()); + } + } + return uids; + } + + /** + * @param results + * @return + * @throws NamingException + */ + private Attributes getFirstUser(NamingEnumeration results) throws NamingException + { + SearchResult result = (SearchResult) results.next(); + Attributes answer = result.getAttributes(); + + return answer; + } + + protected String getEntryPrefix() { + return "uid"; + } + + protected String getSearchSuffix() { + return this.getUserFilter(); + } + + /** + *+ * A template method for defining the attributes for a particular LDAP class. + *
+ * + * @param principalUid The principal uid. + * @return the LDAP attributes object for the particular class. + */ + protected Attributes defineLdapAttributes(final String principalUid) + { + Attributes attrs = new BasicAttributes(true); + BasicAttribute classes = new BasicAttribute("objectclass"); + + classes.add("top"); + classes.add("person"); + classes.add("organizationalPerson"); + classes.add("inetorgperson"); + attrs.put(classes); + attrs.put("cn", principalUid); + attrs.put("sn", principalUid); + + return attrs; + } + + /** + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix() + */ + protected String getDnSuffix() + { + return this.getUserFilterBase(); + } + + /** + *+ * Creates a GroupPrincipal object. + *
+ * + * @param principalUid The principal uid. + * @return A group principal object. + */ + protected Principal makePrincipal(String principalUid) + { + return new UserPrincipalImpl(principalUid); + } + + private String extractUid(String ldapName) { + if (ldapName.indexOf(",")!=-1) + return ldapName.substring(ldapName.indexOf("uid=")+4,ldapName.indexOf(",")); + return ldapName.substring(ldapName.indexOf("uid=")+4,ldapName.length()); + } + + private String extractCn(String ldapName) { + if (ldapName.indexOf(",")!=-1) + return ldapName.substring(ldapName.indexOf("cn=")+3,ldapName.indexOf(",")); + return ldapName.substring(ldapName.indexOf("cn=")+3,ldapName.length()); + } + + protected String[] getObjectClasses() { + return this.getUserObjectClasses(); + } + + +} Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapMembershipDao.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapMembershipDao.java (revision 0) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapMembershipDao.java (revision 0) @@ -0,0 +1,86 @@ +package org.apache.jetspeed.security.spi.impl.ldap; + +import javax.naming.NamingException; +import javax.naming.directory.SearchControls; + +public interface LdapMembershipDao { + + public abstract String[] searchGroupMemberShipByGroup( + final String userPrincipalUid, SearchControls cons) + throws NamingException; + + public abstract String[] searchGroupMemberShipByUser( + final String userPrincipalUid, SearchControls cons) + throws NamingException; + + public abstract String[] searchRoleMemberShipByRole( + final String userPrincipalUid, SearchControls cons) + throws NamingException; + + public abstract String[] searchRoleMemberShipByUser( + final String userPrincipalUid, SearchControls cons) + throws NamingException; + + /** + *+ * Search user by group using the GroupMembershipAttribute. + *
+ * + * @param groupPrincipalUid + * @param cons + * @return + * @throws NamingException A {@link NamingException}. + */ + public abstract String[] searchUsersFromGroupByGroup( + final String groupPrincipalUid, SearchControls cons) + throws NamingException; + + /** + *+ * Search user by group using the UserGroupMembershipAttribute. + *
+ * + * @param groupPrincipalUid + * @param cons + * @return + * @throws NamingException A {@link NamingException}. + */ + public abstract String[] searchUsersFromGroupByUser( + final String groupPrincipalUid, SearchControls cons) + throws NamingException; + + /** + *+ * Search user by role using the RoleMembershipAttribute. + *
+ * + * @param groupPrincipalUid + * @param cons + * @return + * @throws NamingException A {@link NamingException}. + */ + public abstract String[] searchUsersFromRoleByRole( + final String rolePrincipalUid, SearchControls cons) + throws NamingException; + + /** + *+ * Search user by role using the UserRoleMembershipAttribute. + *
+ * + * @param groupPrincipalUid + * @param cons + * @return + * @throws NamingException A {@link NamingException}. + */ + public abstract String[] searchUsersFromRoleByUser( + final String groupPrincipalUid, SearchControls cons) + throws NamingException; + + public abstract String[] searchRolesFromGroupByGroup(final String groupPrincipalUid, + SearchControls cons) throws NamingException; + + public abstract String[] searchRolesFromGroupByRole(final String groupPrincipalUid, + SearchControls cons) throws NamingException; + +} Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java (revision 446621) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java (working copy) @@ -46,9 +46,7 @@ /** The logger. */ private static final Log logger = LogFactory.getLog(LdapPrincipalDaoImpl.class); - /** The uid attribute name. */ - protected String UID_ATTR_NAME = "uid"; - + /** ** Default constructor. @@ -102,7 +100,9 @@ Attributes attrs = defineLdapAttributes(principalUid); try { - String userDn = getEntryPrefix() + "=" + principalUid + getDnSuffix(); + String userDn = getEntryPrefix() + "=" + principalUid; + if (getDnSuffix()!=null && !getDnSuffix().equals("")) userDn+="," + getDnSuffix();// + ',' + getDefaultSearchBase(); + ctx.createSubcontext(userDn, attrs); if (logger.isDebugEnabled()) { @@ -261,7 +261,7 @@ { Attributes atts = searchResult.getAttributes(); - String uid = (String) getAttribute(UID_ATTR_NAME, atts).getAll().next(); + String uid = (String) getAttribute(getEntryPrefix(), atts).getAll().next(); Principal principal = makePrincipal(uid); principals.add(principal); @@ -288,5 +288,9 @@ } return null; } + + protected String getSearchDomain() { + return this.getUserFilterBase(); + } } \ No newline at end of file Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapRoleDaoImpl.java =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapRoleDaoImpl.java (revision 446621) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapRoleDaoImpl.java (working copy) @@ -1,133 +1,120 @@ -/* - * Copyright 2000-2001,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.security.spi.impl.ldap; - -import java.security.Principal; - -import javax.naming.directory.Attributes; -import javax.naming.directory.BasicAttribute; -import javax.naming.directory.BasicAttributes; - -import org.apache.commons.lang.StringUtils; -import org.apache.jetspeed.security.SecurityException; -import org.apache.jetspeed.security.impl.RolePrincipalImpl; - -/** - *
- * DAO for handling group objects. - *
- * - * @author Davy De Waele - */ -public class LdapRoleDaoImpl extends LdapPrincipalDaoImpl -{ - - protected String UID_ATTR_NAME = "cn"; - - /** - *- * Default constructor. - *
- * - * @throws SecurityException A {@link SecurityException}. - */ - public LdapRoleDaoImpl() throws SecurityException - { - super(); - } - - /** - *- * Initializes the dao. - *
- * - * @param ldapConfig Holds the ldap binding configuration. - * @throws SecurityException A {@link SecurityException}. - */ - public LdapRoleDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException - { - super(ldapConfig); - } - - /** - *- * A template method for defining the attributes for a particular LDAP class. - *
- * - * @param principalUid The principal uid. - * @return The LDAP attributes object for the particular class. - */ - protected Attributes defineLdapAttributes(final String principalUid) - { - Attributes attrs = new BasicAttributes(true); - BasicAttribute classes = new BasicAttribute("objectclass"); - - classes.add("top"); - classes.add("uidObject"); - classes.add("jetspeed-2-role"); - attrs.put(classes); - attrs.put("uid", principalUid); - attrs.put("cn", principalUid); - attrs.put("ou", getRolesOu()); - return attrs; - } - - /** - * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix() - */ - protected String getDnSuffix() - { - String suffix = ""; - if (!StringUtils.isEmpty(getRolesOu())) - { - suffix += ",ou=" + getRolesOu(); - } - if (!StringUtils.isEmpty(getDefaultDnSuffix())) - { - suffix += getDefaultDnSuffix(); - } - return suffix; - } - - /** - *- * Creates a GroupPrincipal object. - *
- * - * @param principalUid The principal uid. - * @return A group principal object. - */ - protected Principal makePrincipal(String principalUid) - { - return new RolePrincipalImpl(principalUid); - } - - /** - *- * A template method that returns the LDAP object class of the concrete DAO. - *
- * - * @return A String containing the LDAP object class name. - */ - protected String getObjectClass() - { - return "jetspeed-2-role"; - } - - protected String getEntryPrefix() { - return "cn"; - } -} +/* + * Copyright 2000-2001,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.spi.impl.ldap; + +import java.security.Principal; + +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; + +import org.apache.jetspeed.security.SecurityException; +import org.apache.jetspeed.security.impl.RolePrincipalImpl; + +/** + *+ * DAO for handling group objects. + *
+ * + * @author Davy De Waele + */ +public class LdapRoleDaoImpl extends LdapPrincipalDaoImpl +{ + + /** + *+ * Default constructor. + *
+ * + * @throws SecurityException A {@link SecurityException}. + */ + public LdapRoleDaoImpl() throws SecurityException + { + super(); + } + + /** + *+ * Initializes the dao. + *
+ * + * @param ldapConfig Holds the ldap binding configuration. + * @throws SecurityException A {@link SecurityException}. + */ + public LdapRoleDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException + { + super(ldapConfig); + } + + /** + *+ * A template method for defining the attributes for a particular LDAP class. + *
+ * + * @param principalUid The principal uid. + * @return The LDAP attributes object for the particular class. + */ + protected Attributes defineLdapAttributes(final String principalUid) + { + Attributes attrs = new BasicAttributes(true); + BasicAttribute classes = new BasicAttribute("objectclass"); + + for (int i=0;i@@ -62,7 +53,8 @@ */ public LdapUserPrincipalDaoImpl() throws SecurityException { - super(); + super(); + membership=new LdapMemberShipDaoImpl(); } /** @@ -75,7 +67,8 @@ */ public LdapUserPrincipalDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException { - super(ldapConfig); + super(ldapConfig); + membership=new LdapMemberShipDaoImpl(ldapConfig); } /** @@ -84,7 +77,11 @@ */ public void addGroup(String userPrincipalUid, String groupPrincipalUid) throws SecurityException { - modifyUserGroup(userPrincipalUid, groupPrincipalUid, DirContext.ADD_ATTRIBUTE); + if (getUserGroupMembershipAttribute()!=null && !getUserGroupMembershipAttribute().equals("")) + modifyUserGroupByUser(userPrincipalUid, groupPrincipalUid, DirContext.ADD_ATTRIBUTE); + else + modifyUserGroupByGroup(userPrincipalUid, groupPrincipalUid, DirContext.ADD_ATTRIBUTE); + } /** @@ -97,7 +94,7 @@ * @param operationType whether to replace or remove the specified user group from the user * @throws SecurityException A {@link SecurityException}. */ - private void modifyUserGroup(String userPrincipalUid, String groupPrincipalUid, int operationType) + private void modifyUserGroupByGroup(String userPrincipalUid, String groupPrincipalUid, int operationType) throws SecurityException { validateUid(userPrincipalUid); @@ -102,14 +99,59 @@ { validateUid(userPrincipalUid); validateUid(groupPrincipalUid); - String userDn = lookupByUid(userPrincipalUid); + + String userDn = "uid=" + userPrincipalUid + "," + getUserFilterBase(); + userDn+="," + getRootContext(); + try + { + groupPrincipalUid = getGroupIdAttribute() + "=" + groupPrincipalUid; + + if (getGroupFilterBase()!=null && !getGroupFilterBase().equals("")) + groupPrincipalUid+="," + getGroupFilterBase(); + groupPrincipalUid+="," + getRootContext(); + + String rdn = getSubcontextName(groupPrincipalUid); + Attributes attrs = new BasicAttributes(false); + attrs.put(getGroupMembershipAttribute(), userDn); + ctx.modifyAttributes(rdn, operationType, attrs); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } + + /** + *
+ * Replace or delete the user group attribute. + *
+ * + * @param userPrincipalUid + * @param groupPrincipalUid + * @param operationType whether to replace or remove the specified user group from the user + * @throws SecurityException A {@link SecurityException}. + */ + private void modifyUserGroupByUser(String userPrincipalUid, String groupPrincipalUid, int operationType) + throws SecurityException + { + validateUid(userPrincipalUid); + validateUid(groupPrincipalUid); + + String userDn = "uid=" + userPrincipalUid + "," + getUserFilterBase(); try { + groupPrincipalUid = getGroupIdAttribute() + "=" + groupPrincipalUid; + + if (getGroupFilterBase()!=null && !getGroupFilterBase().equals("")) + groupPrincipalUid+="," + getGroupFilterBase(); + groupPrincipalUid+="," + getRootContext(); String rdn = getSubcontextName(userDn); Attributes attrs = new BasicAttributes(false); - attrs.put("j2-group", groupPrincipalUid); + attrs.put(getUserGroupMembershipAttribute(), groupPrincipalUid); + logger.debug("modifying attrs on " + rdn + " with : " + attrs); ctx.modifyAttributes(rdn, operationType, attrs); + } catch (NamingException e) { @@ -115,7 +157,7 @@ { throw new SecurityException(e); } - } + } /** * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String, @@ -123,7 +165,11 @@ */ public void removeGroup(String userPrincipalUid, String groupPrincipalUid) throws SecurityException { - modifyUserGroup(userPrincipalUid, groupPrincipalUid, DirContext.REMOVE_ATTRIBUTE); + if (getUserGroupMembershipAttribute()!=null && !getUserGroupMembershipAttribute().equals("")) + modifyUserGroupByUser(userPrincipalUid, groupPrincipalUid, DirContext.REMOVE_ATTRIBUTE); + else + modifyUserGroupByGroup(userPrincipalUid, groupPrincipalUid, DirContext.REMOVE_ATTRIBUTE); + } /** @@ -132,7 +178,10 @@ */ public void addRole(String userPrincipalUid, String rolePrincipalUid) throws SecurityException { - modifyUserRole(userPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); + if (getUserRoleMembershipAttribute()!=null && !getUserRoleMembershipAttribute().equals("")) + modifyUserRoleByUser(userPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); + else + modifyUserRoleByRole(userPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); } /** @@ -138,6 +187,7 @@ /** ** Replace or delete the role attribute. + * *
* * @param userPrincipalUid @@ -145,7 +195,7 @@ * @param operationType whether to replace or remove the specified user group from the user * @throws SecurityException A {@link SecurityException}. */ - private void modifyUserRole(String userPrincipalUid, String rolePrincipalUid, int operationType) + private void modifyUserRoleByUser(String userPrincipalUid, String rolePrincipalUid, int operationType) throws SecurityException { validateUid(userPrincipalUid); @@ -154,10 +204,15 @@ try { + rolePrincipalUid = getRoleIdAttribute() + "=" + rolePrincipalUid; + + if (getRoleFilterBase()!=null && !getRoleFilterBase().equals("")) + rolePrincipalUid+="," + getRoleFilterBase(); + rolePrincipalUid+="," + getRootContext(); String rdn = getSubcontextName(userDn); Attributes attrs = new BasicAttributes(false); - attrs.put("j2-role", rolePrincipalUid); + attrs.put(getUserRoleMembershipAttribute(), rolePrincipalUid); ctx.modifyAttributes(rdn, operationType, attrs); } catch (NamingException e) @@ -167,6 +222,42 @@ } /** + *+ * Replace or delete the role attribute. + * + *
+ * + * @param userPrincipalUid + * @param rolePrincipalUid + * @param operationType whether to replace or remove the specified user group from the user + * @throws SecurityException A {@link SecurityException}. + */ + private void modifyUserRoleByRole(String userPrincipalUid, String rolePrincipalUid, int operationType) + throws SecurityException + { + validateUid(userPrincipalUid); + validateUid(rolePrincipalUid); + String userDn = "uid=" + userPrincipalUid + "," + getUserFilterBase() + "," + getRootContext(); + + try + { + rolePrincipalUid = getRoleIdAttribute() + "=" + rolePrincipalUid; + + if (getRoleFilterBase()!=null && !getRoleFilterBase().equals("")) + rolePrincipalUid+="," + getRoleFilterBase(); + + String rdn = getSubcontextName(rolePrincipalUid); + Attributes attrs = new BasicAttributes(false); + + attrs.put(getRoleMembershipAttribute(), userDn); + ctx.modifyAttributes(rdn, operationType, attrs); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } + /** * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String, * java.lang.String) */ @@ -172,7 +263,10 @@ */ public void removeRole(String userPrincipalUid, String rolePrincipalUid) throws SecurityException { - modifyUserRole(userPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); + if (getUserRoleMembershipAttribute()!=null && !getUserRoleMembershipAttribute().equals("")) + modifyUserRoleByUser(userPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); + else + modifyUserRoleByRole(userPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); } /** @@ -188,18 +282,12 @@ Attributes attrs = new BasicAttributes(true); BasicAttribute classes = new BasicAttribute("objectclass"); - classes.add("top"); - classes.add("person"); - classes.add("uidObject"); - classes.add("organizationalPerson"); - classes.add("inetorgperson"); - classes.add("jetspeed-2-user"); + for (int i=0;i- * Return an array of the user principal UIDS that belong to a group. - *
- * - * @param groupPrincipalUid The group principal uid. - * @return The array of user uids asociated with this group - * @throws SecurityException A {@link SecurityException}. - */ - public String[] getUserUidsForGroup(String groupPrincipalUid) throws SecurityException - { - validateUid(groupPrincipalUid); - SearchControls cons = setSearchControls(); - NamingEnumeration results; - try - { - List userPrincipalUids = new ArrayList(); - results = searchUserByGroup(groupPrincipalUid, cons); - while (results.hasMore()) - { - SearchResult result = (SearchResult) results.next(); - Attributes answer = result.getAttributes(); - - userPrincipalUids.addAll(getAttributes(getAttribute(UID_ATTR_NAME, answer))); - } - return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); - } - catch (NamingException e) - { - throw new SecurityException(e); - } - } - - /** - *- * Return an array of the roles that belong to a group. - *
- * - * @param groupPrincipalUid The group principal uid. - * @return The array of user uids asociated with this group - * @throws SecurityException A {@link SecurityException}. - */ - public String[] getRolesForGroup(String groupPrincipalUid) throws SecurityException - { - validateUid(groupPrincipalUid); - SearchControls cons = setSearchControls(); - NamingEnumeration results; - try - { - List userPrincipalUids = new ArrayList(); - results = searchRolesByGroup(groupPrincipalUid, cons); - while (results.hasMore()) - { - SearchResult result = (SearchResult) results.next(); - Attributes answer = result.getAttributes(); - - userPrincipalUids.addAll(getAttributes(getAttribute(ROLE_ATTR_NAME, answer))); - } - return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); - } - catch (NamingException e) - { - throw new SecurityException(e); - } - } - - /** * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#addGroup(java.lang.String, * java.lang.String) */ @@ -317,7 +319,11 @@ */ public void addRoleToGroup(String groupPrincipalUid, String rolePrincipalUid) throws SecurityException { - modifyGroupRole(groupPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); + if (getRoleGroupMembershipForRoleAttribute()!=null && !getRoleGroupMembershipForRoleAttribute().equals("")) + modifyRoleGroupByRole(groupPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); + else + modifyRoleGroupByGroup(groupPrincipalUid, rolePrincipalUid, DirContext.ADD_ATTRIBUTE); + } /** @@ -330,7 +336,7 @@ * @param operationType whether to replace or remove the specified user group from the user * @throws SecurityException A {@link SecurityException}. */ - private void modifyGroupRole(String groupPrincipalUid, String rolePrincipalUid, int operationType) + private void modifyRoleGroupByRole(String groupPrincipalUid, String rolePrincipalUid, int operationType) throws SecurityException { validateUid(groupPrincipalUid); @@ -338,10 +344,15 @@ String userDn = lookupGroupByUid(groupPrincipalUid); try { + groupPrincipalUid = getGroupIdAttribute() + "=" + groupPrincipalUid; + + if (getRoleFilterBase()!=null && !getRoleFilterBase().equals("")) + rolePrincipalUid+="," + getRoleFilterBase(); + String rdn = getSubcontextName(userDn); Attributes attrs = new BasicAttributes(false); - attrs.put("j2-role", rolePrincipalUid); + attrs.put(getRoleGroupMembershipForRoleAttribute(), rolePrincipalUid); ctx.modifyAttributes(rdn, operationType, attrs); } catch (NamingException e) @@ -349,92 +360,35 @@ throw new SecurityException(e); } } - - /** - * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String, - * java.lang.String) - */ - public void removeRoleFromGroup(String groupPrincipalUid, String rolePrincipalUid) throws SecurityException - { - modifyGroupRole(groupPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); - } - /** *- * Search user by group. + * Replace or delete the user group attribute. *
* + * @param userPrincipalUid * @param groupPrincipalUid - * @param cons - * @return - * @throws NamingException A {@link NamingException}. - */ - private NamingEnumeration searchUserByGroup(final String groupPrincipalUid, SearchControls cons) - throws NamingException - { - String query = "(&(" + GROUP_ATTR_NAME + "=" + (groupPrincipalUid) + ") (objectclass=" + getObjectClass() + "))"; - if (logger.isDebugEnabled()) - { - logger.debug("query[" + query + "]"); - } - NamingEnumeration searchResults = ((DirContext) ctx).search("",query , cons); - - return searchResults; - } - - /** - *- * Search user by group. - *
- * - * @param groupPrincipalUid - * @param cons - * @return - * @throws NamingException A {@link NamingException}. - */ - private NamingEnumeration searchRolesByGroup(final String rolePrincipalUid, SearchControls cons) - throws NamingException - { - String query = "(&(" + UID_ATTR_NAME + "=" + (rolePrincipalUid) + ") (objectclass=" + "jetspeed-2-group" + "))"; - if (logger.isDebugEnabled()) - { - logger.debug("query[" + query + "]"); - } - NamingEnumeration searchResults = ((DirContext) ctx).search("",query , cons); - - return searchResults; - } - - - - - /** - *- * Return an array of the user principal UIDS that belong to a group. - *
- * - * @param groupPrincipalUid The group principal uid. - * @return The array of user uids asociated with this group + * @param operationType whether to replace or remove the specified user group from the user * @throws SecurityException A {@link SecurityException}. */ - public String[] getUserUidsForRole(String rolePrincipalUid) throws SecurityException + private void modifyRoleGroupByGroup(String groupPrincipalUid, String rolePrincipalUid, int operationType) + throws SecurityException { + validateUid(groupPrincipalUid); validateUid(rolePrincipalUid); - SearchControls cons = setSearchControls(); - NamingEnumeration results; + String userDn = lookupGroupByUid(groupPrincipalUid); try { - List userPrincipalUids = new ArrayList(); - results = searchUserByRole(rolePrincipalUid, cons); - while (results.hasMore()) - { - SearchResult result = (SearchResult) results.next(); - Attributes answer = result.getAttributes(); + rolePrincipalUid = getRoleIdAttribute() + "=" + rolePrincipalUid; + + if (getRoleFilterBase()!=null && !getRoleFilterBase().equals("")) + rolePrincipalUid+="," + getRoleFilterBase(); + + String rdn = getSubcontextName(userDn); + Attributes attrs = new BasicAttributes(false); - userPrincipalUids.addAll(getAttributes(getAttribute(UID_ATTR_NAME, answer))); - } - return (String[]) userPrincipalUids.toArray(new String[userPrincipalUids.size()]); + attrs.put(getGroupMembershipForRoleAttribute(), rolePrincipalUid); + ctx.modifyAttributes(rdn, operationType, attrs); } catch (NamingException e) { @@ -440,156 +394,168 @@ { throw new SecurityException(e); } - } + } /** - *- * Search user by group. - *
- * - * @param groupPrincipalUid - * @param cons - * @return - * @throws NamingException A {@link NamingException}. + * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String, + * java.lang.String) */ - private NamingEnumeration searchUserByRole(final String rolePrincipalUid, SearchControls cons) - throws NamingException + public void removeRoleFromGroup(String groupPrincipalUid, String rolePrincipalUid) throws SecurityException { - - String query = "(&(" + ROLE_ATTR_NAME + "=" + (rolePrincipalUid) + ") (objectclass=" + getObjectClass() - + "))"; - if (logger.isDebugEnabled()) - { - logger.debug("query[" + query + "]"); - } - NamingEnumeration searchResults = ((DirContext) ctx).search("", query, cons); - - return searchResults; - } - + + if (getRoleGroupMembershipForRoleAttribute()!=null && !getRoleGroupMembershipForRoleAttribute().equals("")) + modifyRoleGroupByRole(groupPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); + else + modifyRoleGroupByGroup(groupPrincipalUid, rolePrincipalUid, DirContext.REMOVE_ATTRIBUTE); + + } - /** - * @param userPrincipalUid - * @return the array of group uids asociated with this user - * @throws SecurityException - */ - public String[] getGroupUidsForUser(String userPrincipalUid) throws SecurityException - { - validateUid(userPrincipalUid); - SearchControls cons = setSearchControls(); - NamingEnumeration results; - try - { - results = searchByWildcardedUid(userPrincipalUid, cons); - return getGroups(results, userPrincipalUid); - } - catch (NamingException e) - { - throw new SecurityException(e); - } - } - /** - *- * Get the groups. - *
- * - * @param results - * @param uid - * @return - * @throws NamingException - */ - private String[] getGroups(final NamingEnumeration results, final String uid) throws NamingException - { - if (!results.hasMore()) - { - throw new NamingException("Could not find any user with uid[" + uid + "]"); - } - - Attributes userAttributes = getFirstUser(results); - - List uids = getAttributes(getAttribute(GROUP_ATTR_NAME, userAttributes)); - return (String[]) uids.toArray(new String[uids.size()]); - } + protected String getEntryPrefix() { + return this.getUserIdAttribute(); + } - - /** - * @param userPrincipalUid - * @return the array of group uids asociated with this user - * @throws SecurityException - */ - public String[] getRoleUidsForUser(String userPrincipalUid) throws SecurityException - { - validateUid(userPrincipalUid); - SearchControls cons = setSearchControls(); - NamingEnumeration results; - try - { - results = searchByWildcardedUid(userPrincipalUid, cons); - return getRoles(results, userPrincipalUid); - } - catch (NamingException e) - { - throw new SecurityException(e); - } - } + protected String getSearchSuffix() { + return this.getUserFilter(); + } - /** - *- * Get the groups. - *
- * - * @param results - * @param uid - * @return - * @throws NamingException - */ - private String[] getRoles(final NamingEnumeration results, final String uid) throws NamingException - { - if (!results.hasMore()) - { - throw new NamingException("Could not find any user with uid[" + uid + "]"); - } + /** + * + * Return the list of group IDs for a particular user + * + * @param userPrincipalUid + * @return the array of group uids asociated with this user + * @throws SecurityException + */ + public String[] getGroupUidsForUser(String userPrincipalUid) throws SecurityException + { + validateUid(userPrincipalUid); + SearchControls cons = setSearchControls(); + try + { + if (getUserGroupMembershipAttribute()!=null && !getUserGroupMembershipAttribute().equals("")) { + return membership.searchGroupMemberShipByUser(userPrincipalUid,cons); + } + return membership.searchGroupMemberShipByGroup(userPrincipalUid,cons); + + + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } - Attributes userAttributes = getFirstUser(results); + /** + *+ * Return an array of the roles that belong to a group. + *
+ * + * @param groupPrincipalUid The group principal uid. + * @return The array of user uids asociated with this group + * @throws SecurityException A {@link SecurityException}. + */ + public String[] getRolesForGroup(String groupPrincipalUid) throws SecurityException + { + { + validateUid(groupPrincipalUid); + SearchControls cons = setSearchControls(); + try + { + if (getRoleGroupMembershipForRoleAttribute()!=null && !getRoleGroupMembershipForRoleAttribute().equals("")) { + return membership.searchRolesFromGroupByRole(groupPrincipalUid,cons); + } + return membership.searchRolesFromGroupByGroup(groupPrincipalUid,cons); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } + } - List uids = getAttributes(getAttribute(ROLE_ATTR_NAME, userAttributes)); - return (String[]) uids.toArray(new String[uids.size()]); - } - - /** - * @param results - * @return - * @throws NamingException - */ - private Attributes getFirstUser(NamingEnumeration results) throws NamingException - { - SearchResult result = (SearchResult) results.next(); - Attributes answer = result.getAttributes(); + + /** + * + * Returns the role IDs for a particular user + * + * Looks up the user, and extracts the rolemembership attr (ex : uniquemember) + * + * @param userPrincipalUid + * @return the array of group uids asociated with this user + * @throws SecurityException + */ + public String[] getRoleUidsForUser(String userPrincipalUid) throws SecurityException + { + validateUid(userPrincipalUid); + SearchControls cons = setSearchControls(); + try + { + if (getUserRoleMembershipAttribute()!=null && !getUserRoleMembershipAttribute().equals("")) { + return membership.searchRoleMemberShipByUser(userPrincipalUid,cons); + } + return membership.searchRoleMemberShipByRole(userPrincipalUid,cons); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } - return answer; - } + /** + *+ * Return an array of the user principal UIDS that belong to a group. + *
+ * + * @param groupPrincipalUid The group principal uid. + * @return The array of user uids asociated with this group + * @throws SecurityException A {@link SecurityException}. + */ + public String[] getUserUidsForGroup(String groupPrincipalUid) throws SecurityException + { + + validateUid(groupPrincipalUid); + SearchControls cons = setSearchControls(); + try + { + if (getUserGroupMembershipAttribute()!=null && !getUserGroupMembershipAttribute().equals("")) { + return membership.searchUsersFromGroupByUser(groupPrincipalUid,cons); + } + return membership.searchUsersFromGroupByGroup(groupPrincipalUid,cons); + } + catch (NamingException e) + { + throw new SecurityException(e); + } + } - /** - * @param attr - * @return - * @throws NamingException - */ - private List getAttributes(Attribute attr) throws NamingException - { - List uids = new ArrayList(); - if (attr != null) - { - Enumeration groupUidEnum = attr.getAll(); - while (groupUidEnum.hasMoreElements()) - { - uids.add(groupUidEnum.nextElement()); - } - } - return uids; - } - - protected String getEntryPrefix() { - return "uid"; + /** + *+ * Return an array of the user principal UIDS that belong to a group. + *
+ * + * @param groupPrincipalUid The group principal uid. + * @return The array of user uids asociated with this group + * @throws SecurityException A {@link SecurityException}. + */ + public String[] getUserUidsForRole(String rolePrincipalUid) throws SecurityException + { + validateUid(rolePrincipalUid); + SearchControls cons = setSearchControls(); + try + { + if (getUserRoleMembershipAttribute()!=null && !getUserRoleMembershipAttribute().equals("")) { + return membership.searchUsersFromRoleByUser(rolePrincipalUid,cons); + } + return membership.searchUsersFromRoleByRole(rolePrincipalUid,cons); + } + catch (NamingException e) + { + throw new SecurityException(e); + } } + + protected String[] getObjectClasses() { + return this.getUserObjectClasses(); + } } \ No newline at end of file Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/company1.ldif =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/company1.ldif (revision 0) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/company1.ldif (revision 0) @@ -0,0 +1,231 @@ +# +# filters +# USER FILTER +# (&(uid=OrgUnit3User2)(objectClass=inetorgperson)) +# +# GROUP FILTER +# (objectclass=groupofuniquenames) +# +# ROLE FILTER +# +# (objectclass=nsroledefinition) +# +# +# +# + + +dn: o=sevenSeas +aci: (targetattr != "userPassword") (version 3.0; acl "Anonymous access"; allow (read, search, compare)userdn = "ldap:///anyone";) +aci: (targetattr != "nsroledn || aci || nsLookThroughLimit || nsSizeLimit || nsTimeLimit || nsIdleTimeout || passwordPolicySubentry || passwordExpirationTime || passwordExpWarned || passwordRetryCount || retryCountResetTime || accountUnlockTime || passwordHistory || passwordAllowChangeTime")(version + 3.0; acl "Allow self entry modification except for nsroledn, aci, resource limit attributes, passwordPolicySubentry and password policy state attributes"; allow (write)userdn ="ldap:///self";) +aci: (targetattr = "*")(version 3.0; acl "Configuration Administrator"; allow (all) userdn = "ldap:///uid=admin,ou=Administrators, ou=TopologyManagement, o=NetscapeRoot";) +aci: (targetattr ="*")(version 3.0;acl "Configuration Administrators Group";allow (all) (groupdn = "ldap:///cn=Configuration Administrators, ou=Groups, ou=TopologyManagement, o=NetscapeRoot");) +aci: (targetattr = "*")(version 3.0; acl "SIE Group"; allow (all)groupdn = "ldap:///o=sevenSeas";) +o: Company2 +objectClass: top +objectClass: organization +creatorsname: cn=directory manager + + +dn: ou=OrgUnit1,o=sevenSeas +ou: OrgUnit1 +objectClass: top +objectClass: organizationalunit + + +dn: ou=OrgUnit2,o=sevenSeas +ou: OrgUnit2 +objectClass: top +objectClass: organizationalunit + + +dn: ou=OrgUnit3,o=sevenSeas +ou: OrgUnit3 +objectClass: top +objectClass: organizationalunit + +dn: ou=People,ou=OrgUnit1,o=sevenSeas +ou: People +objectClass: top +objectClass: organizationalunit + +dn: ou=Groups,ou=OrgUnit1,o=sevenSeas +ou: Groups +objectClass: top +objectClass: organizationalunit + +dn: ou=Roles,ou=OrgUnit1,o=sevenSeas +ou: Roles +objectClass: top +objectClass: organizationalunit + + +dn: ou=People,ou=OrgUnit2,o=sevenSeas +ou: People +objectClass: top +objectClass: organizationalunit + +dn: ou=Groups,ou=OrgUnit2,o=sevenSeas +ou: Groups +objectClass: top +objectClass: organizationalunit + +dn: ou=Roles,ou=OrgUnit2,o=sevenSeas +ou: Roles +objectClass: top +objectClass: organizationalunit + +dn: ou=People,ou=OrgUnit3,o=sevenSeas +ou: People +objectClass: top +objectClass: organizationalunit + +dn: ou=Groups,ou=OrgUnit3,o=sevenSeas +ou: Groups +objectClass: top +objectClass: organizationalunit + +dn: ou=Roles,ou=OrgUnit3,o=sevenSeas +ou: Roles +objectClass: top +objectClass: organizationalunit + + +dn: cn=Group1,ou=Groups,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: organization +cn: Group1 + +dn: cn=Group2,ou=Groups,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: organization +cn: Group2 + + +dn: cn=Group3,ou=Groups,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: organization +cn: Group3 + +dn: cn=admin,ou=Groups,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: organization +member: uid=admin,ou=People,ou=OrgUnit1 +cn: admin + +dn: cn=manager,ou=Groups,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: organization +member: uid=admin,ou=People,ou=OrgUnit1 +cn: manager + +dn: cn=Role1,ou=Roles,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: groupOfUniqueNames +cn: Role1 + + +dn: cn=Role2,ou=Roles,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: groupOfUniqueNames +cn: Role2 + + +dn: cn=Role3,ou=Roles,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: groupOfUniqueNames +cn: Role3 + +dn: cn=admin,ou=Roles,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: groupOfUniqueNames +cn: admin + +dn: cn=manager,ou=Roles,ou=OrgUnit1,o=sevenSeas +objectClass: top +objectClass: groupOfUniqueNames +cn: manager + +dn: uid=OrgUnit1User1,ou=People,ou=OrgUnit1,o=sevenSeas +uid: OrgUnit1User1 +givenName: OrgUnit1User1 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +uniqueMember: cn=Role1,ou=Roles,ou=OrgUnit1 +userPassword: x +sn: OrgUnit1User1 +cn: OrgUnit1User1 OrgUnit1User1 + +dn: uid=OrgUnit1User2,ou=People,ou=OrgUnit1,o=sevenSeas +uid: OrgUnit1User2 +givenName: OrgUnit1User2 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +userPassword: x +sn: OrgUnit1User2 +cn: OrgUnit1User2 OrgUnit1User2 + +dn: uid=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas +uid: OrgUnit2User1 +givenName: OrgUnit2User1 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +uniqueMember: cn=Role1,ou=Roles,ou=OrgUnit1 +uniqueMember: cn=Role3,ou=Roles,ou=OrgUnit1 +userPassword: x +sn: OrgUnit2User1 +cn: OrgUnit2User1 OrgUnit2User1 + +dn: uid=OrgUnit2User2,ou=People,ou=OrgUnit2,o=sevenSeas +uid: OrgUnit2User2 +givenName: OrgUnit2User2 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +userPassword: x +sn: OrgUnit2User2 +cn: OrgUnit2User2 OrgUnit2User2 + + +dn: uid=OrgUnit3User1,ou=People,ou=OrgUnit3,o=sevenSeas +uid: OrgUnit3User1 +givenName: OrgUnit3User1 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +userPassword: x +uniqueMember: cn=Role1,ou=Roles,ou=OrgUnit1 +sn: OrgUnit3User1 +cn: OrgUnit3User1 OrgUnit3User1 + +dn: uid=OrgUnit3User2,ou=People,ou=OrgUnit3,o=sevenSeas +uid: OrgUnit3User2 +givenName: OrgUnit3User2 +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +userPassword: x +sn: OrgUnit3User2 +cn: OrgUnit3User2 OrgUnit3User2 + +dn: uid=admin,ou=People,ou=OrgUnit1,o=sevenSeas +uid: admin +givenName: admin +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetorgperson +uniqueMember: cn=admin,ou=Roles,ou=OrgUnit1 +userPassword: admin +sn: admin +cn: admin admin Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/ldap.properties =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/ldap.properties (revision 0) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/ldap.properties (revision 0) @@ -0,0 +1,59 @@ +# Ldap Configuration. + +org.apache.jetspeed.ldap.initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory +org.apache.jetspeed.ldap.ldapServerName=localhost +org.apache.jetspeed.ldap.ldapServerPort=10389 +org.apache.jetspeed.ldap.rootDn=uid\=admin\,ou\=system +org.apache.jetspeed.ldap.rootPassword=secret +org.apache.jetspeed.ldap.rootContext=o\=sevenSeas +#org.apache.jetspeed.ldap.defaultDnSuffix= +#org.apache.jetspeed.ldap.ou.users=people +#org.apache.jetspeed.ldap.ou.groups=groups +#org.apache.jetspeed.ldap.ou.roles=roles + +# define the filters needed to search for roles/groups/users +#org.apache.jetspeed.ldap.RoleFilter=(&(objectclass=ldapsubentry) (objectclass=nsroledefinition)) +org.apache.jetspeed.ldap.RoleFilter=(objectClass=groupOfUniqueNames) +org.apache.jetspeed.ldap.GroupFilter=(objectclass=organization) +org.apache.jetspeed.ldap.UserFilter=(objectclass=inetorgperson) + + +org.apache.jetspeed.ldap.UserAuthenticationFiler=(&(uid=%u)(objectclass=inetorgperson)) + +# define the way role membership occurs +# if RoleMembershipAttributes is used, membership attr will be stored on role +# if UserRoleMembershipAttributes is used, membership attr will be stored on user +org.apache.jetspeed.ldap.RoleMembershipAttributes=member +org.apache.jetspeed.ldap.UserRoleMembershipAttributes= + +# define the way group membership occurs +# if GroupMembershipAttributes is used, membership attr will be stored on group +# if UserGroupMembershipAttributes is used, membership attr will be stored on user +org.apache.jetspeed.ldap.GroupMembershipAttributes= +org.apache.jetspeed.ldap.UserGroupMembershipAttributes=uniqueMember + +# define the way group membership occurs +# if GroupMembershipAttributes is used, membership attr will be stored on group +# if UserGroupMembershipAttributes is used, membership attr will be stored on user +org.apache.jetspeed.ldap.GroupMembershipForRoleAttributes=uniqueMember +org.apache.jetspeed.ldap.RoleGroupMembershipAttributes= + +# define the default search base. (=rootContext) +org.apache.jetspeed.ldap.DefaultSearchBase=o\=sevenSeas + +# define the path to roles,groups and users +# needs to be defined without the defaultsearchbase +org.apache.jetspeed.ldap.RoleFilterBase=ou\=Roles\,ou\=OrgUnit1 +org.apache.jetspeed.ldap.GroupFilterBase=ou\=Groups\,ou\=OrgUnit1 +org.apache.jetspeed.ldap.UserFilterBase=ou\=People\,ou\=OrgUnit1 + +org.apache.jetspeed.ldap.RoleObjectClasses=top\,groupOfUniqueNames +org.apache.jetspeed.ldap.GroupObjectClasses=top\,organization +org.apache.jetspeed.ldap.UserObjectClasses=top\,person\,organizationalPerson\,inetorgperson + +# define the ID attribute used to search roles/groups/users +org.apache.jetspeed.ldap.RoleIdAttribute=cn +org.apache.jetspeed.ldap.GroupIdAttribute=cn +org.apache.jetspeed.ldap.UserIdAttribute=uid + + Index: /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/security-spi-atz.xml =================================================================== --- /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/security-spi-atz.xml (revision 0) +++ /home/davy/DEVELOPMENT/JAVA/WORKBENCH3/jetspeed-2/components/security/src/test/JETSPEED-INF/directory/config/apacheds/security-spi-atz.xml (revision 0) @@ -0,0 +1,60 @@ + + + +