1 package org
.argeo
.cms
.acr
.directory
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
7 import org
.argeo
.api
.acr
.ArgeoNamespace
;
8 import org
.argeo
.api
.acr
.Content
;
9 import org
.argeo
.api
.acr
.ContentNotFoundException
;
10 import org
.argeo
.api
.acr
.spi
.ContentProvider
;
11 import org
.argeo
.api
.acr
.spi
.ProvidedContent
;
12 import org
.argeo
.api
.acr
.spi
.ProvidedSession
;
13 import org
.argeo
.api
.cms
.directory
.CmsUserManager
;
14 import org
.argeo
.api
.cms
.directory
.HierarchyUnit
;
15 import org
.argeo
.api
.cms
.directory
.UserDirectory
;
16 import org
.argeo
.cms
.acr
.AbstractSimpleContentProvider
;
17 import org
.argeo
.cms
.acr
.ContentUtils
;
18 import org
.osgi
.service
.useradmin
.User
;
20 /** A {@link ContentProvider} based on a {@link CmsUserManager} service. */
21 public class DirectoryContentProvider
extends AbstractSimpleContentProvider
<CmsUserManager
> {
23 public DirectoryContentProvider(CmsUserManager service
, String mountPath
) {
24 super(ArgeoNamespace
.LDAP_NAMESPACE_URI
, ArgeoNamespace
.LDAP_DEFAULT_PREFIX
, service
, mountPath
);
28 protected Iterator
<Content
> firstLevel(ProvidedSession session
) {
29 List
<Content
> res
= new ArrayList
<>();
30 for (UserDirectory userDirectory
: getService().getUserDirectories()) {
31 DirectoryContent content
= new DirectoryContent(session
, DirectoryContentProvider
.this, userDirectory
);
34 return res
.iterator();
38 public ProvidedContent
get(ProvidedSession session
, List
<String
> segments
) {
39 String userDirectoryName
= segments
.get(0);
40 UserDirectory userDirectory
= null;
41 userDirectories
: for (UserDirectory ud
: getService().getUserDirectories()) {
42 if (userDirectoryName
.equals(ud
.getName())) {
44 break userDirectories
;
47 if (userDirectory
== null)
48 throw new ContentNotFoundException(session
, getMountPath() + "/" + ContentUtils
.toPath(segments
),
49 "Cannot find user directory " + userDirectoryName
);
50 if (segments
.size() == 1) {
51 return new DirectoryContent(session
, this, userDirectory
);
53 List
<String
> relSegments
= new ArrayList
<>(segments
);
54 relSegments
.remove(0);
55 String pathWithinUserDirectory
= ContentUtils
.toPath(relSegments
);
58 // dn = LdapNameUtils.toLdapName(userDirectoryDn);
59 // for (int i = 1; i < segments.size(); i++) {
60 // dn.add(segments.get(i));
62 // } catch (InvalidNameException e) {
63 // throw new IllegalStateException("Cannot interpret " + segments + " as DN", e);
65 User user
= (User
) userDirectory
.getRoleByPath(pathWithinUserDirectory
);
67 HierarchyUnit parent
= userDirectory
.getHierarchyUnit(user
);
68 return new RoleContent(session
, this, new HierarchyUnitContent(session
, this, parent
), user
);
70 HierarchyUnit hierarchyUnit
= userDirectory
.getHierarchyUnit(pathWithinUserDirectory
);
71 if (hierarchyUnit
== null)
72 throw new ContentNotFoundException(session
,
73 getMountPath() + "/" + ContentUtils
.toPath(segments
) + "/" + pathWithinUserDirectory
,
74 "Cannot find " + pathWithinUserDirectory
+ " within " + userDirectoryName
);
75 return new HierarchyUnitContent(session
, this, hierarchyUnit
);
80 public boolean exists(ProvidedSession session
, String relativePath
) {
82 return exists(session
, relativePath
);
85 // public void setUserManager(CmsUserManager userManager) {
86 // this.userManager = userManager;
89 CmsUserManager
getUserManager() {
93 ServiceContent
getRootContent(ProvidedSession session
) {
94 return new ServiceContent(session
);