Package org.apache.directory.api.ldap.model.entry

Examples of org.apache.directory.api.ldap.model.entry.DefaultAttribute


        if ( pwdAt == null )
        {
            return null;
        }

        Attribute newPwd = new DefaultAttribute( pwdAt.getAttributeType() );

        // Special case : deal with a potential empty value. We may have more than one
        for ( Value<?> userPassword : pwdAt )
        {
            if ( userPassword.getValue() == null )
            {
                continue;
            }

            // check if the given password is already hashed
            LdapSecurityConstants existingAlgo = PasswordUtil.findAlgorithm( ( ( BinaryValue ) userPassword )
                .getValue() );

            // if there exists NO algorithm, then hash the password
            if ( existingAlgo == null )
            {
                byte[] hashedPassword = PasswordUtil.createStoragePassword(
                    ( ( BinaryValue ) userPassword ).getValue(), algorithm );

                newPwd.add( hashedPassword );
            }
            else
            {
                newPwd.add( ( ( BinaryValue ) userPassword ).getValue() );
            }
        }

        return newPwd;
    }
View Full Code Here


            return null;
        }

        try
        {
            Attribute serverAttribute = new DefaultAttribute( attributeType );

            for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements(); )
            {
                Object value = values.nextElement();
                int nbAdded = 0;

                if ( value == null )
                {
                    continue;
                }

                if ( serverAttribute.isHumanReadable() )
                {
                    if ( value instanceof String )
                    {
                        nbAdded = serverAttribute.add( ( String ) value );
                    }
                    else if ( value instanceof byte[] )
                    {
                        nbAdded = serverAttribute.add( Strings.utf8ToString( ( byte[] ) value ) );
                    }
                    else
                    {
                        throw new LdapInvalidAttributeTypeException();
                    }
                }
                else
                {
                    if ( value instanceof String )
                    {
                        nbAdded = serverAttribute.add( Strings.getBytesUtf8( ( String ) value ) );
                    }
                    else if ( value instanceof byte[] )
                    {
                        nbAdded = serverAttribute.add( ( byte[] ) value );
                    }
                    else
                    {
                        throw new LdapInvalidAttributeTypeException();
                    }
View Full Code Here

                    }
                }
                break;

            case ADD_ATTRIBUTE:
                Attribute combined = new DefaultAttribute( id, attributeType );
                Attribute toBeAdded = mod.getAttribute();
                Attribute existing = entry.get( id );

                if ( existing != null )
                {
                    for ( Value<?> value : existing )
                    {
                        combined.add( value );
                    }
                }

                for ( Value<?> value : toBeAdded )
                {
                    combined.add( value );
                }

                targetEntry.put( combined );
                break;
View Full Code Here

    private static Modification toServerModification( Modification modification, AttributeType attributeType )
        throws LdapException
    {
        Modification serverModification = new DefaultModification(
            modification.getOperation(),
            new DefaultAttribute( attributeType, modification.getAttribute() ) );

        return serverModification;

    }
View Full Code Here

    @Test
    public void testModifyAddOUAttrib() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );

        Attribute attrib = new DefaultAttribute( SchemaConstants.OU_AT, OU_AT );
        attrib.add( "Engineering" );

        Modification add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attrib );

        store.modify( dn, add );
    }
View Full Code Here

    @Test
    public void testModifyAdd() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );

        Attribute attrib = new DefaultAttribute( "sn", SN_AT );

        String attribVal = "Walker";
        attrib.add( attribVal );

        Modification add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
View Full Code Here

    @Test
    public void testModifyReplace() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );

        Attribute attrib = new DefaultAttribute( SchemaConstants.SN_AT, SN_AT );

        String attribVal = "Johnny";
        attrib.add( attribVal );

        Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
View Full Code Here

    @Test
    public void testModifyRemove() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );

        Attribute attrib = new DefaultAttribute( SchemaConstants.SN_AT, SN_AT );

        Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
View Full Code Here

            "entryUUID", UUID.randomUUID().toString() );

        AddOperationContext addContext = new AddOperationContext( null, entry );
        store.add( addContext );

        Attribute attrib = new DefaultAttribute( SchemaConstants.OU_AT, OU_AT );

        String attribVal = "Marketing";
        attrib.add( attribVal );

        Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
View Full Code Here

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

        Attribute attribute = new DefaultAttribute( "userPassword", "replaced" );

        Modification mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
     
        Dn userDn = new Dn( getService().getSchemaManager(), "uid=akarasulu,ou=users,ou=system" );
        LdapPrincipal principal = new LdapPrincipal( getService().getSchemaManager(), userDn, AuthenticationLevel.SIMPLE );
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.entry.DefaultAttribute

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.