Package org.apache.directory.shared.ldap.entry.client

Examples of org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute


     * @return An instance of ClientAttribute
     */
    public EntryAttribute toClientAttribute()
    {
        // Create the new EntryAttribute
        EntryAttribute clientAttribute = new DefaultClientAttribute( upId );
       
        // Copy the values
        for ( Value<?> value:this )
        {
            Value<?> clientValue = null;
           
            if ( value instanceof ServerStringValue )
            {
                clientValue = new ClientStringValue( value.getString() );
            }
            else
            {
                clientValue = new ClientBinaryValue( value.getBytes() );
            }
           
            clientAttribute.add( clientValue );
        }
       
        return clientAttribute;
    }
View Full Code Here


     *
     */
    @Test
    public void testCopyClientModification()
    {
        ClientAttribute attribute = new DefaultClientAttribute( atC.getName() );
        attribute.add( "test1", "test2" );
        Modification clientModification = new ClientModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
       
        Modification copy = new ServerModification( registries, clientModification );
       
        assertTrue( copy instanceof ServerModification );
        assertFalse( copy instanceof ClientModification );
        assertFalse( copy.equalsclientModification ) );
        assertTrue( copy.getAttribute() instanceof ServerAttribute );
        assertEquals( atC, ((ServerAttribute)copy.getAttribute()).getAttributeType() );
        assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
        assertTrue( copy.getAttribute().contains( "test1", "test2" ) );
       
        clientModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE );
        assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
       
        ClientAttribute attribute2 = new DefaultClientAttribute( "cn", "t" );
        clientModification.setAttribute( attribute2 );
        assertNotSame( attribute2, copy.getAttribute() );
    }
View Full Code Here

        LdapDN dn = new LdapDN( dnstr );
        LdifEntry ldif = new LdifEntry();
        ldif.setDn( dnstr );
        ldif.setChangeType( ChangeType.Add );

        EntryAttribute attr = new DefaultClientAttribute( "objectClass",
            "top", "person", "organizationalPerson", "inetOrgPerson" );
        ldif.addAttribute( attr );

        attr = new DefaultClientAttribute( "ou", "Engineering", "People" );
        ldif.addAttribute( attr );

        String uid = ( String ) dn.getRdn().getValue();
        ldif.putAttribute( "uid", uid );
View Full Code Here

        attr1.clear();
        attr1.put( "a", (String)null, "b" );
        assertTrue( attr1.remove( (String )null, "a" ) );
        assertEquals( 1, attr1.size() );
       
        EntryAttribute attr2 = new DefaultClientAttribute( "test" );
       
        attr2.put( BYTES1, BYTES2, BYTES3 );
       
        assertFalse( attr2.remove( (String)null ) );
        assertTrue( attr2.remove( "ab", "c" ) );
        assertFalse( attr2.remove( "d" ) );
    }
View Full Code Here

     * Test the copy constructor of a ClientAttribute
     */
    @Test
    public void testCopyConstructorClientAttribute() throws InvalidAttributeValueException
    {
        EntryAttribute attribute = new DefaultClientAttribute( "commonName" );
        attribute.put( "test" );
       
        ServerAttribute copy = new DefaultServerAttribute( atCN, attribute );

        assertEquals( atCN, copy.getAttributeType() );
        assertEquals( "test", copy.getString() );
        assertTrue( copy.isHR() );
       
        attribute.add( "test2" );
        assertFalse( copy.contains( "test2" ) );
    }
View Full Code Here

        // create the non-admin user
        createUser( "billyd", "billyd" );

        // create the password modification
        Modification[] mods = toItems( ModificationOperation.REPLACE_ATTRIBUTE, new DefaultClientAttribute(
            "userPassword", "williams" ) );

        // try a modify operation which should fail without any ACI
        assertFalse( checkCanSelfModify( "billyd", "billyd", mods ) );
View Full Code Here

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Addition
        // ----------------------------------------------------------------------------------

        // create the add modifications
        EntryAttribute attr = new DefaultClientAttribute( "registeredAddress", "100 Park Ave." );
        Modification[] mods = toItems( ModificationOperation.ADD_ATTRIBUTE, attr );

        // create the non-admin user
        createUser( "billyd", "billyd" );

        createGroup( "TestGroup" );

        // try a modify operation which should fail without any ACI
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
        // entries and all attribute types and values
        createAccessControlSubentry(
            "administratorModifyAdd",
            "{ "
                + "identificationTag \"addAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { userGroup { \"cn=TestGroup,ou=groups,ou=system\" } }, "
                + "userPermissions { "
                + "{ protectedItems {entry}, grantsAndDenials { grantModify, grantBrowse } }, "
                + "{ protectedItems {attributeType {registeredAddress}, allAttributeValues {registeredAddress}}, grantsAndDenials { grantAdd } } "
                + "} } }" );

        // see if we can now add that test entry which we could not before
        // add op should still fail since billd is not in the admin group
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        // now add billyd to the TestGroup group and try again
        addUserToGroup( "billyd", "TestGroup" );

        // try a modify operation which should succeed with ACI and group membership change
        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );
        deleteAccessControlSubentry( "administratorModifyAdd" );

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Removal
        // ----------------------------------------------------------------------------------

        // now let's test to see if we can perform a modify with a delete op
        mods = toItems( ModificationOperation.REMOVE_ATTRIBUTE, new DefaultClientAttribute( "telephoneNumber",
            "867-5309" ) );

        // make sure we cannot remove the telephone number from the test entry
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
        // entries and all attribute types and values
        createAccessControlSubentry(
            "administratorModifyRemove",
            "{ "
                + "identificationTag \"addAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { userGroup { \"cn=TestGroup,ou=groups,ou=system\" } }, "
                + "userPermissions { "
                + "{ protectedItems {entry}, grantsAndDenials { grantModify, grantBrowse } }, "
                + "{ protectedItems {attributeType {telephoneNumber}, allAttributeValues {telephoneNumber}}, grantsAndDenials { grantRemove } } "
                + "} } }" );

        // try a modify operation which should succeed with ACI and group membership change
        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );
        deleteAccessControlSubentry( "administratorModifyRemove" );

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Replace (requires both grantRemove and grantAdd on attrs)
        // ----------------------------------------------------------------------------------

        // now let's test to see if we can perform a modify with a delete op
        mods = toItems( ModificationOperation.REPLACE_ATTRIBUTE, new DefaultClientAttribute( "telephoneNumber",
            "867-5309" ) );

        // make sure we cannot remove the telephone number from the test entry
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
        // entries and all attribute types and values
        createAccessControlSubentry(
            "administratorModifyReplace",
            "{ "
                + "identificationTag \"addAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { userGroup { \"cn=TestGroup,ou=groups,ou=system\" } }, "
                + "userPermissions { "
                + "{ protectedItems {entry}, grantsAndDenials { grantModify, grantBrowse } }, "
                + "{ protectedItems {attributeType {registeredAddress}, allAttributeValues {telephoneNumber}}, grantsAndDenials { grantAdd, grantRemove } } "
                + "} } }" );

        // try a modify operation which should succeed with ACI and group membership change
        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );
        deleteAccessControlSubentry( "administratorModifyReplace" );

        /* =================================================================================
         *              DO IT ALL OVER AGAIN BUT USE THE OTHER MODIFY METHOD
         * ================================================================================= */

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Addition
        // ----------------------------------------------------------------------------------
        // create the add modifications
        EntryAttribute changes = new DefaultClientAttribute( "registeredAddress", "100 Park Ave." );

        // try a modify operation which should fail without any ACI
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", ModificationOperation.ADD_ATTRIBUTE, changes ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
        // entries and all attribute types and values
        createAccessControlSubentry(
            "administratorModifyAdd",
            "{ "
                + "identificationTag \"addAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { userGroup { \"cn=TestGroup,ou=groups,ou=system\" } }, "
                + "userPermissions { "
                + "{ protectedItems {entry}, grantsAndDenials { grantModify, grantBrowse } }, "
                + "{ protectedItems {attributeType {registeredAddress}, allAttributeValues {registeredAddress}}, grantsAndDenials { grantAdd } } "
                + "} } }" );

        // try a modify operation which should succeed with ACI and group membership change
        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", ModificationOperation.ADD_ATTRIBUTE, changes ) );
        deleteAccessControlSubentry( "administratorModifyAdd" );

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Removal
        // ----------------------------------------------------------------------------------

        // now let's test to see if we can perform a modify with a delete op
        changes = new DefaultClientAttribute( "telephoneNumber", "867-5309" );

        // make sure we cannot remove the telephone number from the test entry
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", ModificationOperation.REMOVE_ATTRIBUTE, changes ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
        // entries and all attribute types and values
        createAccessControlSubentry(
            "administratorModifyRemove",
            "{ "
                + "identificationTag \"addAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { userGroup { \"cn=TestGroup,ou=groups,ou=system\" } }, "
                + "userPermissions { "
                + "{ protectedItems {entry}, grantsAndDenials { grantModify, grantBrowse } }, "
                + "{ protectedItems {attributeType {telephoneNumber}, allAttributeValues {telephoneNumber}}, grantsAndDenials { grantRemove } } "
                + "} } }" );

        // try a modify operation which should succeed with ACI and group membership change
        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", ModificationOperation.REMOVE_ATTRIBUTE, changes ) );
        deleteAccessControlSubentry( "administratorModifyRemove" );

        // ----------------------------------------------------------------------------------
        // Modify with Attribute Replace (requires both grantRemove and grantAdd on attrs)
        // ----------------------------------------------------------------------------------

        // now let's test to see if we can perform a modify with a delete op
        changes = new DefaultClientAttribute( "telephoneNumber", "867-5309" );

        // make sure we cannot remove the telephone number from the test entry
        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", ModificationOperation.REPLACE_ATTRIBUTE, changes ) );

        // Gives grantModify, and grantRead perm to all users in the TestGroup group for
View Full Code Here

    @Test
    public void testPresciptiveACIModification() throws Exception
    {

        Modification[] mods = toItems( ModificationOperation.ADD_ATTRIBUTE, new DefaultClientAttribute(
            "registeredAddress", "100 Park Ave." ) );

        createUser( "billyd", "billyd" );

        createAccessControlSubentry(
            "modifyACI",
            "{ "
                + "identificationTag \"modifyAci\", "
                + "precedence 14, "
                + "authenticationLevel none, "
                + "itemOrUserFirst userFirst: { "
                + "userClasses { allUsers }, "
                + "userPermissions { "
                + "{ protectedItems {entry, allUserAttributeTypesAndValues}, grantsAndDenials { grantModify, grantBrowse, grantAdd, grantRemove } } } } }" );

        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        mods = toItems( ModificationOperation.REPLACE_ATTRIBUTE, new DefaultClientAttribute( "registeredAddress",
            "200 Park Ave." ) );

        changePresciptiveACI( "modifyACI", "{ " + "identificationTag \"modifyAci\", " + "precedence 14, "
            + "authenticationLevel none, " + "itemOrUserFirst userFirst: { " + "userClasses { allUsers }, "
            + "userPermissions { "
View Full Code Here

            + " grantsAndDenials { grantModify, grantBrowse }" + " }" + " ," + " {" + " protectedItems" + " {"
            + " attributeType { description }," + " allAttributeValues { description }," + " maxValueCount" + " {"
            + " { type description, maxCount 1 }" + " }" + " }" + " ," + " grantsAndDenials" + " {" + " grantRemove,"
            + " grantAdd" + " }" + " }" + " }" + " }" + " }" );

        Modification[] mods = toItems( ModificationOperation.ADD_ATTRIBUTE, new DefaultClientAttribute( "description",
            "description 1" ) );

        assertTrue( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );

        EntryAttribute attr = new DefaultClientAttribute( "description" );
        attr.add( "description 1" );
        attr.add( "description 2" );

        mods = toItems( ModificationOperation.ADD_ATTRIBUTE, attr );

        assertFalse( checkCanModifyAs( "billyd", "billyd", "ou=testou", mods ) );
View Full Code Here

        // Read the entry we just created using the akarasuluSession
        Entry readEntry = service.getAdminSession().lookup( akarasulu.getDn(), new String[]{ "userPassword"} );
       
        assertTrue( Arrays.equals( akarasulu.get( "userPassword" ).getBytes(), readEntry.get( "userPassword" ).getBytes() ) );

        EntryAttribute attribute = new DefaultClientAttribute( "userPassword", "replaced" );

        List<Modification> mods = new ArrayList<Modification>();
       
        Modification mod = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
        mods.add( mod );
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute

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.