Package org.apache.directory.ldap.client.api

Examples of org.apache.directory.ldap.client.api.LdapNetworkConnection


    @Before
    public void createConnection() throws Exception
    {
        if ( con == null )
        {
            con = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
            con.bind( "uid=admin,ou=system", "secret" );
            con.setTimeOut( Long.MAX_VALUE );
        }

        baseDn = new Dn( "ou=parent,ou=system" );
View Full Code Here


     * Tests bind operation on referral entry.
     */
    @Test
    public void testBindWithDoubleQuote() throws Exception
    {
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );

        connection.bind( "uid=\"admin\",ou=\"system\"", "secret" );
        assertTrue( connection.isAuthenticated() );
        connection.close();
    }
View Full Code Here

     * Tests bind operation on a server where the SimpleAuthenticator is disabled
     */
    @Test
    public void testBindSimpleAuthenticatorDisabled() throws Exception
    {
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.setTimeOut( 0 );

        try
        {
            connection.bind( "uid=hacker", "badsecret" );
            fail();
        }
        catch ( LdapAuthenticationException lae )
        {
            //Expected
        }

        assertFalse( connection.isAuthenticated() );

        AuthenticationInterceptor authInterceptor = ( AuthenticationInterceptor ) ldapServer.getDirectoryService()
            .getInterceptor( InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName() );
        authInterceptor.destroy();
        authInterceptor.setAuthenticators( new Authenticator[]
            { new StrongAuthenticator() } );

        try
        {
            connection.bind( "uid=hacker", "badsecret" );
            fail();
        }
        catch ( LdapAuthenticationException lae )
        {
            //Expected
        }

        // Try with an existing user
        try
        {
            connection.bind( "uid=admin,ou=system", "secret" );
            fail();
        }
        catch ( LdapAuthenticationException lae )
        {
            //Expected
        }

        assertFalse( connection.isAuthenticated() );
        connection.close();

        // Reset the authenticators
        authInterceptor.destroy();
        authInterceptor.setAuthenticators( new Authenticator[]
            { new StrongAuthenticator(), new SimpleAuthenticator(), new AnonymousAuthenticator() } );
View Full Code Here

    @Test
    public void testDelegatedAuthentication() throws Exception
    {
        assertTrue( getService().isStarted() );
        assertEquals( "DelegatedAuthIT-method", getService().getInstanceId() );
        LdapConnection ldapConnection = new LdapNetworkConnection( "localhost", 10200 );

        ldapConnection.setTimeOut( 0L );
        ldapConnection.bind( "uid=antoine,ou=users,ou=system", "secret" );

        assertTrue( ldapConnection.isAuthenticated() );

        ldapConnection.unBind();

        try
        {
            ldapConnection.bind( "uid=antoine,ou=users,ou=system", "sesame" );
            fail();
        }
        catch ( LdapAuthenticationException lae )
        {
            assertTrue( true );
        }

        ldapConnection.unBind();

        try
        {
            ldapConnection.bind( "uid=ivanhoe,ou=users,ou=system", "secret" );
            fail();
        }
        catch ( Exception exc )
        {
            assertTrue( true );
        }

        ldapConnection.unBind();
        ldapConnection.close();
    }
View Full Code Here

     * Tests to make sure PLAIN-binds works
     */
    @Test
    public void testSaslBindPLAIN() throws Exception
    {
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.setTimeOut( 0L );

        BindResponse resp = connection.bindSaslPlain( "hnelson", "secret" );
        assertEquals( ResultCodeEnum.SUCCESS, resp.getLdapResult().getResultCode() );

        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        Entry entry = connection.lookup( userDn );
        assertEquals( "hnelson", entry.get( "uid" ).getString() );

        connection.close();

        // Try to bind with a wrong user
        resp = connection.bindSaslPlain( "hnelsom", "secret" );
        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, resp.getLdapResult().getResultCode() );

        // Try to bind with a wrong password
        resp = connection.bindSaslPlain( "hnelson", "secres" );
        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, resp.getLdapResult().getResultCode() );
    }
View Full Code Here

    @Test
    @Ignore("Activate and fix when DIRAPI-36 (Provide a SaslBindRequest extending BindRequest that can be used in LdapConnection.bind(...) method) is solved")
    public void testSaslBindNoMech() throws Exception
    {
        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        BindRequest bindReq = new BindRequestImpl();
        bindReq.setCredentials( "secret" );
        bindReq.setDn( userDn );
        bindReq.setSaslMechanism( "" ); // invalid mechanism
        bindReq.setSimple( false );

        try
        {
            connection.bind( bindReq );
            fail();
        }
        catch ( LdapException le )
        {
            //expected
        }

        connection.close();
    }
View Full Code Here

     */
    @Test
    public void testSaslCramMd5Bind() throws Exception
    {
        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.setTimeOut( 0L );

        SaslCramMd5Request request = new SaslCramMd5Request();
        request.setUsername( userDn.getRdn().getValue().getString() );
        request.setCredentials( "secret" );

        BindResponse resp = connection.bind( request );
        assertEquals( ResultCodeEnum.SUCCESS, resp.getLdapResult().getResultCode() );

        Entry entry = connection.lookup( userDn );
        assertEquals( "hnelson", entry.get( "uid" ).getString() );

        connection.close();
    }
View Full Code Here

     */
    @Test
    public void testSaslCramMd5BindBadPassword() throws Exception
    {
        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );

        SaslCramMd5Request request = new SaslCramMd5Request();
        request.setUsername( userDn.getRdn().getValue().getString() );
        request.setCredentials( "badsecret" );

        BindResponse resp = connection.bind( request );
        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, resp.getLdapResult().getResultCode() );
        connection.close();
    }
View Full Code Here

     */
    @Test
    public void testSaslDigestMd5Bind() throws Exception
    {
        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );

        SaslDigestMd5Request request = new SaslDigestMd5Request();
        request.setUsername( userDn.getRdn().getValue().getString() );
        request.setCredentials( "secret" );
        request.setRealmName( ldapServer.getSaslRealms().get( 0 ) );
        BindResponse resp = connection.bind( request );
        assertEquals( ResultCodeEnum.SUCCESS, resp.getLdapResult().getResultCode() );

        Entry entry = connection.lookup( userDn );
        assertEquals( "hnelson", entry.get( "uid" ).getString() );

        connection.close();
    }
View Full Code Here

     */
    @Test
    public void testSaslDigestMd5BindSaslQoPAuth() throws Exception
    {
        Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );

        SaslDigestMd5Request request = new SaslDigestMd5Request();
        request.setUsername( userDn.getRdn().getValue().getString() );
        request.setCredentials( "secret" );
        request.setRealmName( ldapServer.getSaslRealms().get( 0 ) );
        request.setQualityOfProtection( SaslQoP.AUTH );
        BindResponse resp = connection.bind( request );
        assertEquals( ResultCodeEnum.SUCCESS, resp.getLdapResult().getResultCode() );

        Entry entry = connection.lookup( userDn );
        assertEquals( "hnelson", entry.get( "uid" ).getString() );

        connection.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.ldap.client.api.LdapNetworkConnection

Copyright © 2018 www.massapicom. 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.