@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")); } }
/** * Constructs an OtdsUserProfile representation that contains a list * of OTDS attributes, only admin level clients (including service agents) * should be able to retrieve this version. * * @param username user name * @param isAdmin is the user ad admin? * @param attributes OTDS user attributes */ public OtdsUserProfile(String username, boolean isAdmin, BasicAttributes attributes) { this.userName = username; this.userID = username; this.admin = isAdmin; this.attributes = new HashMap<>(); NamingEnumeration<Attribute> iter = attributes.getAll(); try { while (iter.hasMore()) { Attribute attribute = iter.next(); if (attribute.get() instanceof String) { this.attributes.put(attribute.getID(), (String) attribute.get()); } } } catch (NamingException e) { e.printStackTrace(); } }
for ( NamingEnumeration attrs = attributeList.getAll(); attrs.hasMoreElements(); )
@Override public void updateAttributedType(IdentityContext context, AttributedType attributedType) { // this store does not support updation of relationship types if (Relationship.class.isInstance(attributedType)) { LDAP_STORE_LOGGER.ldapRelationshipUpdateNotSupported(attributedType); } else { BasicAttributes updatedAttributes = extractAttributes(attributedType, false); NamingEnumeration<Attribute> attributes = updatedAttributes.getAll(); this.operationManager.modifyAttributes(getBindingDN(attributedType, true), attributes); } }
@Override public void updateAttributedType(IdentityContext context, AttributedType attributedType) { // this store does not support updation of relationship types if (Relationship.class.isInstance(attributedType)) { LDAP_STORE_LOGGER.ldapRelationshipUpdateNotSupported(attributedType); } else { BasicAttributes updatedAttributes = extractAttributes(attributedType, false); NamingEnumeration<Attribute> attributes = updatedAttributes.getAll(); this.operationManager.modifyAttributes(getBindingDN(attributedType, true), attributes); } }