Search in sources :

Example 1 with ClonedServerEntry

use of org.apache.directory.server.core.api.entry.ClonedServerEntry in project aws-iam-ldap-bridge by denismo.

the class AWSIAMAuthenticator method authenticate.

@Override
public LdapPrincipal authenticate(BindOperationContext bindContext) throws Exception {
    if (!isAWSAccount(bindContext) || disabled) {
        LOG.debug("Skipping " + bindContext.getDn() + " - not an AWS account");
        if (delegatedAuth == null) {
            LOG.error("Delegated auth is null");
            return null;
        }
        return delegatedAuth.authenticate(bindContext);
    }
    LOG.debug("Authenticating " + bindContext.getDn());
    byte[] password = bindContext.getCredentials();
    LookupOperationContext lookupContext = new LookupOperationContext(getDirectoryService().getAdminSession(), bindContext.getDn(), SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES);
    Entry userEntry = getDirectoryService().getPartitionNexus().lookup(lookupContext);
    if (validator.verifyIAMPassword(userEntry, new String(password))) {
        LdapPrincipal principal = new LdapPrincipal(getDirectoryService().getSchemaManager(), bindContext.getDn(), AuthenticationLevel.SIMPLE, password);
        IoSession session = bindContext.getIoSession();
        if (session != null) {
            SocketAddress clientAddress = session.getRemoteAddress();
            principal.setClientAddress(clientAddress);
            SocketAddress serverAddress = session.getServiceAddress();
            principal.setServerAddress(serverAddress);
        }
        bindContext.setEntry(new ClonedServerEntry(userEntry));
        return principal;
    } else {
        // Bad password ...
        String message = I18n.err(I18n.ERR_230, bindContext.getDn().getName());
        LOG.info(message);
        throw new LdapAuthenticationException(message);
    }
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) ClonedServerEntry(org.apache.directory.server.core.api.entry.ClonedServerEntry) LdapPrincipal(org.apache.directory.server.core.api.LdapPrincipal) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) LookupOperationContext(org.apache.directory.server.core.api.interceptor.context.LookupOperationContext) SocketAddress(java.net.SocketAddress) ClonedServerEntry(org.apache.directory.server.core.api.entry.ClonedServerEntry) IoSession(org.apache.mina.core.session.IoSession)

Aggregations

SocketAddress (java.net.SocketAddress)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 LdapPrincipal (org.apache.directory.server.core.api.LdapPrincipal)1 ClonedServerEntry (org.apache.directory.server.core.api.entry.ClonedServerEntry)1 LookupOperationContext (org.apache.directory.server.core.api.interceptor.context.LookupOperationContext)1 IoSession (org.apache.mina.core.session.IoSession)1