Package javax.naming.directory

Examples of javax.naming.directory.DirContext.modifyAttributes()


     */
    public static void changePresciptiveACI( String cn, String aciItem ) throws Exception
    {
        DirContext adminCtx = getContextAsAdmin();
        Attributes changes = new BasicAttributes( "prescriptiveACI", aciItem, true );
        adminCtx.modifyAttributes( "cn=" + cn, DirContext.REPLACE_ATTRIBUTE, changes );
    }


    public static void addPrescriptiveACI( String cn, String aciItem ) throws Exception
    {


    public static void addPrescriptiveACI( String cn, String aciItem ) throws Exception
    {
        DirContext adminCtx = getContextAsAdmin();
        Attributes changes = new BasicAttributes( "prescriptiveACI", aciItem, true );
        adminCtx.modifyAttributes( "cn=" + cn, DirContext.ADD_ATTRIBUTE, changes );
    }
}

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

            // modify the entry as the user
            DirContext userContext = getContextAs( userName, password );
            userContext.modifyAttributes( entryRdn, mods );

            return true;
        }
        catch ( LdapNoPermissionException e )
        {

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

            // modify the entry as the user
            DirContext userContext = getContextAs( userName, password );
            userContext.modifyAttributes( entryRdn, modOp, mods );

            return true;
        }
        catch ( LdapNoPermissionException e )
        {

        try
        {
            // modify the entry as the user
            Name userEntry = new DN( "uid=" + uid + ",ou=users,ou=system" );
            DirContext userContext = getContextAs( userEntry, password, userEntry.toString() );
            userContext.modifyAttributes( "", modOp, mods );
            return true;
        }
        catch ( LdapNoPermissionException e )
        {
            return false;

        try
        {
            // modify the entry as the user
            Name userEntry = new DN( "uid=" + uid + ",ou=users,ou=system" );
            DirContext userContext = getContextAs( userEntry, password, userEntry.toString() );
            userContext.modifyAttributes( "", mods );
            return true;
        }
        catch ( LdapNoPermissionException e )
        {
            return false;

        // Add the first value for description
        String description1 = "an American singer-songwriter";
        Attribute firstDescr = new BasicAttribute( "description", description1 );
        ModificationItem modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, firstDescr);
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification });

        // Add a second value to description
        String description2 = "Grammy award winning";
        Attribute otherDescr = new BasicAttribute( "description", description2 );

        // Add a second value to description
        String description2 = "Grammy award winning";
        Attribute otherDescr = new BasicAttribute( "description", description2 );

        modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, otherDescr );
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification } );
     
        // Add a third value to description
        String description3 = "MTV Music Award winning";
        Attribute thirdDescr = new BasicAttribute( "description", description3 );

        // Add a third value to description
        String description3 = "MTV Music Award winning";
        Attribute thirdDescr = new BasicAttribute( "description", description3 );

        modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, thirdDescr );
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification });

        // Search Entry
        SearchControls sctls = new SearchControls();
        sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
        String filter = '(' + rdn + ')';

        DirContext ctx = new InitialDirContext( env );

        // remove "cn=aaa", which is not part of the RDN
        Attribute attr = new BasicAttribute( "cn", "aaa" );
        ModificationItem modification = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
        ctx.modifyAttributes( "cn=test", new ModificationItem[]
            { modification } );

        Attributes attrs = ctx.getAttributes( "cn=test", new String[]
            { "cn" } );
        Attribute cn = attrs.get( "cn" );

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.