public Essence(DirContextOperations ctx) { setDn(ctx.getDn()); }
public DirContextOperations searchAuthenticate(DirContextOperations user, byte[] passwordBytes, SpringSecurityLdapTemplate ldapTemplate) { if (logger.isDebugEnabled()) { logger.debug("Performing LDAP compare of password attribute '" + passwordAttributeName + "' for user '" + user.getDn() + "'"); } if (!ldapTemplate.compare(user.getDn().toString(), passwordAttributeName, passwordBytes)) { throw new BadCredentialsException(messages.getMessage("PasswordComparisonAuthenticator.badCredentials", "Bad credentials")); } return user; }
private boolean isLdapPasswordCompare(DirContextOperations user, SpringSecurityLdapTemplate ldapTemplate, String password) { String encodedPassword = passwordEncoder.encode(password); byte[] passwordBytes = Utf8.encode(encodedPassword); return ldapTemplate.compare(user.getDn().toString(), passwordAttributeName, passwordBytes); }
private String getReferencedGroupValue(final DirContextOperations ctx) { final String referencedGroupValue; if (StringUtils.isBlank(userGroupReferencedGroupAttribute)) { referencedGroupValue = ctx.getDn().toString(); } else { final Attribute attributeName = ctx.getAttributes().get(userGroupReferencedGroupAttribute); if (attributeName == null) { throw new AuthorizationAccessException("Referenced group value attribute [" + userGroupReferencedGroupAttribute + "] does not exist."); } try { referencedGroupValue = (String) attributeName.get(); } catch (NamingException e) { throw new AuthorizationAccessException("Error while retrieving referenced group value attribute [" + userGroupReferencedGroupAttribute + "]."); } } return referencedGroupValue; }
private String getReferencedUserValue(final DirContextOperations ctx) { final String referencedUserValue; if (StringUtils.isBlank(groupMemberReferencedUserAttribute)) { referencedUserValue = ctx.getDn().toString(); } else { final Attribute attributeName = ctx.getAttributes().get(groupMemberReferencedUserAttribute); if (attributeName == null) { throw new AuthorizationAccessException("Referenced user value attribute [" + groupMemberReferencedUserAttribute + "] does not exist."); } try { referencedUserValue = (String) attributeName.get(); } catch (NamingException e) { throw new AuthorizationAccessException("Error while retrieving reference user value attribute [" + groupMemberReferencedUserAttribute + "]."); } } return referencedUserValue; }
private String getUserIdentity(final DirContextOperations ctx) { final String identity; if (useDnForUserIdentity) { identity = ctx.getDn().toString(); } else { final Attribute attributeName = ctx.getAttributes().get(userIdentityAttribute); if (attributeName == null) { throw new AuthorizationAccessException("User identity attribute [" + userIdentityAttribute + "] does not exist."); } try { identity = (String) attributeName.get(); } catch (NamingException e) { throw new AuthorizationAccessException("Error while retrieving user name attribute [" + userIdentityAttribute + "]."); } } return IdentityMappingUtil.mapIdentity(identity, identityMappings); }
private String getGroupName(final DirContextOperations ctx) { final String name; if (useDnForGroupName) { name = ctx.getDn().toString(); } else { final Attribute attributeName = ctx.getAttributes().get(groupNameAttribute); if (attributeName == null) { throw new AuthorizationAccessException("Group identity attribute [" + groupNameAttribute + "] does not exist."); } try { name = (String) attributeName.get(); } catch (NamingException e) { throw new AuthorizationAccessException("Error while retrieving group name attribute [" + groupNameAttribute + "]."); } } return IdentityMappingUtil.mapIdentity(name, groupMappings); }
user = bindWithDn(userFromSearch.getDn().toString(), username, password, userFromSearch.getAttributes());
+ passwordAttributeName + "' for user '" + user.getDn() + "'");
user.getDn() + "'");
public Name doMapFromContext(DirContextOperations ctx) { return ctx.getDn(); } };
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void modifyAttributes(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && ctx.isUpdateMode()) { modifyAttributes(dn, ctx.getModificationItems()); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
private boolean isLdapPasswordCompare(DirContextOperations user, SpringSecurityLdapTemplate ldapTemplate, String password) { String encodedPassword = passwordEncoder.encode(password); byte[] passwordBytes = Utf8.encode(encodedPassword); return ldapTemplate.compare(user.getDn().toString(), passwordAttributeName, passwordBytes); }
public void visit(DirContextOperations node, int currentDepth) { LdapName next = keyIterator.next(); assertThat(node.getDn()).isEqualTo(next); assertThat(currentDepth).isEqualTo(names.get(next).intValue()); } }
public void visit(DirContextOperations node, int currentDepth) { LdapName next = keyIterator.next(); assertThat(node.getDn()).isEqualTo(next); assertThat(currentDepth).isEqualTo(names.get(next).intValue()); } }
public LdapEntryIdentification mapFromContext(Object ctx) { DirContextOperations adapter = (DirContextOperations) ctx; return new LdapEntryIdentification( LdapUtils.newLdapName(adapter.getNameInNamespace()), LdapUtils.newLdapName(adapter.getDn())); } }
@Override protected Object doMapFromContext(DirContextOperations ctx) { LdapName dn = (LdapName) ctx.getDn(); Rdn rdn = LdapUtils.getRdn(dn, "cn"); assertThat(dn.toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,ou=Sweden"); assertThat(rdn.getValue()).isEqualTo("Some\\Person6"); return new Object(); } });
@Test public void testBindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.bind(dirContextOperationsMock); verify(dirContextMock).bind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }
@Test public void testRebindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.rebind(dirContextOperationsMock); verify(dirContextMock).rebind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }