1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.subtree;
18  
19  
20  import org.apache.ldap.server.AbstractAdminTestCase;
21  import org.apache.ldap.common.message.LockableAttributesImpl;
22  import org.apache.ldap.common.message.LockableAttributeImpl;
23  import org.apache.ldap.common.exception.LdapNoSuchAttributeException;
24  
25  import javax.naming.NamingException;
26  import javax.naming.NamingEnumeration;
27  import javax.naming.directory.*;
28  import java.util.Map;
29  import java.util.HashMap;
30  
31  
32  /***
33   * Testcases for the SubentryService.
34   *
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   * @version $Rev$
37   */
38  public class SubentryServiceTest extends AbstractAdminTestCase
39  {
40      public Attributes getTestEntry( String cn )
41      {
42          Attributes subentry = new LockableAttributesImpl();
43          Attribute objectClass = new LockableAttributeImpl( "objectClass" );
44          objectClass.add( "top" );
45          objectClass.add( "person" );
46          subentry.put( objectClass );
47          subentry.put( "cn", cn );
48          subentry.put( "sn", "testentry" );
49          return subentry;
50      }
51  
52  
53      public Attributes getTestSubentry()
54      {
55          Attributes subentry = new LockableAttributesImpl();
56          Attribute objectClass = new LockableAttributeImpl( "objectClass" );
57          objectClass.add( "top" );
58          objectClass.add( "subentry" );
59          subentry.put( objectClass );
60          subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
61          subentry.put( "cn", "testsubentry" );
62          return subentry;
63      }
64  
65  
66      public Attributes getTestSubentryWithExclusion()
67      {
68          Attributes subentry = new LockableAttributesImpl();
69          Attribute objectClass = new LockableAttributeImpl( "objectClass" );
70          objectClass.add( "top" );
71          objectClass.add( "subentry" );
72          subentry.put( objectClass );
73          String spec = "{ base \"ou=configuration\", specificExclusions { chopBefore:\"cn=unmarked\" } }";
74          subentry.put( "subtreeSpecification", spec );
75          subentry.put( "cn", "testsubentry" );
76          return subentry;
77      }
78  
79  
80      public void addAdministrativeRole( String role ) throws NamingException
81      {
82          Attribute attribute = new LockableAttributeImpl( "administrativeRole" );
83          attribute.add( role );
84          ModificationItem item = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
85          super.sysRoot.modifyAttributes( "", new ModificationItem[] { item } );
86      }
87  
88  
89      public Map getAllEntries() throws NamingException
90      {
91          Map resultMap = new HashMap();
92          SearchControls controls = new SearchControls();
93          controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
94          controls.setReturningAttributes( new String[] { "+", "*" } );
95          NamingEnumeration results = super.sysRoot.search( "", "(objectClass=*)", controls );
96          while ( results.hasMore() )
97          {
98              SearchResult result = ( SearchResult ) results.next();
99              resultMap.put( result.getName(), result.getAttributes() );
100         }
101         return resultMap;
102     }
103 
104 
105     public void testEntryAdd() throws NamingException
106     {
107         addAdministrativeRole( "autonomousArea" );
108         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
109         super.sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
110         super.sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
111         Map results = getAllEntries();
112 
113         // --------------------------------------------------------------------
114         // Make sure entries selected by the subentry do have the mark
115         // --------------------------------------------------------------------
116 
117         Attributes marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
118         Attribute autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
119         assertNotNull( "ou=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
120         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
121         assertEquals( 1, autonomousSubentry.size() );
122 
123         // --------------------------------------------------------------------
124         // Make sure entries not selected by subentry do not have the mark
125         // --------------------------------------------------------------------
126 
127         Attributes unmarked = ( Attributes ) results.get( "cn=unmarked,ou=system" );
128         assertNull( "cn=unmarked,ou=system should not be marked",
129                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
130     }
131 
132 
133     public void testSubentryAdd() throws NamingException
134     {
135         try
136         {
137             super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
138             fail( "should never get here: cannot create subentry under regular entries" );
139         }
140         catch ( LdapNoSuchAttributeException e ) {}
141 
142         addAdministrativeRole( "autonomousArea" );
143         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
144         Map results = getAllEntries();
145 
146         // --------------------------------------------------------------------
147         // Make sure entries selected by the subentry do have the mark
148         // --------------------------------------------------------------------
149 
150         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
151         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
152         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
153         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
154         assertEquals( 1, autonomousSubentry.size() );
155 
156         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
157         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
158         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
159         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
160         assertEquals( 1, autonomousSubentry.size() );
161 
162         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
163         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
164         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
165         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
166         assertEquals( 1, autonomousSubentry.size() );
167 
168         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
169         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
170         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
171         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
172         assertEquals( 1, autonomousSubentry.size() );
173 
174         // --------------------------------------------------------------------
175         // Make sure entries not selected by subentry do not have the mark
176         // --------------------------------------------------------------------
177 
178         Attributes system = ( Attributes ) results.get( "ou=system" );
179         assertNull( "ou=system should not be marked",
180                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
181 
182         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
183         assertNull( "ou=users,ou=system should not be marked",
184                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
185 
186         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
187         assertNull( "ou=groups,ou=system should not be marked",
188                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
189 
190         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
191         assertNull( "uid=admin,ou=system should not be marked",
192                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
193 
194         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
195         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
196                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
197 
198     }
199 
200 
201     public void testSubentryModify() throws NamingException
202     {
203         addAdministrativeRole( "autonomousArea" );
204         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
205         Map results = getAllEntries();
206 
207         // --------------------------------------------------------------------
208         // Make sure entries selected by the subentry do have the mark
209         // --------------------------------------------------------------------
210 
211         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
212         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
213         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
214         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
215         assertEquals( 1, autonomousSubentry.size() );
216 
217         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
218         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
219         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
220         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
221         assertEquals( 1, autonomousSubentry.size() );
222 
223         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
224         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
225         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
226         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
227         assertEquals( 1, autonomousSubentry.size() );
228 
229         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
230         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
231         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
232         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
233         assertEquals( 1, autonomousSubentry.size() );
234 
235         // --------------------------------------------------------------------
236         // Make sure entries not selected by subentry do not have the mark
237         // --------------------------------------------------------------------
238 
239         Attributes system = ( Attributes ) results.get( "ou=system" );
240         assertNull( "ou=system should not be marked",
241                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
242 
243         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
244         assertNull( "ou=users,ou=system should not be marked",
245                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
246 
247         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
248         assertNull( "ou=groups,ou=system should not be marked",
249                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
250 
251         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
252         assertNull( "uid=admin,ou=system should not be marked",
253                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
254 
255         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
256         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
257                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
258 
259         // --------------------------------------------------------------------
260         // Now modify the subentry by introducing an exclusion
261         // --------------------------------------------------------------------
262 
263         Attribute subtreeSpecification = new LockableAttributeImpl( "subtreeSpecification" );
264         subtreeSpecification.add( "{ base \"ou=configuration\", specificExclusions { chopBefore:\"ou=services\" } }" );
265         ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, subtreeSpecification );
266         super.sysRoot.modifyAttributes( "cn=testsubentry", new ModificationItem[] { item } );
267         results = getAllEntries();
268 
269         // --------------------------------------------------------------------
270         // Make sure entries selected by the subentry do have the mark
271         // --------------------------------------------------------------------
272 
273         configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
274         autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
275         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
276         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
277         assertEquals( 1, autonomousSubentry.size() );
278 
279         interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
280         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
281         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
282         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
283         assertEquals( 1, autonomousSubentry.size() );
284 
285         partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
286         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
287         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
288         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
289         assertEquals( 1, autonomousSubentry.size() );
290 
291         // --------------------------------------------------------------------
292         // Make sure entries not selected by subentry do not have the mark
293         // --------------------------------------------------------------------
294 
295         system = ( Attributes ) results.get( "ou=system" );
296         assertNull( "ou=system should not be marked",
297                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
298 
299         users = ( Attributes ) results.get( "ou=users,ou=system" );
300         assertNull( "ou=users,ou=system should not be marked",
301                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
302 
303         groups = ( Attributes ) results.get( "ou=groups,ou=system" );
304         assertNull( "ou=groups,ou=system should not be marked",
305                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
306 
307         admin = ( Attributes ) results.get( "uid=admin,ou=system" );
308         assertNull( "uid=admin,ou=system should not be marked",
309                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
310 
311         sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
312         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
313                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
314 
315         services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
316         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
317         if ( autonomousSubentry != null )
318         {
319             assertEquals( "ou=services,ou=configuration,ou=system should not be marked",
320                 0, autonomousSubentry.size() );
321         }
322     }
323 
324 
325     public void testSubentryModify2() throws NamingException
326     {
327         addAdministrativeRole( "autonomousArea" );
328         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
329         Map results = getAllEntries();
330 
331         // --------------------------------------------------------------------
332         // Make sure entries selected by the subentry do have the mark
333         // --------------------------------------------------------------------
334 
335         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
336         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
337         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
338         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
339         assertEquals( 1, autonomousSubentry.size() );
340 
341         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
342         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
343         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
344         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
345         assertEquals( 1, autonomousSubentry.size() );
346 
347         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
348         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
349         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
350         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
351         assertEquals( 1, autonomousSubentry.size() );
352 
353         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
354         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
355         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
356         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
357         assertEquals( 1, autonomousSubentry.size() );
358 
359         // --------------------------------------------------------------------
360         // Make sure entries not selected by subentry do not have the mark
361         // --------------------------------------------------------------------
362 
363         Attributes system = ( Attributes ) results.get( "ou=system" );
364         assertNull( "ou=system should not be marked",
365                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
366 
367         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
368         assertNull( "ou=users,ou=system should not be marked",
369                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
370 
371         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
372         assertNull( "ou=groups,ou=system should not be marked",
373                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
374 
375         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
376         assertNull( "uid=admin,ou=system should not be marked",
377                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
378 
379         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
380         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
381                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
382 
383         // --------------------------------------------------------------------
384         // Now modify the subentry by introducing an exclusion
385         // --------------------------------------------------------------------
386 
387         Attributes changes = new LockableAttributesImpl();
388         changes.put( "subtreeSpecification",
389                 "{ base \"ou=configuration\", specificExclusions { chopBefore:\"ou=services\" } }" );
390         super.sysRoot.modifyAttributes( "cn=testsubentry", DirContext.REPLACE_ATTRIBUTE, changes );
391         results = getAllEntries();
392 
393         // --------------------------------------------------------------------
394         // Make sure entries selected by the subentry do have the mark
395         // --------------------------------------------------------------------
396 
397         configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
398         autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
399         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
400         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
401         assertEquals( 1, autonomousSubentry.size() );
402 
403         interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
404         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
405         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
406         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
407         assertEquals( 1, autonomousSubentry.size() );
408 
409         partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
410         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
411         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
412         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
413         assertEquals( 1, autonomousSubentry.size() );
414 
415         // --------------------------------------------------------------------
416         // Make sure entries not selected by subentry do not have the mark
417         // --------------------------------------------------------------------
418 
419         system = ( Attributes ) results.get( "ou=system" );
420         assertNull( "ou=system should not be marked",
421                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
422 
423         users = ( Attributes ) results.get( "ou=users,ou=system" );
424         assertNull( "ou=users,ou=system should not be marked",
425                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
426 
427         groups = ( Attributes ) results.get( "ou=groups,ou=system" );
428         assertNull( "ou=groups,ou=system should not be marked",
429                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
430 
431         admin = ( Attributes ) results.get( "uid=admin,ou=system" );
432         assertNull( "uid=admin,ou=system should not be marked",
433                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
434 
435         sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
436         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
437                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
438 
439         services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
440         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
441         if ( autonomousSubentry != null )
442         {
443             assertEquals( "ou=services,ou=configuration,ou=system should not be marked",
444                 0, autonomousSubentry.size() );
445         }
446     }
447 
448 
449     public void testSubentryDelete() throws NamingException
450     {
451         addAdministrativeRole( "autonomousArea" );
452         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
453         super.sysRoot.destroySubcontext( "cn=testsubentry" );
454 
455         Map results = getAllEntries();
456 
457         // --------------------------------------------------------------------
458         // Make sure entries not selected by subentry do not have the mark
459         // --------------------------------------------------------------------
460 
461         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
462         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
463         if ( autonomousSubentry != null )
464         {
465             assertEquals( "ou=configuration,ou=system should not be marked", 0, autonomousSubentry.size() );
466         }
467 
468         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
469         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
470         if ( autonomousSubentry != null )
471         {
472             assertEquals( "ou=interceptors,ou=configuration,ou=system should not be marked",
473                     0,autonomousSubentry.size() );
474         }
475 
476         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
477         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
478         if ( autonomousSubentry != null )
479         {
480             assertEquals( "ou=partitions,ou=configuration,ou=system should not be marked",
481                     0, autonomousSubentry.size() );
482         }
483 
484         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
485         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
486         if ( autonomousSubentry != null )
487         {
488             assertEquals( "ou=services,ou=configuration,ou=system should not be marked",
489                     0, autonomousSubentry.size() );
490         }
491 
492         Attributes system = ( Attributes ) results.get( "ou=system" );
493         assertNull( "ou=system should not be marked",
494                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
495 
496         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
497         assertNull( "ou=users,ou=system should not be marked",
498                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
499 
500         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
501         assertNull( "uid=admin,ou=system should not be marked",
502                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
503 
504         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
505         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
506                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
507 
508     }
509 
510 
511     public void testSubentryModifyRdn() throws NamingException
512     {
513         addAdministrativeRole( "autonomousArea" );
514         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
515         super.sysRoot.rename( "cn=testsubentry", "cn=newname" );
516         Map results = getAllEntries();
517 
518         // --------------------------------------------------------------------
519         // Make sure entries selected by the subentry do have the mark
520         // --------------------------------------------------------------------
521 
522         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
523         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
524         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
525         assertEquals( "cn=newname,ou=system", autonomousSubentry.get() );
526         assertEquals( 1, autonomousSubentry.size() );
527 
528         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
529         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
530         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
531         assertEquals( "cn=newname,ou=system", autonomousSubentry.get() );
532         assertEquals( 1, autonomousSubentry.size() );
533 
534         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
535         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
536         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
537         assertEquals( "cn=newname,ou=system", autonomousSubentry.get() );
538         assertEquals( 1, autonomousSubentry.size() );
539 
540         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
541         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
542         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
543         assertEquals( "cn=newname,ou=system", autonomousSubentry.get() );
544         assertEquals( 1, autonomousSubentry.size() );
545 
546         // --------------------------------------------------------------------
547         // Make sure entries not selected by subentry do not have the mark
548         // --------------------------------------------------------------------
549 
550         Attributes system = ( Attributes ) results.get( "ou=system" );
551         assertNull( "ou=system should not be marked",
552                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
553 
554         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
555         assertNull( "ou=users,ou=system should not be marked",
556                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
557 
558         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
559         assertNull( "ou=groups,ou=system should not be marked",
560                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
561 
562         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
563         assertNull( "uid=admin,ou=system should not be marked",
564                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
565 
566         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
567         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
568                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
569 
570     }
571 
572 
573     public void testEntryModifyRdn() throws NamingException
574     {
575         addAdministrativeRole( "autonomousArea" );
576         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
577         super.sysRoot.createSubcontext( "cn=unmarked,ou=configuration", getTestEntry( "unmarked" ) );
578         super.sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
579         Map results = getAllEntries();
580 
581         // --------------------------------------------------------------------
582         // Make sure entries selected by the subentry do have the mark
583         // --------------------------------------------------------------------
584 
585         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
586         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
587         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
588         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
589         assertEquals( 1, autonomousSubentry.size() );
590 
591         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
592         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
593         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
594         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
595         assertEquals( 1, autonomousSubentry.size() );
596 
597         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
598         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
599         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
600         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
601         assertEquals( 1, autonomousSubentry.size() );
602 
603         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
604         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
605         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
606         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
607         assertEquals( 1, autonomousSubentry.size() );
608 
609         Attributes marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
610         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
611         assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
612         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
613         assertEquals( 1, autonomousSubentry.size() );
614 
615         // --------------------------------------------------------------------
616         // Make sure entries not selected by subentry do not have the mark
617         // --------------------------------------------------------------------
618 
619         Attributes system = ( Attributes ) results.get( "ou=system" );
620         assertNull( "ou=system should not be marked",
621                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
622 
623         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
624         assertNull( "ou=users,ou=system should not be marked",
625                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
626 
627         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
628         assertNull( "ou=groups,ou=system should not be marked",
629                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
630 
631         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
632         assertNull( "uid=admin,ou=system should not be marked",
633                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
634 
635         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
636         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
637                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
638 
639         Attributes unmarked = ( Attributes ) results.get( "cn=unmarked,ou=configuration,ou=system" );
640         assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked",
641                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
642 
643         // --------------------------------------------------------------------
644         // Now destry one of the marked/unmarked and rename to deleted entry
645         // --------------------------------------------------------------------
646 
647         super.sysRoot.destroySubcontext( "cn=unmarked,ou=configuration" );
648         super.sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked,ou=configuration" );
649         results = getAllEntries();
650 
651         unmarked = ( Attributes ) results.get( "cn=unmarked,ou=configuration,ou=system" );
652         assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked",
653                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
654         assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
655 
656         // --------------------------------------------------------------------
657         // Now rename unmarked to marked and see that subentry op attr is there
658         // --------------------------------------------------------------------
659 
660         super.sysRoot.rename( "cn=unmarked,ou=configuration", "cn=marked,ou=configuration" );
661         results = getAllEntries();
662         assertNull( results.get( "cn=unmarked,ou=configuration,ou=system" ) );
663         marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
664         assertNotNull( marked );
665         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
666         assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
667         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
668         assertEquals( 1, autonomousSubentry.size() );
669     }
670 
671 
672     public void testEntryMoveWithRdnChange() throws NamingException
673     {
674         addAdministrativeRole( "autonomousArea" );
675         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
676         super.sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
677         super.sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
678         Map results = getAllEntries();
679 
680         // --------------------------------------------------------------------
681         // Make sure entries selected by the subentry do have the mark
682         // --------------------------------------------------------------------
683 
684         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
685         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
686         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
687         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
688         assertEquals( 1, autonomousSubentry.size() );
689 
690         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
691         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
692         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
693         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
694         assertEquals( 1, autonomousSubentry.size() );
695 
696         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
697         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
698         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
699         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
700         assertEquals( 1, autonomousSubentry.size() );
701 
702         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
703         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
704         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
705         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
706         assertEquals( 1, autonomousSubentry.size() );
707 
708         Attributes marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
709         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
710         assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
711         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
712         assertEquals( 1, autonomousSubentry.size() );
713 
714         // --------------------------------------------------------------------
715         // Make sure entries not selected by subentry do not have the mark
716         // --------------------------------------------------------------------
717 
718         Attributes system = ( Attributes ) results.get( "ou=system" );
719         assertNull( "ou=system should not be marked",
720                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
721 
722         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
723         assertNull( "ou=users,ou=system should not be marked",
724                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
725 
726         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
727         assertNull( "ou=groups,ou=system should not be marked",
728                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
729 
730         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
731         assertNull( "uid=admin,ou=system should not be marked",
732                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
733 
734         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
735         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
736                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
737 
738         Attributes unmarked = ( Attributes ) results.get( "cn=unmarked,ou=system" );
739         assertNull( "cn=unmarked,ou=system should not be marked",
740                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
741 
742         // --------------------------------------------------------------------
743         // Now destry one of the marked/unmarked and rename to deleted entry
744         // --------------------------------------------------------------------
745 
746         super.sysRoot.destroySubcontext( "cn=unmarked" );
747         super.sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked" );
748         results = getAllEntries();
749 
750         unmarked = ( Attributes ) results.get( "cn=unmarked,ou=system" );
751         assertNull( "cn=unmarked,ou=system should not be marked",
752                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
753         assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
754 
755         // --------------------------------------------------------------------
756         // Now rename unmarked to marked and see that subentry op attr is there
757         // --------------------------------------------------------------------
758 
759         super.sysRoot.rename( "cn=unmarked", "cn=marked,ou=configuration" );
760         results = getAllEntries();
761         assertNull( results.get( "cn=unmarked,ou=system" ) );
762         marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
763         assertNotNull( marked );
764         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
765         assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
766         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
767         assertEquals( 1, autonomousSubentry.size() );
768     }
769 
770 
771     public void testEntryMove() throws NamingException
772     {
773         addAdministrativeRole( "autonomousArea" );
774         super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
775         super.sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
776         super.sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
777         Map results = getAllEntries();
778 
779         // --------------------------------------------------------------------
780         // Make sure entries selected by the subentry do have the mark
781         // --------------------------------------------------------------------
782 
783         Attributes configuration = ( Attributes ) results.get( "ou=configuration,ou=system" );
784         Attribute autonomousSubentry = configuration.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
785         assertNotNull( "ou=configuration,ou=system should be marked", autonomousSubentry );
786         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
787         assertEquals( 1, autonomousSubentry.size() );
788 
789         Attributes interceptors = ( Attributes ) results.get( "ou=interceptors,ou=configuration,ou=system" );
790         autonomousSubentry = interceptors.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
791         assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", autonomousSubentry );
792         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
793         assertEquals( 1, autonomousSubentry.size() );
794 
795         Attributes partitions = ( Attributes ) results.get( "ou=partitions,ou=configuration,ou=system" );
796         autonomousSubentry = partitions.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
797         assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", autonomousSubentry );
798         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
799         assertEquals( 1, autonomousSubentry.size() );
800 
801         Attributes services = ( Attributes ) results.get( "ou=services,ou=configuration,ou=system" );
802         autonomousSubentry = services.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
803         assertNotNull( "ou=services,ou=configuration,ou=system should be marked", autonomousSubentry );
804         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
805         assertEquals( 1, autonomousSubentry.size() );
806 
807         Attributes marked = ( Attributes ) results.get( "cn=marked,ou=configuration,ou=system" );
808         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
809         assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", autonomousSubentry );
810         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
811         assertEquals( 1, autonomousSubentry.size() );
812 
813         // --------------------------------------------------------------------
814         // Make sure entries not selected by subentry do not have the mark
815         // --------------------------------------------------------------------
816 
817         Attributes system = ( Attributes ) results.get( "ou=system" );
818         assertNull( "ou=system should not be marked",
819                 system.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
820 
821         Attributes users = ( Attributes ) results.get( "ou=users,ou=system" );
822         assertNull( "ou=users,ou=system should not be marked",
823                 users.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
824 
825         Attributes groups = ( Attributes ) results.get( "ou=groups,ou=system" );
826         assertNull( "ou=groups,ou=system should not be marked",
827                 groups.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
828 
829         Attributes admin = ( Attributes ) results.get( "uid=admin,ou=system" );
830         assertNull( "uid=admin,ou=system should not be marked",
831                 admin.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
832 
833         Attributes sysPrefRoot = ( Attributes ) results.get( "prefNodeName=sysPrefRoot,ou=system" );
834         assertNull( "prefNode=sysPrefRoot,ou=system should not be marked",
835                 sysPrefRoot.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
836 
837         Attributes unmarked = ( Attributes ) results.get( "cn=unmarked,ou=system" );
838         assertNull( "cn=unmarked,ou=system should not be marked",
839                 unmarked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY ) );
840 
841         // --------------------------------------------------------------------
842         // Now destry one of the marked/unmarked and rename to deleted entry
843         // --------------------------------------------------------------------
844 
845         super.sysRoot.destroySubcontext( "cn=unmarked" );
846         super.sysRoot.rename( "cn=marked,ou=configuration", "cn=marked,ou=services,ou=configuration" );
847         results = getAllEntries();
848 
849         unmarked = ( Attributes ) results.get( "cn=unmarked,ou=system" );
850         assertNull( "cn=unmarked,ou=system should not be marked", unmarked );
851         assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
852 
853         marked = ( Attributes ) results.get( "cn=marked,ou=services,ou=configuration,ou=system" );
854         assertNotNull( marked );
855         autonomousSubentry = marked.get( SubentryService.AUTONOUMOUS_AREA_SUBENTRY );
856         assertNotNull( "cn=marked,ou=services,ou=configuration should be marked", autonomousSubentry );
857         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
858         assertEquals( 1, autonomousSubentry.size() );
859     }
860 }