Package javax.naming.directory

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


            { "administrativeRole" } );
        Attribute administrativeRole = ap.get( "administrativeRole" );
        if ( administrativeRole == null || !administrativeRole.contains( "accessControlSpecificArea" ) )
        {
            Attributes changes = new BasicAttributes( "administrativeRole", "accessControlSpecificArea", true );
            adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
        }

        // now add the A/C subentry below ou=system
        Attributes subentry = new BasicAttributes( "cn", cn, true );
        Attribute objectClass = new BasicAttribute( "objectClass" );


        Attributes attributes = LdifUtils.createAttributes(
            "objectClass: organizationalPerson",
            "objectClass: inetOrgPerson" );

        DirContext person = ( DirContext ) ctx.lookup( RDN );
        person.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, attributes );

        // Read again from directory
        person = ( DirContext ) ctx.lookup( RDN );
        attributes = person.getAttributes( "" );
        Attribute newOcls = attributes.get( "objectClass" );

        Attributes attributes = new BasicAttributes( true );
        Attribute desc = new BasicAttribute( "description", newDescription );
        attributes.put( desc );

        DirContext person = ( DirContext ) ctx.lookup( RDN );
        person.modifyAttributes( "", DirContext.REPLACE_ATTRIBUTE, attributes );

        // Read again from directory
        person = ( DirContext ) ctx.lookup( RDN );
        attributes = person.getAttributes( "" );
        Attribute newDesc = attributes.get( "description" );

        DirContext person = ( DirContext ) ctx.lookup( RDN );
       
        try
        {
            person.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, attributes );
            fail();
        }
        catch ( Exception e )
        {
            // We are expecting the session to be close here.

        ctx = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE );
        person = ( DirContext ) ctx.lookup( RDN );
       
        try
        {
            person.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, attributes );
        }
        catch ( Exception e )
        {
            // We should not go there
            fail();

     */
    public static void addUserToGroup( String userUid, String groupCn ) throws Exception
    {
        DirContext adminCtx = getContextAsAdmin();
        Attributes changes = new BasicAttributes( "uniqueMember", "uid=" + userUid + ",ou=users,ou=system", true );
        adminCtx.modifyAttributes( "cn=" + groupCn + ",ou=groups", DirContext.ADD_ATTRIBUTE, changes );
    }


    /**
     * Removes a user from a group.

     */
    public static void removeUserFromGroup( String userUid, String groupCn ) throws Exception
    {
        DirContext adminCtx = getContextAsAdmin();
        Attributes changes = new BasicAttributes( "uniqueMember", "uid=" + userUid + ",ou=users,ou=system", true );
        adminCtx.modifyAttributes( "cn=" + groupCn + ",ou=groups", DirContext.REMOVE_ATTRIBUTE, changes );
    }


    /**
     * Gets the context at ou=system as a specific user.

            { "administrativeRole" } );
        Attribute administrativeRole = ap.get( "administrativeRole" );
        if ( administrativeRole == null || !administrativeRole.contains( SubentryInterceptor.AC_AREA ) )
        {
            Attributes changes = new BasicAttributes( "administrativeRole", SubentryInterceptor.AC_AREA, true );
            adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
        }

        // now add the A/C subentry below ou=system
        Attributes subentry = new BasicAttributes( "cn", cn, true );
        Attribute objectClass = new BasicAttribute( "objectClass" );

    {
        DirContext adminCtx = getContextAsAdmin();

        // modify the entry relative to ou=system to include the aciItem
        Attributes changes = new BasicAttributes( "entryACI", aciItem, true );
        adminCtx.modifyAttributes( rdn, DirContext.ADD_ATTRIBUTE, changes );
    }


    /**
     * Adds and subentryACI attribute to ou=system

    {
        DirContext adminCtx = getContextAsAdmin();

        // modify the entry relative to ou=system to include the aciItem
        Attributes changes = new BasicAttributes( "subentryACI", aciItem, true );
        adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
    }


    /**
     * Replaces values of an prescriptiveACI attribute of a subentry subordinate

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.