X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.security.core%2Fext%2Ftest%2Forg%2Fargeo%2Fsecurity%2FPasswordSandbox.java;fp=org.argeo.security.core%2Fext%2Ftest%2Forg%2Fargeo%2Fsecurity%2FPasswordSandbox.java;h=d8a0846079462efd450f7757597d0545d471967e;hb=10ed6557c631d5feee8541badd0c9f16a9e791c6;hp=0000000000000000000000000000000000000000;hpb=864072113f7a44fd2a291a4cb50659d6e67f8c29;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.security.core/ext/test/org/argeo/security/PasswordSandbox.java b/org.argeo.security.core/ext/test/org/argeo/security/PasswordSandbox.java new file mode 100644 index 000000000..d8a084607 --- /dev/null +++ b/org.argeo.security.core/ext/test/org/argeo/security/PasswordSandbox.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security; + +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.Hex; +import org.springframework.security.providers.ldap.authenticator.LdapShaPasswordEncoder; + +public class PasswordSandbox { + public static void main(String[] args) { + try { + // Tested password + String pwdPlain = "demo"; + + // Check Java generated values + LdapShaPasswordEncoder lspe = new LdapShaPasswordEncoder(); + String pwdLdapShaBase64 = lspe.encodePassword(pwdPlain, null); + System.out.println("pwdLdapShaBase64:\t\t" + pwdLdapShaBase64); + + String pwdShaBase64 = pwdLdapShaBase64.substring("{SHA}".length()); + System.out.println("pwdShaBase64:\t\t\t" + pwdShaBase64); + + byte[] pwdShaArray = Base64.decodeBase64(pwdShaBase64.getBytes()); + String pwdShaHex = new String(Hex.encodeHex(pwdShaArray)); + System.out.println("pwdShaHex:\t\t\t" + pwdShaHex); + + // Check that we can use JavaScript generated values in Hex + String jsShaHex = "89e495e7941cf9e40e6980d14a16bf023ccd4c91"; + System.out.println("jsShaHex:\t\t\t" + pwdShaHex); + System.out.println("pwdShaHex==jsShaHex:\t\t" + + (pwdShaHex.equals(jsShaHex))); + + byte[] jsShaArray = Hex.decodeHex(jsShaHex.toCharArray()); + String jsShaBase64 = new String(Base64.encodeBase64(jsShaArray)); + System.out.println("jsShaBase64:\t\t\t" + jsShaBase64); + System.out.println("pwdShaBase64==jsShaBase64:\t" + + (pwdShaBase64.equals(jsShaBase64))); + } catch (DecoderException e) { + e.printStackTrace(); + } + + } + +} \ No newline at end of file