1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.protocol.shared.catalog;
22
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.directory.api.ldap.model.cursor.Cursor;
28 import org.apache.directory.api.ldap.model.entry.Attribute;
29 import org.apache.directory.api.ldap.model.entry.Entry;
30 import org.apache.directory.api.ldap.model.filter.FilterParser;
31 import org.apache.directory.api.ldap.model.message.AliasDerefMode;
32 import org.apache.directory.api.ldap.model.message.SearchScope;
33 import org.apache.directory.api.ldap.model.name.Dn;
34 import org.apache.directory.server.constants.ApacheSchemaConstants;
35 import org.apache.directory.server.core.api.CoreSession;
36 import org.apache.directory.server.protocol.shared.store.DirectoryServiceOperation;
37
38
39
40
41
42
43
44 public class GetCatalog implements DirectoryServiceOperation
45 {
46
47
48
49 public Object execute( CoreSession session, Dn base ) throws Exception
50 {
51 String filter = "(objectClass=" + ApacheSchemaConstants.APACHE_CATALOG_ENTRY_OC + ")";
52
53 Cursor<Entry> list = session.search(
54 Dn.ROOT_DSE,
55 SearchScope.SUBTREE,
56 FilterParser.parse( session.getDirectoryService().getSchemaManager(), filter ),
57 AliasDerefMode.DEREF_ALWAYS );
58
59 Map<String, String> catalog = new HashMap<>();
60
61 list.beforeFirst();
62
63 while ( list.next() )
64 {
65 Entry result = list.get();
66
67 String name = null;
68 Attribute attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_NAME_AT );
69
70 if ( attribute != null )
71 {
72 name = attribute.getString();
73 }
74
75 String basedn = null;
76 attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_BASE_DN_AT );
77
78 if ( attribute != null )
79 {
80 basedn = attribute.getString();
81 }
82
83 catalog.put( name, basedn );
84 }
85
86 return catalog;
87 }
88 }