X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.security.core%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifUser.java;h=9f378f1510163396fb8ccb2cbcc965e929bb360a;hb=b4c3087d7a41cde4a9e92736882b450e51742bf7;hp=379ac23ab2ca6349203655b318b4166efc8e620d;hpb=3439a3b6aba14618b06c72cf59b220e216135c96;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 379ac23ab..9f378f151 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,6 +1,7 @@ package org.argeo.osgi.useradmin; import java.util.ArrayList; +import java.util.Arrays; import java.util.Dictionary; import java.util.List; @@ -16,9 +17,19 @@ class LdifUser implements User { private final LdapName dn; 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 @@ -33,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; } @@ -79,5 +94,4 @@ class LdifUser implements User { public String toString() { return dn.toString(); } - }