/** * Gets the full dn of a name by prepending the name of the context it is relative to. * If the name already contains the base name, it is returned unaltered. */ public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx) throws NamingException { DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace()); if (dn.contains(baseDn)) { return dn; } baseDn.append(dn); return baseDn; }
/** * Gets the full dn of a name by prepending the name of the context it is relative to. * If the name already contains the base name, it is returned unaltered. */ public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx) throws NamingException { DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace()); if(dn.contains(baseDn)) { return dn; } baseDn.append(dn); return baseDn; }
/** * Gets the full dn of a name by prepending the name of the context it is relative to. * If the name already contains the base name, it is returned unaltered. */ public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx) throws NamingException { DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace()); if (dn.contains(baseDn)) { return dn; } baseDn.append(dn); return baseDn; }
private String buildUserRefDn(String username) { return new DistinguishedName(BASE_DN).append("cn", username).toString(); }
@Test public void testAppend() { DistinguishedName path1 = new DistinguishedName("ou=foo, OU=bar"); DistinguishedName path2 = new DistinguishedName("OU=baz"); path1.append(path2); assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar"); }
@Test public void verifyRetrievalOfLotsOfAttributeValues() { DistinguishedName testgroupDn = new DistinguishedName(OU_DN).append("cn", "testgroup"); // The 'member' attribute consists of > 1500 entries and will not be returned without range specifier. DirContextOperations ctx = ldapTemplate.lookupContext(testgroupDn); assertThat(ctx.getStringAttribute("member")).isNull(); DefaultIncrementalAttributesMapper attributeMapper = new DefaultIncrementalAttributesMapper(new String[]{"member", "cn"}); assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); String[] attributesArray = attributeMapper.getAttributesForLookup(); assertThat(attributesArray.length).isEqualTo(2); assertThat(attributesArray[0]).isEqualTo("member"); assertThat(attributesArray[1]).isEqualTo("cn"); // First iteration - there should now be more members left, but all cn values should have been collected. ldapTemplate.lookup(testgroupDn, attributesArray, attributeMapper); assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); // Only member attribute should be requested in this query. attributesArray = attributeMapper.getAttributesForLookup(); assertThat(attributesArray.length).isEqualTo(1); assertThat(attributesArray[0]).isEqualTo("member;Range=1500-*"); // Second iteration - all data should now have been collected. ldapTemplate.lookup(testgroupDn, attributeMapper.getAttributesForLookup(), attributeMapper); assertThat(attributeMapper.hasMore()).as("There should be no more results to get").isFalse(); List memberValues = attributeMapper.getValues("member"); assertThat(memberValues).isNotNull(); assertThat(memberValues).hasSize(1501); List cnValues = attributeMapper.getValues("cn"); assertThat(cnValues).isNotNull(); assertThat(cnValues).hasSize(1); }
private void createUser(String username) throws UnsupportedEncodingException { DirContextAdapter ctx = new DirContextAdapter(new DistinguishedName(OU_DN).append("cn", username)); ctx.addAttributeValue("objectclass", "top"); ctx.addAttributeValue("objectclass", "person"); ctx.addAttributeValue("objectclass", "organizationalPerson"); ctx.addAttributeValue("objectclass", "user"); ctx.setAttributeValue("givenName", username); ctx.setAttributeValue("userPrincipalName", username + "@example.com"); ctx.setAttributeValue("cn", username); ctx.setAttributeValue("description", "Dummy user"); ctx.setAttributeValue("sAMAccountName", username.toUpperCase() + "." + username.toUpperCase()); ctx.setAttributeValue("userAccountControl", "512"); String newQuotedPassword = "\"" + DEFAULT_PASSWORD + "\""; ctx.setAttributeValue("unicodePwd", newQuotedPassword.getBytes("UTF-16LE")); ldapTemplate.bind(ctx); }