DirContext adminCtx = getContextAsAdmin();   Attributes ap = adminCtx.getAttributes( "", new String[] { "administrativeRole" } ); Attribute administrativeRole = ap.get( "administrativeRole" ); if ( administrativeRole == null || ! administrativeRole.contains( SubentryService.AC_AREA ) ) { Attributes changes = new BasicAttributes( "administrativeRole", SubentryService.AC_AREA, true ); adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); }   Attributes subentry = new BasicAttributes( "cn", cn, true ); Attribute objectClass = new BasicAttribute( "objectClass" ); subentry.put( objectClass ); objectClass.add( "top" ); objectClass.add( "subentry" ); objectClass.add( "accessControlSubentry" ); subentry.put( "subtreeSpecification", "{}" ); subentry.put( "prescriptiveACI", aciItem ); adminCtx.createSubcontext( "cn=" + cn, subentry );
createAccessControlSubentry( cn, "{}", aciItem );
    public void createAccessControlSubentry( String cn, String aciItem ) throws NamingException    {        DirContext adminCtx = getContextAsAdmin();        // modify ou=system to be an AP for an A/C AA if it is not already        Attributes ap = adminCtx.getAttributes( "", new String[] { "administrativeRole" } );        Attribute administrativeRole = ap.get( "administrativeRole" );        if ( administrativeRole == null || ! administrativeRole.contains( SubentryService.AC_AREA ) )        {            Attributes changes = new BasicAttributes( "administrativeRole", SubentryService.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" );        subentry.put( objectClass );        objectClass.add( "top" );        objectClass.add( "subentry" );        objectClass.add( "accessControlSubentry" );        subentry.put( "subtreeSpecification", "{}" );        subentry.put( "prescriptiveACI", aciItem );        adminCtx.createSubcontext( "cn=" + cn, subentry );    }