1 package org
.argeo
.osgi
.useradmin
;
3 import java
.util
.ArrayList
;
6 import javax
.naming
.NameNotFoundException
;
7 import javax
.naming
.NamingException
;
8 import javax
.naming
.directory
.Attributes
;
9 import javax
.naming
.ldap
.LdapName
;
11 import org
.argeo
.util
.directory
.HierarchyUnit
;
12 import org
.argeo
.util
.directory
.ldap
.AbstractLdapDirectory
;
13 import org
.argeo
.util
.directory
.ldap
.AbstractLdapDirectoryDao
;
14 import org
.argeo
.util
.directory
.ldap
.LdapEntry
;
15 import org
.argeo
.util
.directory
.ldap
.LdapEntryWorkingCopy
;
16 import org
.argeo
.util
.naming
.LdapAttrs
;
18 /** Pseudo user directory to be used when logging in as OS user. */
19 public class OsUserDirectory
extends AbstractLdapDirectoryDao
{
20 private final String osUsername
= System
.getProperty("user.name");
21 private final LdapName osUserDn
;
22 private final LdapEntry osUser
;
24 public OsUserDirectory(AbstractLdapDirectory directory
) {
27 osUserDn
= new LdapName(LdapAttrs
.uid
.name() + "=" + osUsername
+ "," + directory
.getUserBaseRdn() + ","
28 + directory
.getBaseDn());
29 // Attributes attributes = new BasicAttributes();
30 // attributes.put(LdapAttrs.uid.name(), osUsername);
31 osUser
= newUser(osUserDn
);
32 } catch (NamingException e
) {
33 throw new IllegalStateException("Cannot create system user", e
);
38 public List
<LdapName
> getDirectGroups(LdapName dn
) {
39 return new ArrayList
<>();
43 public Boolean
entryExists(LdapName dn
) {
44 return osUserDn
.equals(dn
);
48 public LdapEntry
doGetEntry(LdapName key
) throws NameNotFoundException
{
49 if (osUserDn
.equals(key
))
52 throw new NameNotFoundException("Not an OS role");
56 public List
<LdapEntry
> doGetEntries(LdapName searchBase
, String f
, boolean deep
) {
57 List
<LdapEntry
> res
= new ArrayList
<>();
58 // if (f == null || f.match(osUser.getProperties()))
64 public HierarchyUnit
doGetHierarchyUnit(LdapName dn
) {
69 public Iterable
<HierarchyUnit
> doGetDirectHierarchyUnits(LdapName searchBase
, boolean functionalOnly
) {
70 return new ArrayList
<>();
73 public void prepare(LdapEntryWorkingCopy wc
) {
77 public void commit(LdapEntryWorkingCopy wc
) {
81 public void rollback(LdapEntryWorkingCopy wc
) {
87 // TODO Auto-generated method stub
92 public void destroy() {
93 // TODO Auto-generated method stub
98 public Attributes
doGetAttributes(LdapName name
) {
100 return doGetEntry(name
).getAttributes();
101 } catch (NameNotFoundException e
) {
102 throw new IllegalStateException(name
+ " doe not exist in " + getDirectory().getBaseDn(), e
);