1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22 import java.util.Set;
23
24 import org.apache.jetspeed.security.PasswordCredential;
25 import org.apache.jetspeed.security.om.InternalUserPrincipal;
26 import org.apache.jetspeed.security.om.impl.InternalCredentialImpl;
27 import org.apache.jetspeed.security.spi.impl.DefaultPasswordCredentialImpl;
28 import org.apache.jetspeed.security.util.test.AbstractSecurityTestcase;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32
33 /***
34 * <p>
35 * TestDefaultInternalPasswordCredentialIntercepto
36 * </p>
37 *
38 * @author <a href="mailto:ate@apache.org">Ate Douma</a>
39 * @version $Id: TestCredentialPasswordEncoder.java 516448 2007-03-09 16:25:47Z ate $
40 */
41 public class TestCredentialPasswordEncoder extends AbstractSecurityTestcase
42 {
43 protected void setUp() throws Exception
44 {
45 super.setUp();
46
47 destroyUser();
48 initUser();
49 }
50
51 public void tearDown() throws Exception
52 {
53 destroyUser();
54 super.tearDown();
55 }
56
57 public static Test suite()
58 {
59 return new TestSuite(TestCredentialPasswordEncoder.class);
60 }
61
62 public void testEncodedPassword() throws Exception
63 {
64 Set privateCredentials = ums.getUser("testcred").getSubject().getPrivateCredentials();
65 assertNotNull(privateCredentials);
66 assertEquals(1, privateCredentials.size());
67 PasswordCredential[] pwdCreds = (PasswordCredential[]) privateCredentials.toArray(new PasswordCredential[0]);
68 assertEquals("testcred", pwdCreds[0].getUserName());
69 assertNotSame("Password should be not same (encoded)", "password", new String(pwdCreds[0].getPassword()));
70 }
71
72 protected void initUser() throws Exception
73 {
74
75 ums.addUser("testcred", null);
76
77 InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal("testcred");
78 ArrayList credentials = new ArrayList();
79 InternalCredentialImpl credential =
80 new InternalCredentialImpl(internalUser.getPrincipalId(),
81 "password", 0, DefaultPasswordCredentialImpl.class.getName());
82 credentials.add(credential);
83 internalUser.setCredentials(credentials);
84 securityAccess.setInternalUserPrincipal(internalUser,false);
85 }
86
87 protected void destroyUser() throws Exception
88 {
89 ums.removeUser("testcred");
90 }
91
92 protected String[] getConfigurations()
93 {
94 String[] confs = super.getConfigurations();
95 List confList = new ArrayList(Arrays.asList(confs));
96 confList.add("JETSPEED-INF/spring/TestCredentialPasswordEncoder.xml");
97 return (String[])confList.toArray(new String[1]);
98 }
99 }