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" }); }
private DirContextAdapter createUserContext() { DirContextAdapter ctx = new DirContextAdapter(); ctx.setDn(new DistinguishedName("ignored=ignored")); ctx.setAttributeValue("uid", "ghengis"); ctx.setAttributeValue("userPassword", "pillage"); ctx.setAttributeValue("carLicense", "HORS1"); ctx.setAttributeValue("cn", "Ghengis Khan"); ctx.setAttributeValue("description", "Scary"); ctx.setAttributeValue("destinationIndicator", "West"); ctx.setAttributeValue("displayName", "Ghengis McCann"); ctx.setAttributeValue("givenName", "Ghengis"); ctx.setAttributeValue("homePhone", "+467575436521"); ctx.setAttributeValue("initials", "G"); ctx.setAttributeValue("employeeNumber", "00001"); ctx.setAttributeValue("homePostalAddress", "Steppes"); ctx.setAttributeValue("mail", "ghengis@mongolia"); ctx.setAttributeValue("mobile", "always"); ctx.setAttributeValue("o", "Hordes"); ctx.setAttributeValue("ou", "Horde1"); ctx.setAttributeValue("postalAddress", "On the Move"); ctx.setAttributeValue("postalCode", "Changes Frequently"); ctx.setAttributeValue("roomNumber", "Yurt 1"); ctx.setAttributeValue("roomNumber", "Yurt 1"); ctx.setAttributeValue("sn", "Khan"); ctx.setAttributeValue("street", "Westward Avenue"); ctx.setAttributeValue("telephoneNumber", "+442075436521"); return ctx; }
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" }); }
public DirContextOperations authenticate(Authentication authentication) { DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValue("ou", "FROM_ENTRY"); String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (username.equals("ben") && password.equals("benspassword")) { ctx.setDn(new DistinguishedName( "cn=ben,ou=people,dc=springframework,dc=org")); ctx.setAttributeValue("userPassword", "{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ="); return ctx; } else if (username.equals("jen") && password.equals("")) { ctx.setDn(new DistinguishedName( "cn=jen,ou=people,dc=springframework,dc=org")); return ctx; } throw new BadCredentialsException("Authentication failed."); } }
@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); }
@Test public void testPasswordAttributeIsMappedCorrectly() throws Exception { LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); mapper.setPasswordAttributeName("myappsPassword"); BasicAttributes attrs = new BasicAttributes(); attrs.put(new BasicAttribute("myappsPassword", "mypassword".getBytes())); DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName")); ctx.setAttributeValue("uid", "ani"); LdapUserDetails user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES); assertThat(user.getPassword()).isEqualTo("mypassword"); }
@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); }
result.setAttributeValue(ppolicy.getID(), ppolicy);
@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(); }
/** * SEC-303. Non-retrieved role attribute causes NullPointerException */ @Test public void testNonRetrievedRoleAttributeIsIgnored() throws Exception { LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); mapper.setRoleAttributes(new String[] { "userRole", "nonRetrievedAttribute" }); BasicAttributes attrs = new BasicAttributes(); attrs.put(new BasicAttribute("userRole", "x")); DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName")); ctx.setAttributeValue("uid", "ani"); LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES); assertThat(user.getAuthorities()).hasSize(1); assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities())).contains("ROLE_X"); }
@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(); }
public void update(String dn, String fullname, String lastname, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(ctx); jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] { lastname, description, fullname }); }
@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(); }
public void modifyAttributes(String dn, String lastName, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastName); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(dn, ctx.getModificationItems()); }
public void updateAndRename(String dn, String newDn, String updatedDescription) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("description", updatedDescription); ldapTemplate.modifyAttributes(ctx); ldapTemplate.rename(dn, newDn); }
public void update(OrgPerson person) { String dn = prepareDn(person); DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", person.getLastname()); ctx.setAttributeValue("description", person.getDescription()); ldapTemplate.modifyAttributes(ctx); this.getHibernateTemplate().saveOrUpdate(person); }
@Test public void testSetStringAttribute() throws Exception { assertThat(tested.isUpdateMode()).isFalse(); tested.setAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); assertThat((String) attr.get()).isEqualTo("123"); }
@Test public void testRemoveAttributeValueInUpdateModeSameValueExistsInUpdatedAttrs() { tested.setUpdateMode(true); tested.setAttributeValue("abc", "123"); // Perform test tested.removeAttributeValue("abc", "123"); assertThat(tested.getAttributes().get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }
/** * Test for LDAP-13. */ @Test public void testModifyAttributeByteArray() { tested.setAttribute(new BasicAttribute("abc", new byte[] { 1, 2, 3 })); tested.setUpdateMode(true); // Perform test tested.setAttributeValue("abc", new byte[] { 1, 2, 3 }); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }
@Test public void testSetDnAttributeValueIdentical() { 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.setAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }