]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/test/java/org/argeo/security/PasswordSandbox.java
Add JCR MVC
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / test / java / org / argeo / security / PasswordSandbox.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.security;
18
19 import org.apache.commons.codec.DecoderException;
20 import org.apache.commons.codec.binary.Base64;
21 import org.apache.commons.codec.binary.Hex;
22 import org.springframework.security.providers.ldap.authenticator.LdapShaPasswordEncoder;
23
24 public class PasswordSandbox {
25 public static void main(String[] args) {
26 try {
27 // Tested password
28 String pwdPlain = "demo";
29
30 // Check Java generated values
31 LdapShaPasswordEncoder lspe = new LdapShaPasswordEncoder();
32 String pwdLdapShaBase64 = lspe.encodePassword(pwdPlain, null);
33 System.out.println("pwdLdapShaBase64:\t\t" + pwdLdapShaBase64);
34
35 String pwdShaBase64 = pwdLdapShaBase64.substring("{SHA}".length());
36 System.out.println("pwdShaBase64:\t\t\t" + pwdShaBase64);
37
38 byte[] pwdShaArray = Base64.decodeBase64(pwdShaBase64.getBytes());
39 String pwdShaHex = new String(Hex.encodeHex(pwdShaArray));
40 System.out.println("pwdShaHex:\t\t\t" + pwdShaHex);
41
42 // Check that we can use JavaScript generated values in Hex
43 String jsShaHex = "89e495e7941cf9e40e6980d14a16bf023ccd4c91";
44 System.out.println("jsShaHex:\t\t\t" + pwdShaHex);
45 System.out.println("pwdShaHex==jsShaHex:\t\t"
46 + (pwdShaHex.equals(jsShaHex)));
47
48 byte[] jsShaArray = Hex.decodeHex(jsShaHex.toCharArray());
49 String jsShaBase64 = new String(Base64.encodeBase64(jsShaArray));
50 System.out.println("jsShaBase64:\t\t\t" + jsShaBase64);
51 System.out.println("pwdShaBase64==jsShaBase64:\t"
52 + (pwdShaBase64.equals(jsShaBase64)));
53 } catch (DecoderException e) {
54 e.printStackTrace();
55 }
56
57 }
58
59 }