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=fe1ca7643f1a4ecf1596beeb870e9efdc21f7a2d;hpb=9f729eeb8255a9d800ad2506735dda8cc215a135;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 fe1ca7643..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,49 +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.naming.LdapAttrs; -import org.osgi.framework.Filter; -import org.osgi.service.useradmin.User; +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; -public class OsUserDirectory extends AbstractUserDirectory { +/** Pseudo user directory to be used when logging in as OS user. */ +public class OsUserDirectory extends AbstractLdapDirectoryDao { private final String osUsername = System.getProperty("user.name"); private final LdapName osUserDn; - private final LdifUser 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 + "," + getUserBase() + "," + getBaseDn()); - Attributes attributes = new BasicAttributes(); - attributes.put(LdapAttrs.uid.name(), osUsername); - osUser = new LdifUser(this, 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 UserDirectoryException("Cannot create system user", 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 daoHasRole(LdapName dn) { + public boolean entryExists(LdapName dn) { return osUserDn.equals(dn); } @Override - protected DirectoryUser daoGetRole(LdapName key) throws NameNotFoundException { + public boolean checkConnection() { + return true; + } + + @Override + public LdapEntry doGetEntry(LdapName key) throws NameNotFoundException { if (osUserDn.equals(key)) return osUser; else @@ -51,16 +58,54 @@ public class OsUserDirectory extends AbstractUserDirectory { } @Override - protected List doGetRoles(Filter f) { - List res = new ArrayList<>(); - if (f == null || f.match(osUser.getProperties())) - res.add(osUser); + public List doGetEntries(LdapName searchBase, String f, boolean deep) { + List res = new ArrayList<>(); +// if (f == null || f.match(osUser.getProperties())) + res.add(osUser); return res; } @Override - protected AbstractUserDirectory scope(User user) { - throw new UnsupportedOperationException(); + public HierarchyUnit doGetHierarchyUnit(LdapName dn) { + return null; + } + + @Override + public Iterable doGetDirectHierarchyUnits(LdapName searchBase, boolean functionalOnly) { + return new ArrayList<>(); + } + + public void prepare(LdapEntryWorkingCopy wc) { + + } + + public void commit(LdapEntryWorkingCopy wc) { + + } + + public void rollback(LdapEntryWorkingCopy wc) { + + } + + @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); + } } }