X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FOsUserDirectory.java;h=5d7e97ddeea487975ebd64609f63167a0720656d;hb=3c1cdc594d954520b14646102b366290bdad58c7;hp=1f428ecbd9841702011224d4a7dc5ff5eaa51ea2;hpb=e2ffdf6872592aa22d0de2b0ec69ee4eca698c45;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/osgi/useradmin/OsUserDirectory.java b/org.argeo.util/src/org/argeo/osgi/useradmin/OsUserDirectory.java index 1f428ecbd..5d7e97dde 100644 --- a/org.argeo.util/src/org/argeo/osgi/useradmin/OsUserDirectory.java +++ b/org.argeo.util/src/org/argeo/osgi/useradmin/OsUserDirectory.java @@ -1,54 +1,56 @@ package org.argeo.osgi.useradmin; -import java.net.URI; import java.util.ArrayList; -import java.util.Dictionary; import java.util.List; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.directory.Attributes; -import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; import org.argeo.util.directory.HierarchyUnit; +import org.argeo.util.directory.ldap.AbstractLdapDirectory; +import org.argeo.util.directory.ldap.AbstractLdapDirectoryDao; import org.argeo.util.directory.ldap.LdapEntry; import org.argeo.util.directory.ldap.LdapEntryWorkingCopy; import org.argeo.util.naming.LdapAttrs; -import org.osgi.framework.Filter; -import org.osgi.service.useradmin.User; /** Pseudo user directory to be used when logging in as OS user. */ -public class OsUserDirectory extends AbstractUserDirectory { +public class OsUserDirectory extends AbstractLdapDirectoryDao { private final String osUsername = System.getProperty("user.name"); private final LdapName osUserDn; - private final DirectoryUser osUser; + private final LdapEntry osUser; - public OsUserDirectory(URI uriArg, Dictionary props) { - super(uriArg, props, false); + public OsUserDirectory(AbstractLdapDirectory directory) { + super(directory); try { - osUserDn = new LdapName( - LdapAttrs.uid.name() + "=" + osUsername + "," + getUserBaseRdn() + "," + getBaseDn()); - Attributes attributes = new BasicAttributes(); - attributes.put(LdapAttrs.uid.name(), osUsername); - osUser = newUser(osUserDn, attributes); + osUserDn = new LdapName(LdapAttrs.uid.name() + "=" + osUsername + "," + directory.getUserBaseRdn() + "," + + directory.getBaseDn()); +// Attributes attributes = new BasicAttributes(); +// attributes.put(LdapAttrs.uid.name(), osUsername); + osUser = newUser(osUserDn); } catch (NamingException e) { throw new IllegalStateException("Cannot create system user", e); } } @Override - protected List getDirectGroups(LdapName dn) { + public List getDirectGroups(LdapName dn) { return new ArrayList<>(); } @Override - protected Boolean daoHasEntry(LdapName dn) { + public boolean entryExists(LdapName dn) { return osUserDn.equals(dn); } @Override - protected DirectoryUser daoGetEntry(LdapName key) throws NameNotFoundException { + public boolean checkConnection() { + return true; + } + + @Override + public LdapEntry doGetEntry(LdapName key) throws NameNotFoundException { if (osUserDn.equals(key)) return osUser; else @@ -56,18 +58,13 @@ public class OsUserDirectory extends AbstractUserDirectory { } @Override - protected List doGetEntries(LdapName searchBase, Filter f, boolean deep) { + public List doGetEntries(LdapName searchBase, String f, boolean deep) { List res = new ArrayList<>(); - if (f == null || f.match(osUser.getProperties())) - res.add(osUser); +// if (f == null || f.match(osUser.getProperties())) + res.add(osUser); return res; } - @Override - protected AbstractUserDirectory scope(User user) { - throw new UnsupportedOperationException(); - } - @Override public HierarchyUnit doGetHierarchyUnit(LdapName dn) { return null; @@ -90,4 +87,25 @@ public class OsUserDirectory extends AbstractUserDirectory { } + @Override + public void init() { + // TODO Auto-generated method stub + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + + @Override + public Attributes doGetAttributes(LdapName name) { + try { + return doGetEntry(name).getAttributes(); + } catch (NameNotFoundException e) { + throw new IllegalStateException(name + " doe not exist in " + getDirectory().getBaseDn(), e); + } + } + }