X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.security.core%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifUser.java;h=85d18c082b1d5ad93bd8e78d1740a9f29bd60759;hb=d8b62960ec3c9d991840348c63dc0c8ce980233e;hp=1de18c5b42be9a9468e64e7c2784751e094b7377;hpb=e96c7f26228b70f604e41b7a56ce6c5836da9e12;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java index 1de18c5b4..85d18c082 100644 --- a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java @@ -1,21 +1,35 @@ package org.argeo.osgi.useradmin; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Dictionary; -import java.util.Hashtable; +import java.util.List; import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; import org.osgi.service.useradmin.User; -import org.osgi.service.useradmin.UserAdmin; class LdifUser implements User { + // optimisation + //List directMemberOf = new ArrayList(); + private final LdapName dn; - private final Attributes attributes; + private Attributes attributes; + + private final AttributeDictionary properties; + private final AttributeDictionary credentials; + + private List credentialAttributes = Arrays + .asList(new String[] { "userpassword" }); LdifUser(LdapName dn, Attributes attributes) { this.dn = dn; this.attributes = attributes; + properties = new AttributeDictionary(attributes, credentialAttributes, + false); + credentials = new AttributeDictionary(attributes, credentialAttributes, + true); } @Override @@ -30,21 +44,25 @@ class LdifUser implements User { @Override public Dictionary getProperties() { - if (attributes == null) - throw new ArgeoUserAdminException( - "Must be loaded from user admin service"); - return new AttributeDictionary(attributes); + return properties; } @Override public Dictionary getCredentials() { - // TODO Auto-generated method stub - return null; + return credentials; } @Override public boolean hasCredential(String key, Object value) { - // TODO Auto-generated method stub + Object storedValue = getCredentials().get(key); + if (storedValue == null || value == null) + return false; + if (!(value instanceof String || value instanceof byte[])) + return false; + if (storedValue instanceof String && value instanceof String) + return storedValue.equals(value); + if (storedValue instanceof byte[] && value instanceof byte[]) + return Arrays.equals((byte[]) storedValue, (byte[]) value); return false; } @@ -56,4 +74,24 @@ class LdifUser implements User { return attributes; } + @Override + public int hashCode() { + return dn.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj instanceof LdifUser) { + LdifUser that = (LdifUser) obj; + return this.dn.equals(that.dn); + } + return false; + } + + @Override + public String toString() { + return dn.toString(); + } }