1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.astrogrid.community.common.security.manager ;
29
30 import org.apache.commons.logging.Log ;
31 import org.apache.commons.logging.LogFactory ;
32
33 import org.astrogrid.community.common.policy.data.AccountData ;
34 import org.astrogrid.community.common.policy.manager.AccountManager ;
35
36 import org.astrogrid.community.common.service.CommunityServiceTest ;
37
38 /***
39 * A JUnit test case for our Securitymanager interface.
40 * This is designed to be extended by each set of tests, mock, client and server.
41 *
42 */
43 public class SecurityManagerTest
44 extends CommunityServiceTest
45 {
46 /***
47 * Our debug logger.
48 *
49 */
50 private static Log log = LogFactory.getLog(SecurityManagerTest.class);
51
52 /***
53 * Our test Account ident.
54 *
55 */
56 public static String TEST_ACCOUNT = "test-account" ;
57
58 /***
59 * Our test password.
60 *
61 */
62 public static String TEST_PASSWORD = "test-password" ;
63
64 /***
65 * Public constructor.
66 *
67 */
68 public SecurityManagerTest()
69 {
70 }
71
72 /***
73 * Our target AccountManager.
74 *
75 */
76 private AccountManager accountManager ;
77
78 /***
79 * Get our target AccountManager.
80 *
81 */
82 public AccountManager getAccountManager()
83 {
84 return this.accountManager ;
85 }
86
87 /***
88 * Set our target AccountManager.
89 *
90 */
91 public void setAccountManager(AccountManager manager)
92 {
93 log.debug("") ;
94 log.debug("----\"----") ;
95 log.debug("SecurityServiceTest.setAccountManager()") ;
96 log.debug(" Manager : " + manager.getClass()) ;
97 this.accountManager = manager ;
98 }
99
100 /***
101 * Our target SecurityManager.
102 *
103 */
104 private SecurityManager securityManager ;
105
106 /***
107 * Get our target SecurityManager.
108 *
109 */
110 public SecurityManager getSecurityManager()
111 {
112 return this.securityManager ;
113 }
114
115 /***
116 * Set our target SecurityManager.
117 *
118 */
119 public void setSecurityManager(SecurityManager manager)
120 {
121 log.debug("") ;
122 log.debug("----\"----") ;
123 log.debug("SecurityManagerTest.setSecurityManager()") ;
124 log.debug(" Manager : " + manager.getClass()) ;
125
126
127 this.securityManager = manager ;
128
129
130 this.setCommunityService(securityManager) ;
131 }
132
133 /***
134 * Check we can set an account password.
135 *
136 */
137 public void testSetPassword()
138 throws Exception
139 {
140 log.debug("") ;
141 log.debug("----\"----") ;
142 log.debug("SecurityManagerTest.testSetPassword()") ;
143
144
145 AccountData account = accountManager.addAccount(
146 createLocal(TEST_ACCOUNT).toString()
147 ) ;
148 assertNotNull(
149 "addAccount returned null",
150 account
151 ) ;
152
153
154 assertTrue(
155 "setPassword returned false",
156 securityManager.setPassword(
157 account.getIdent(),
158 TEST_PASSWORD
159 )
160 ) ;
161 }
162
163 /***
164 * Check we can change an account password.
165 *
166 */
167 public void testChangePassword()
168 throws Exception
169 {
170 log.debug("") ;
171 log.debug("----\"----") ;
172 log.debug("SecurityManagerTest.testChangePassword()") ;
173
174
175 AccountData account = accountManager.addAccount(
176 createLocal(TEST_ACCOUNT).toString()
177 ) ;
178 assertNotNull(
179 "addAccount returned null",
180 account
181 ) ;
182
183
184 assertTrue(
185 "setPassword returned false",
186 securityManager.setPassword(
187 account.getIdent(),
188 TEST_PASSWORD
189 )
190 ) ;
191
192
193 assertTrue(
194 "setPassword returned false",
195 securityManager.setPassword(
196 account.getIdent(),
197 TEST_PASSWORD
198 )
199 ) ;
200 }
201 }
202