Announcement Announcement Module
Collapse
No announcement yet.
Issue setting uniqueName Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue setting uniqueName

    Hi folks,

    I've writing an application using spring ldap and I bascially want to be able to create users as well as user groups (roles). I can create the user objects, but then when I try to update the groups for the new user, the the group doesn;t get updated and I don't get any errors/exceptions indicating what the problem is.

    The user dn looks like this:

    Code:
    uid=<user id>,ou=people,dc=mycompany,dc=com
    and my groups dn looks like this (with my two groups also included):

    Code:
    ou=roles,dc=mycompany,dc=com
    cn=subscriber
    cn=admin
    My code to create the group is like this:

    Code:
    	@Override
    	public void create(Object suppliedObject) {
    		SystemUser sysUser = (SystemUser) suppliedObject;
    		Name userDn = buildDn(sysUser);
    		Name groupDn = buildDn(sysUser.getUserRole());
    		DirContextAdapter groupContext = new DirContextAdapter(groupDn);
    		groupContext.addAttributeValue("uniqueMember", userDn.toString());
    		ldapTemplate.modifyAttributes(groupDn, groupContext.getModificationItems());
    	}
    
    	private DistinguishedName buildDn(SystemUser sysUser) {
    		return buildDn(sysUser.getUid());
    	}
    
    	private DistinguishedName buildDn(UserRole userRole) {
    		final DistinguishedName dn = new DistinguishedName();
    		dn.add("ou", "roles");
    		if (UserRole.Admin.equals(userRole)) {
    			dn.add("cn", "admin");	
    		} else {
    			dn.add("cn", "subscriber");
    		}
    		return dn;
    	}
    	
    	private DistinguishedName buildDn(String uid) {
    		final DistinguishedName dn = new DistinguishedName();
    		dn.add("ou", "people");
    		dn.add("uid", uid);
    		return dn;
    	}
    As I'm not getting any errors thrown, I'm unsure why the entry is not being created. Has anyone got any ideas? Also, is there any way to access the base dn of dc=aepona,dc=com which is supplied in the contextSource to the ldapTemplate?

  • #2
    Just bumping this post as it's had a number of views but no suggestions. I'm going to try writing some integration tests to see whether it shines any further light on the issue. I'm using OpenDS if that means anything further to anyone?

    /KramKroc

    Comment


    • #3
      Hi folks,

      heres the ldif of the directory I'm using prior to this test:

      Code:
      dn: dc=integration,dc=test
      dc: integration
      objectClass: domain
      objectClass: top
      
      dn: ou=people, dc=integration,dc=test
      ou: people
      objectClass: organizationalUnit
      objectClass: top
      
      dn: ou=roles, dc=integration,dc=test
      ou: roles
      objectClass: organizationalUnit
      objectClass: top
      
      dn: cn=subscriber,ou=roles, dc=integration,dc=test
      objectClass: groupOfUniqueNames
      objectClass: top
      cn: subscriber
      
      dn: cn=admin,ou=roles, dc=integration,dc=test
      objectClass: groupOfUniqueNames
      objectClass: top
      cn: admin
      
      dn: uid=12345,ou=people, dc=integration,dc=test
      telephoneNumber: 12345
      mail: [email protected]
      uid: 12345
      givenName: First
      objectClass: person
      objectClass: organizationalPerson
      objectClass: inetOrgPerson
      objectClass: top
      sn: Last
      cn: First Last
      
      dn: uid=54321,ou=people, dc=integration,dc=test
      telephoneNumber: 54321
      mail: [email protected]
      uid: 12345
      givenName: Kram
      objectClass: person
      objectClass: organizationalPerson
      objectClass: inetOrgPerson
      objectClass: top
      sn: Kroc
      cn: Kram Kroc
      And here is my test code:

      Code:
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations = "/config/testLdapContext.xml")
      public class UserDAOImplIntegrationTest implements BaseLdapPathAware, InitializingBean {
      
      	private DistinguishedName baseDn;
      	
      	@Autowired
      	private LdapTemplate ldapTemplate;	
      
      	@Test
      	public void shouldUpdateGroupTableUsingGroupContext() {
      		final DistinguishedName groupDn = new DistinguishedName();
      		groupDn.add("ou", "roles");
      		groupDn.add("cn", "subscriber");
      
      		DirContextAdapter groupContext = new DirContextAdapter(groupDn);
      		
      		groupContext.addAttributeValue("uniqueMember", "uid=54321,ou=people,dc=integration,dc=test");
      
      		ldapTemplate.modifyAttributes(groupDn, groupContext.getModificationItems());
      	}
      
      	@Test
      	public void shouldUpdateGroupTableUsingOwnArray() {
      		ModificationItem[] mods = new ModificationItem[1];
      		mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("uniqueMember", "uid=12345,ou=people,dc=integration,dc=test"));
      		ldapTemplate.modifyAttributes("cn=subscriber,ou=roles",mods);
      	}
      
      	@Override
      	public void setBaseLdapPath(DistinguishedName suppliedBaseDn) {
      		this.baseDn = suppliedBaseDn;
      	}
      
      	@Override
      	public void afterPropertiesSet() throws Exception {
      		Assert.notNull(baseDn, "basePath must be set");
      		Assert.notNull(ldapTemplate, "ldapTemplate must be set");
      	}
      	
      }
      What I'm finding is that the shouldUpdateGroupTableUsingGroupContext method (which is how I thought this should be coded) does not update the cn=subscriber,ou=roles, dc=integration,dc=test directory, but the shouldUpdateGroupTableUsingOwnArray method does update the directory.

      Any ideas on why the shouldUpdateGroupTableUsingGroupContext method is not working as expected would be very much appreciated.

      /KramKroc
      Last edited by KramKroc; Nov 18th, 2010, 06:08 AM.

      Comment


      • #4
        Resolved, but unsure why...

        Hi folks,

        I finally got this working:

        Code:
        	@Test
        	public void shouldUpdateGroupTableUsingGroupContext() {
        		final DistinguishedName groupDn = new DistinguishedName();
        		groupDn.add("ou", "roles");
        		groupDn.add("cn", "subscriber");
        
        		DirContextOperations ctx = ldapTemplate.lookupContext(groupDn);
        		
        		ctx.addAttributeValue("uniqueMember", "uid=54321,ou=people,dc=integration,dc=test");
        
        		ldapTemplate.modifyAttributes(ctx);
        	}
        Can anyone explain why this works when I use DirContextOperations ctx = ldapTemplate.lookupContext(groupDn); but not when I use DirContextAdapter groupContext = new DirContextAdapter(groupDn);?

        Comment

        Working...
        X