Examples of ServerLdapContext


Examples of org.apache.directory.server.core.jndi.ServerLdapContext

    @Test
    public void testSMD5() throws Exception
    {
        apply( service, getUserAddLdif() );
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );

        // Check that we can get the attributes
        Attributes attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // now modify the password for akarasulu : 'secret', encrypted using SMD5
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );

        // close and try with old password (should fail)
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }

        // try again now with new password (should be successful)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // try again now with new password, to check that the
        // cache is updated (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
    }
View Full Code Here

Examples of org.apache.directory.server.core.jndi.ServerLdapContext

    @Test
    public void testCRYPT() throws Exception
    {
        apply( service, getUserAddLdif() );
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );

        // Check that we can get the attributes
        Attributes attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // now modify the password for akarasulu : 'secret', encrypted using CRYPT
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{crypt}qFkH8Z1woBlXw" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );

        // close and try with old password (should fail)
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }

        // try again now with new password (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // try again now with new password, to check that the
        // cache is updated (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
    }
View Full Code Here

Examples of org.apache.directory.server.core.jndi.ServerLdapContext

    {
        apply( service, getUserAddLdif() );

        // bind as akarasulu
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
        ctx.close();

        // bind as admin
        userDn = "uid=admin,ou=system";
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );

        // now modify the password for akarasulu (while we're admin)
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "newpwd" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }
    }
View Full Code Here

Examples of org.apache.directory.server.core.jndi.ServerLdapContext

        {
            dn = "";
        }
       
        CoreSession session = service.getSession( principal );
        LdapContext ctx = new ServerLdapContext( service, session, new DN( dn ) );
        return ctx;
    }
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

            LdapName userName = new LdapName( "uid="+uid+",ou=users,ou=system" );
            adminContext.createSubcontext( entryRdn, testEntry );

            // compare the telephone numbers
            DirContext userContext = getContextAs( userName, password );
            ServerLdapContext ctx = ( ServerLdapContext ) userContext.lookup( "" );
            ctx.compare( new LdapName( entryRdn + ",ou=system" ), "telephoneNumber", number );

            // don't return compare result which can be false but true since op was permitted
            return true;
        }
        catch ( LdapNoPermissionException e )
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

    protected void process( NextInterceptor nextInterceptor, Lookup call ) throws NamingException
    {
        nextInterceptor.process( call );

        ServerLdapContext ctx = ( ServerLdapContext ) call.getContextStack().peek();
        Attributes attributes = ( Attributes ) call.getReturnValue();
        Attributes retval = ( Attributes ) attributes.clone();
        doFilter( ctx, retval );
        call.setReturnValue( retval );
    }
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

    protected void process( NextInterceptor nextInterceptor, LookupWithAttrIds call ) throws NamingException
    {
        nextInterceptor.process( call );

        ServerLdapContext ctx = ( ServerLdapContext ) call.getContextStack().peek();
        Attributes attributes = ( Attributes ) call.getReturnValue();
        if ( attributes == null )
        {
            return;
        }
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

    public static final SearchControls DEFUALT_SEARCH_CONTROLS = new SearchControls();

    public NamingEnumeration list( NextInterceptor next, Name base ) throws NamingException
    {
        Invocation invocation = InvocationStack.getInstance().peek();
        ServerLdapContext ctx = ( ServerLdapContext ) invocation.getCaller();
        LdapPrincipal user = ctx.getPrincipal();
        NamingEnumeration e = next.list( base );
        if ( user.getName().equalsIgnoreCase( DirectoryPartitionNexus.ADMIN_PRINCIPAL ) || ! enabled )
        {
            return e;
        }
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

    public NamingEnumeration search( NextInterceptor next, Name base, Map env, ExprNode filter,
                                     SearchControls searchCtls ) throws NamingException
    {
        Invocation invocation = InvocationStack.getInstance().peek();
        ServerLdapContext ctx = ( ServerLdapContext ) invocation.getCaller();
        LdapPrincipal user = ctx.getPrincipal();
        NamingEnumeration e = next.search( base, env, filter, searchCtls );
        if ( user.getName().equalsIgnoreCase( DirectoryPartitionNexus.ADMIN_PRINCIPAL ) || ! enabled )
        {
            return e;
        }
View Full Code Here

Examples of org.apache.ldap.server.jndi.ServerLdapContext

        * First call hasPermission() for entry level "Browse" and "ReturnDN" perm
        * tests.  If we hasPermission() returns false we immediately short the
        * process and return false.
        */
        Attributes entry = invocation.getProxy().lookup( normName, DirectoryPartitionNexusProxy.LOOKUP_BYPASS );
        ServerLdapContext ctx = ( ServerLdapContext ) invocation.getCaller();
        Name userDn = ctx.getPrincipal().getJndiName();
        Set userGroups = groupCache.getGroups( userDn.toString() );
        Collection tuples = new HashSet();
        addPerscriptiveAciTuples( invocation.getProxy(), tuples, normName, entry );
        addEntryAciTuples( tuples, entry );
        addSubentryAciTuples( invocation.getProxy(), tuples, normName, entry );

        if ( ! engine.hasPermission( invocation.getProxy(), userGroups, userDn,
                ctx.getPrincipal().getAuthenticationLevel(),
                normName, null, null, SEARCH_ENTRY_PERMS, tuples, entry ) )
        {
            return false;
        }

        /*
         * For each attribute type we check if access is allowed to the type.  If not
         * the attribute is yanked out of the entry to be returned.  If permission is
         * allowed we move on to check if the values are allowed.  Values that are
         * not allowed are removed from the attribute.  If the attribute has no more
         * values remaining then the entire attribute is removed.
         */
        NamingEnumeration idList = result.getAttributes().getIDs();
        while ( idList.hasMore() )
        {
            // if attribute type scope access is not allowed then remove the attribute and continue
            String id = ( String ) idList.next();
            Attribute attr = result.getAttributes().get( id );
            if ( ! engine.hasPermission( invocation.getProxy(), userGroups, userDn,
                    ctx.getPrincipal().getAuthenticationLevel(),
                    normName, attr.getID(), null, SEARCH_ATTRVAL_PERMS, tuples, entry ) )
            {
                result.getAttributes().remove( attr.getID() );

                if ( attr.size() == 0 )
                {
                    result.getAttributes().remove( attr.getID() );
                }
                continue;
            }

            // attribute type scope is ok now let's determine value level scope
            for ( int ii = 0; ii < attr.size(); ii++ )
            {
                if ( ! engine.hasPermission( invocation.getProxy(), userGroups, userDn,
                        ctx.getPrincipal().getAuthenticationLevel(), normName,
                        attr.getID(), attr.get( ii ), SEARCH_ATTRVAL_PERMS, tuples, entry ) )
                {
                    attr.remove( ii );

                    if ( ii > 0 )
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.