X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FAuthenticatingUser.java;h=01db8be9895b9f3548728f2b6d5c580f684424e4;hb=f9efbe5228615951dd8482a4582aa24e00c10ce5;hp=2689d34fcae39c4d6b55738955aeab59d6d5697b;hpb=a5459b7f0a4ce0463b950efd5c776368fe169256;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/AuthenticatingUser.java b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/AuthenticatingUser.java index 2689d34fc..01db8be98 100644 --- a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/AuthenticatingUser.java +++ b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/AuthenticatingUser.java @@ -1,9 +1,5 @@ package org.argeo.osgi.useradmin; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.util.Arrays; import java.util.Dictionary; import java.util.Hashtable; @@ -25,6 +21,8 @@ public class AuthenticatingUser implements User { private final Dictionary credentials; public AuthenticatingUser(LdapName name) { + if (name == null) + throw new NullPointerException("Provided name cannot be null."); this.name = name.toString(); this.credentials = new Hashtable<>(); } @@ -35,10 +33,12 @@ public class AuthenticatingUser implements User { } public AuthenticatingUser(String name, char[] password) { + if (name == null) + throw new NullPointerException("Provided name cannot be null."); this.name = name; credentials = new Hashtable<>(); credentials.put(SHARED_STATE_NAME, name); - byte[] pwd = charsToBytes(password); + byte[] pwd = DigestUtils.charsToBytes(password); credentials.put(SHARED_STATE_PWD, pwd); } @@ -52,13 +52,13 @@ public class AuthenticatingUser implements User { return User.USER; } - @SuppressWarnings("rawtypes") + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Dictionary getProperties() { throw new UnsupportedOperationException(); } - @SuppressWarnings("rawtypes") + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Dictionary getCredentials() { return credentials; @@ -69,22 +69,14 @@ public class AuthenticatingUser implements User { throw new UnsupportedOperationException(); } - static byte[] charsToBytes(char[] chars) { - CharBuffer charBuffer = CharBuffer.wrap(chars); - ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); - byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); - Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data - Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data - return bytes; + @Override + public int hashCode() { + return name.hashCode(); } - static char[] bytesToChars(byte[] bytes) { - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - CharBuffer charBuffer = Charset.forName("UTF-8").decode(byteBuffer); - char[] chars = Arrays.copyOfRange(charBuffer.array(), charBuffer.position(), charBuffer.limit()); - Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data - Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data - return chars; + @Override + public String toString() { + return "Authenticating user " + name; } }