protected void populateContext(DirContextAdapter adapter) { adapter.setAttributeValue("givenName", givenName); adapter.setAttributeValue("sn", sn); adapter.setAttributeValues("cn", getCn()); adapter.setAttributeValue("description", getDescription()); adapter.setAttributeValue("telephoneNumber", getTelephoneNumber()); if (getPassword() != null) { adapter.setAttributeValue("userPassword", getPassword()); } adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); }
@Test public void mappingBackToContextMatchesOriginalData() { DirContextAdapter ctx1 = createUserContext(); DirContextAdapter ctx2 = new DirContextAdapter(); ctx1.setAttributeValues("objectclass", new String[] { "top", "person", "organizationalPerson", "inetOrgPerson" }); ctx2.setDn(new DistinguishedName("ignored=ignored")); InetOrgPerson p = (InetOrgPerson) (new InetOrgPerson.Essence(ctx1)) .createUserDetails(); p.populateContext(ctx2); assertThat(ctx2).isEqualTo(ctx1); }
@Test public void copyMatchesOriginalData() { DirContextAdapter ctx1 = createUserContext(); DirContextAdapter ctx2 = new DirContextAdapter(); ctx2.setDn(new DistinguishedName("ignored=ignored")); ctx1.setAttributeValues("objectclass", new String[] { "top", "person", "organizationalPerson", "inetOrgPerson" }); InetOrgPerson p = (InetOrgPerson) (new InetOrgPerson.Essence(ctx1)) .createUserDetails(); InetOrgPerson p2 = (InetOrgPerson) new InetOrgPerson.Essence(p) .createUserDetails(); p2.populateContext(ctx2); assertThat(ctx2).isEqualTo(ctx1); }
@Test public void testMultipleRoleAttributeValuesAreMappedToAuthorities() throws Exception { LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); mapper.setConvertToUpperCase(false); mapper.setRolePrefix(""); mapper.setRoleAttributes(new String[] { "userRole" }); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("userRole", new String[] { "X", "Y", "Z" }); ctx.setAttributeValue("uid", "ani"); LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES); assertThat(user.getAuthorities()).hasSize(3); }
protected void populateContext(DirContextAdapter adapter) { super.populateContext(adapter); adapter.setAttributeValue("carLicense", carLicense); adapter.setAttributeValue("departmentNumber", departmentNumber); adapter.setAttributeValue("destinationIndicator", destinationIndicator); adapter.setAttributeValue("displayName", displayName); adapter.setAttributeValue("employeeNumber", employeeNumber); adapter.setAttributeValue("homePhone", homePhone); adapter.setAttributeValue("homePostalAddress", homePostalAddress); adapter.setAttributeValue("initials", initials); adapter.setAttributeValue("mail", mail); adapter.setAttributeValue("mobile", mobile); adapter.setAttributeValue("postalAddress", postalAddress); adapter.setAttributeValue("postalCode", postalCode); adapter.setAttributeValue("ou", ou); adapter.setAttributeValue("o", o); adapter.setAttributeValue("roomNumber", roomNumber); adapter.setAttributeValue("street", street); adapter.setAttributeValue("uid", uid); adapter.setAttributeValues("objectclass", new String[] { "top", "person", "organizationalPerson", "inetOrgPerson" }); }
/** * {@inheritDoc} */ @Override public void setAttributeValues(String name, Object[] values) { setAttributeValues(name, values, ORDER_DOESNT_MATTER); }
/** * {@inheritDoc} */ @Override public void setAttributeValues(String name, Object[] values) { setAttributeValues(name, values, ORDER_DOESNT_MATTER); }
/** * {@inheritDoc} */ @Override public void setAttributeValues(String name, Object[] values) { setAttributeValues(name, values, ORDER_DOESNT_MATTER); }
Name dn = buildDn(user); DirContextAdapter context = new DirContextAdapter(dn); context.setAttributeValues("objectclass", new String[] {"top", "person"}); context.setAttributeValue("cn", user.getFullname()); // populate more attributes ldapTemplate.bind(context);
@Override public T create(final String dn, final String cn) { final T container = newContainer(dn, cn); // First create the LDAP entry log.info("{} {} will be created as {}", type.name(), container.getName(), dn); final DirContextAdapter context = new DirContextAdapter(dn); context.setAttributeValues("objectClass", new String[] { className }); mapToContext(container, context); template.bind(context); // Return the new container return container; }
@Override public void createRecursivelyAndUnbindSubnode() { DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"}); ctx.setAttributeValue("ou", "dummy"); ctx.setAttributeValue("description", "dummy description"); ldapTemplate.bind("ou=dummy", ctx, null); ldapTemplate.bind("ou=dummy,ou=dummy", ctx, null); ldapTemplate.unbind("ou=dummy,ou=dummy"); ldapTemplate.unbind("ou=dummy"); }
public void create(String country, String company, String fullname, String lastname, String description) { DistinguishedName dn = new DistinguishedName(); dn.add("ou", country); dn.add("ou", company); dn.add("cn", fullname); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[] { "top", "person" }); ctx.setAttributeValue("cn", fullname); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.bind(dn, ctx, null); }
@Test public void testSetDnAttributesValueIdentical() { BasicAttributes attributes = new BasicAttributes(); attributes.put("uniqueMember", "cn=john doe, ou=company"); DirContextAdapter tested = new DirContextAdapter(attributes, LdapUtils.newLdapName("cn=administrators, ou=groups")); tested.setUpdateMode(true); tested.setAttributeValues("uniqueMember", new Object[]{LdapUtils.newLdapName("cn=john doe, ou=company")}); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.bind(DN, adapter, null); }
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some\\Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.unbind(DN); tested.bind(DN, adapter, null); }
@Test public void testBindAndUnbindName() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); ldapTemplate.bind(DN, adapter, null); verifyBoundCorrectData(); ldapTemplate.unbind(DN); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapter() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(DN, adapter, null); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapter() { DirContextAdapter adapter = new DirContextAdapter(DN); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); ldapTemplate.bind(adapter); verifyBoundCorrectData(); ldapTemplate.unbind(DN); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapterOnly() { DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN)); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(adapter); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapterUsingLdapName() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(LdapUtils.newLdapName(DN), adapter, null); verifyBoundCorrectData(); tested.unbind(LdapUtils.newLdapName(DN)); verifyCleanup(); }