@Test public void ldapCompareOperationIsUsedWhenPasswordIsNotRetrieved() throws Exception { final DirContext dirCtx = mock(DirContext.class); final BaseLdapPathContextSource source = mock(BaseLdapPathContextSource.class); final BasicAttributes attrs = new BasicAttributes(); attrs.put(new BasicAttribute("uid", "bob")); PasswordComparisonAuthenticator authenticator = new PasswordComparisonAuthenticator( source); authenticator.setUserDnPatterns(new String[] { "cn={0},ou=people" }); // Get the mock to return an empty attribute set when(source.getReadOnlyContext()).thenReturn(dirCtx); when(dirCtx.getAttributes(eq("cn=Bob,ou=people"), any(String[].class))) .thenReturn(attrs); when(dirCtx.getNameInNamespace()).thenReturn("dc=springframework,dc=org"); // Setup a single return value (i.e. success) final NamingEnumeration searchResults = new BasicAttributes("", null).getAll(); when( dirCtx.search(eq("cn=Bob,ou=people"), eq("(userPassword={0})"), any(Object[].class), any(SearchControls.class))).thenReturn( searchResults); authenticator.authenticate(new UsernamePasswordAuthenticationToken("Bob", "bobspassword")); } }
@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"); }
private BasicAttributes createSrvRecords() { BasicAttributes records = new BasicAttributes(); BasicAttribute record = new BasicAttribute("SRV"); // the structure of the service records is: // priority weight port hostname // for more information: http://en.wikipedia.org/wiki/SRV_record record.add("20 80 389 kdc3.springsource.com."); record.add("10 70 389 kdc.springsource.com."); record.add("20 20 389 kdc4.springsource.com."); record.add("10 30 389 kdc2.springsource.com"); records.put(record); return records; } }
/** * 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"); }
private DirContext appendContext(Name name, Attributes attrs) throws NamingException { TestDirContext tcd = new TestDirContext(name, this); children.put(name, tcd); for (NamingEnumeration e = attrs.getAll(); e.hasMore();) { tcd.attributes.put((Attribute) e.next()); } return tcd; }
public void addAttribute(Name dn, Attribute a) throws NamingException { BasicAttributes atts = new BasicAttributes(); atts.put(a); modifyAttributes(dn, 1, atts); }
public void addAttribute(String dn, Attribute a) throws NamingException { BasicAttributes atts = new BasicAttributes(); atts.put(a); modifyAttributes(dn, 1, atts); }
public void deleteAttribute(Name dn, Attribute a) throws NamingException { BasicAttributes atts = new BasicAttributes(); atts.put(a); modifyAttributes(dn, 3, atts); }
private void storeForwardRuleDimse(BasicAttributes attrs, List<Dimse> dimseList) { if (!dimseList.isEmpty()) { Attribute attr = new BasicAttribute("dcmForwardRuleDimse"); for (Dimse dimse : dimseList) attr.add(dimse.toString()); attrs.put(attr); } }
private static Attributes storeTo(AttributeCoercion ac, BasicAttributes attrs) { attrs.put("objectclass", "dcmAttributeCoercion"); attrs.put("cn", ac.getCommonName()); LdapUtils.storeNotNullOrDef(attrs, "dcmDIMSE", ac.getDIMSE(), null); LdapUtils.storeNotNullOrDef(attrs, "dicomTransferRole", ac.getRole(), null); LdapUtils.storeNotEmpty(attrs, "dcmAETitle", ac.getAETitles()); LdapUtils.storeNotEmpty(attrs, "dcmSOPClass", ac.getSOPClasses()); LdapUtils.storeNotNullOrDef(attrs, "dcmURI", ac.getURI(), null); return attrs; }
private static Attributes storeTo(AttributeCoercion ac, BasicAttributes attrs) { attrs.put("objectclass", "dcmAttributeCoercion"); attrs.put("cn", ac.getCommonName()); LdapUtils.storeNotNullOrDef(attrs, "dcmDIMSE", ac.getDIMSE(), null); LdapUtils.storeNotNullOrDef(attrs, "dicomTransferRole", ac.getRole(), null); LdapUtils.storeNotEmpty(attrs, "dcmAETitle", ac.getAETitles()); LdapUtils.storeNotEmpty(attrs, "dcmSOPClass", ac.getSOPClasses()); LdapUtils.storeNotNullOrDef(attrs, "dcmURI", ac.getURI(), null); return attrs; }
public void removeMember(String groupDN, String memberDN) throws Exception { LdapContext ctxt = getWiredContext(); BasicAttributes attrs = new BasicAttributes(); attrs.put("member", memberDN); ctxt.modifyAttributes(groupDN, DirContext.REMOVE_ATTRIBUTE, attrs); }
public void addMember(String groupDN, String memberDN) throws Exception { LdapContext ctxt = getWiredContext(); BasicAttributes attrs = new BasicAttributes(); attrs.put("member", memberDN); ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs); }
private static Attributes storeTo(ConfigurationChanges.ModifiedObject ldapObj, BasicBulkDataDescriptor descriptor, BasicAttributes attrs) { attrs.put("objectclass", "dcmBulkDataDescriptor"); LdapUtils.storeNotNullOrDef(ldapObj, attrs, "dcmBulkDataDescriptorID", descriptor.getBulkDataDescriptorID(), null); LdapUtils.storeNotDef(ldapObj, attrs, "dcmBulkDataExcludeDefaults", descriptor.isExcludeDefaults(), false); LdapUtils.storeNotEmpty(ldapObj, attrs, "dcmAttributeSelector", descriptor.getAttributeSelectors()); LdapUtils.storeNotEmpty(ldapObj, attrs, "dcmBulkDataVRLengthThreshold", descriptor.getLengthsThresholdsAsStrings()); return attrs; }
private Attributes storeToRetry(Retry retry, BasicAttributes attrs) { attrs.put("objectclass", "dcmRetry"); LdapUtils.storeNotNull(attrs, "dcmRetryObject", retry.getRetryObject().toString()); LdapUtils.storeNotNull(attrs, "dcmRetryDelay", retry.getDelay()); LdapUtils.storeNotNull(attrs, "dcmRetryNum", retry.getNumberOfRetries()); LdapUtils.storeNotNull(attrs, "dcmDeleteAfterFinalRetry", retry.isDeleteAfterFinalRetry()); return attrs; }
@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); }
@Test public void testAddDnAttributeSyntacticallyEqual() { 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.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }
@Test public void testAddDnAttributeValueIdentical() { 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.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); assertThat(modificationItems.length).isEqualTo(0); }
@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); }
public void addMembers(String groupDN, Iterable<String> memberDNs) throws Exception { LdapContext ctxt = getWiredContext(); Attribute attr = new BasicAttribute("member"); for (String dn : memberDNs) { attr.add(dn); } BasicAttributes attrs = new BasicAttributes(); attrs.put(attr); ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs); }