Examples of LdapPrincipal


Examples of org.apache.directory.server.core.api.LdapPrincipal

    /**
     * Get back an anonymous session
     */
    public CoreSession getSession()
    {
        return new DefaultCoreSession( new LdapPrincipal( schemaManager ), this );
    }
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

        partitions.add( schemaPartition );
        systemPartition.setCacheService( cacheService );
        systemPartition.getSuffixDn().apply( schemaManager );

        adminDn = getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN );
        adminSession = new DefaultCoreSession( new LdapPrincipal( schemaManager, adminDn, AuthenticationLevel.STRONG ),
            this );

        // @TODO - NOTE: Need to find a way to instantiate without dependency on DPN
        partitionNexus = new DefaultPartitionNexus( new DefaultEntry( schemaManager, Dn.ROOT_DSE ) );
        partitionNexus.setDirectoryService( this );
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

     * {@inheritDoc}
     */
    public LdapPrincipal authenticate( BindOperationContext bindContext )
        throws Exception
    {
        LdapPrincipal principal = null;

        if ( IS_DEBUG )
        {
            LOG.debug( "Authenticating {}", bindContext.getDn() );
        }

        LdapConnectionConfig connectionConfig;
        LdapNetworkConnection ldapConnection;

        // Create a connection on the remote host
        if ( delegateTls )
        {
            connectionConfig = new LdapConnectionConfig();
            connectionConfig.setLdapHost( delegateHost );
            connectionConfig.setLdapPort( delegatePort );
            connectionConfig.setTrustManagers( new NoVerificationTrustManager() );

            ldapConnection = new LdapNetworkConnection( connectionConfig );
            ldapConnection.connect();
            ldapConnection.startTls();
        }
        else if ( delegateSsl )
        {
            connectionConfig = new LdapConnectionConfig();
            connectionConfig.setLdapHost( delegateHost );
            connectionConfig.setUseSsl( true );
            connectionConfig.setLdapPort( delegatePort );
            connectionConfig.setTrustManagers( new NoVerificationTrustManager() );

            ldapConnection = new LdapNetworkConnection( connectionConfig );
            ldapConnection.connect();
        }
        else
        {
            connectionConfig = new LdapConnectionConfig();
            connectionConfig.setLdapHost( delegateHost );
            connectionConfig.setLdapPort( delegatePort );

            ldapConnection = new LdapNetworkConnection( delegateHost, delegatePort );
            ldapConnection.connect();
        }

        ldapConnection.setTimeOut( 0L );

        try
        {
            // Try to bind
            try
            {
                ldapConnection.bind( bindContext.getDn(),
                    Strings.utf8ToString( bindContext.getCredentials() ) );

                // no need to remain bound to delegate host
                ldapConnection.unBind();
            }
            catch ( LdapException le )
            {
                String message = I18n.err( I18n.ERR_230, bindContext.getDn().getName() );
                LOG.info( message );
                throw new LdapAuthenticationException( message );
            }

            // Create the new principal
            principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(),
                AuthenticationLevel.SIMPLE,
                bindContext.getCredentials() );

            IoSession session = bindContext.getIoSession();

            if ( session != null )
            {
                SocketAddress clientAddress = session.getRemoteAddress();
                principal.setClientAddress( clientAddress );
                SocketAddress serverAddress = session.getServiceAddress();
                principal.setServerAddress( serverAddress );
            }

            return principal;

        }
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

            for ( Authenticator authenticator : authenticators )
            {
                try
                {
                    // perform the authentication
                    LdapPrincipal principal = authenticator.authenticate( bindContext );

                    LdapPrincipal clonedPrincipal = ( LdapPrincipal ) ( principal.clone() );

                    // remove creds so there is no security risk
                    bindContext.setCredentials( null );
                    clonedPrincipal.setUserPassword( StringConstants.EMPTY_BYTES );

                    // authentication was successful
                    CoreSession session = new DefaultCoreSession( clonedPrincipal, directoryService );
                    bindContext.setSession( session );
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

        forward.setChangeType( ChangeType.Add );
        forward.putAttribute( "objectClass", "organizationalUnit" );
        forward.putAttribute( "ou", "system" );

        LdifEntry reverse = LdifRevertor.reverseAdd( forward.getDn() );
        assertEquals( 1, store.log( new LdapPrincipal( schemaManager ), forward, reverse ).getRevision() );
        assertEquals( 1, store.getCurrentRevision() );
    }
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

        LdifEntry reverse = LdifRevertor.reverseAdd( reverseDn );

        String zuluTime = DateUtils.getGeneralizedTime();
        long revision = 1L;

        LdapPrincipal principal = new LdapPrincipal( schemaManager, adminDn, AuthenticationLevel.SIMPLE,
            Strings.getBytesUtf8( "secret" ) );
        ChangeLogEvent event = new ChangeLogEvent( revision, zuluTime, principal, forward, reverse );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream( baos );

        ChangeLogEventSerializer.serialize( event, out );

        byte[] data = baos.toByteArray();
        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );

        ChangeLogEvent read = ChangeLogEventSerializer.deserialize( schemaManager, in );

        // The read event should not be equal to the written event, as
        // the principal's password has not been stored
        assertNotSame( event, read );

        LdapPrincipal readPrincipal = read.getCommitterPrincipal();

        assertEquals( principal.getAuthenticationLevel(), readPrincipal.getAuthenticationLevel() );
        assertEquals( principal.getName(), readPrincipal.getName() );
        assertEquals( principal.getDn(), readPrincipal.getDn() );
        assertNull( readPrincipal.getUserPasswords() );

        assertEquals( zuluTime, read.getZuluTime() );
        assertEquals( revision, read.getRevision() );
        assertEquals( forward, read.getForwardLdif() );
        assertEquals( reverse, read.getReverseLdifs().get( 0 ) );
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

        StoreUtils.loadExampleData( store, schemaManager );

        DirectoryService directoryService = new MockDirectoryService();
        directoryService.setSchemaManager( schemaManager );
        session = new MockCoreSession( new LdapPrincipal(), directoryService );

        LOG.debug( "Created new store" );
    }
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

     * @return A byte array which can be empty if the password was not found
     * @throws Exception If we have a problem during the lookup operation
     */
    private LdapPrincipal getStoredPassword( BindOperationContext bindContext ) throws LdapException
    {
        LdapPrincipal principal = null;

        // use cache only if pwdpolicy is not enabled
        if ( !getDirectoryService().isPwdPolicyEnabled() )
        {
            synchronized ( credentialCache )
            {
                principal = ( LdapPrincipal ) credentialCache.get( bindContext.getDn().getNormName() );
            }
        }

        byte[][] storedPasswords;

        if ( principal == null )
        {
            // Not found in the cache
            // Get the user password from the backend
            storedPasswords = lookupUserPassword( bindContext );

            // Deal with the special case where the user didn't enter a password
            // We will compare the empty array with the credentials. Sometime,
            // a user does not set a password. This is bad, but there is nothing
            // we can do against that, except education ...
            if ( storedPasswords == null )
            {
                storedPasswords = new byte[][]
                    {};
            }

            // Create the new principal before storing it in the cache
            principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(),
                AuthenticationLevel.SIMPLE );
            principal.setUserPassword( storedPasswords );

            // Now, update the local cache ONLY if pwdpolicy is not enabled.
            if ( !getDirectoryService().isPwdPolicyEnabled() )
            {
                synchronized ( credentialCache )
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

        }

        // ---- extract password from JNDI environment
        byte[] credentials = bindContext.getCredentials();

        LdapPrincipal principal = getStoredPassword( bindContext );

        IoSession session = bindContext.getIoSession();

        if ( session != null )
        {
            SocketAddress clientAddress = session.getRemoteAddress();
            principal.setClientAddress( clientAddress );
            SocketAddress serverAddress = session.getServiceAddress();
            principal.setServerAddress( serverAddress );
        }

        // Get the stored password, either from cache or from backend
        byte[][] storedPasswords = principal.getUserPasswords();

        // Now, compare the passwords.
        for ( byte[] storedPassword : storedPasswords )
        {
            if ( PasswordUtil.compareCredentials( credentials, storedPassword ) )
View Full Code Here

Examples of org.apache.directory.server.core.api.LdapPrincipal

    {
        // We only allow Anonymous binds if the service allows them
        if ( getDirectoryService().isAllowAnonymousAccess() )
        {
            LOG.info( "Authentication as anonymous" );
            LdapPrincipal principal = getDirectoryService().getAdminSession().getAnonymousPrincipal();

            IoSession session = bindContext.getIoSession();

            if ( session != null )
            {
                SocketAddress clientAddress = session.getRemoteAddress();
                principal.setClientAddress( clientAddress );
                SocketAddress serverAddress = session.getServiceAddress();
                principal.setServerAddress( serverAddress );
            }

            return principal;
        }
        else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.