1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.security.xwss.callback;
18
19 import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
20 import junit.framework.TestCase;
21
22 import java.util.Properties;
23
24 public class SimplePasswordValidationCallbackHandlerTest extends TestCase {
25
26 private SimplePasswordValidationCallbackHandler handler;
27
28 protected void setUp() throws Exception {
29 handler = new SimplePasswordValidationCallbackHandler();
30 Properties users = new Properties();
31 users.setProperty("Bert", "Ernie");
32 handler.setUsers(users);
33 }
34
35 public void testPlainTextPasswordValid() throws Exception {
36 PasswordValidationCallback.PlainTextPasswordRequest request =
37 new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Ernie");
38 PasswordValidationCallback callback = new PasswordValidationCallback(request);
39 handler.handleInternal(callback);
40 boolean authenticated = callback.getResult();
41 assertTrue("Not authenticated", authenticated);
42 }
43
44 public void testPlainTextPasswordInvalid() throws Exception {
45 PasswordValidationCallback.PlainTextPasswordRequest request =
46 new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Big bird");
47 PasswordValidationCallback callback = new PasswordValidationCallback(request);
48 handler.handleInternal(callback);
49 boolean authenticated = callback.getResult();
50 assertFalse("Authenticated", authenticated);
51 }
52
53 public void testPlainTextPasswordNoSuchUser() throws Exception {
54 PasswordValidationCallback.PlainTextPasswordRequest request =
55 new PasswordValidationCallback.PlainTextPasswordRequest("Big bird", "Bert");
56 PasswordValidationCallback callback = new PasswordValidationCallback(request);
57 handler.handleInternal(callback);
58 boolean authenticated = callback.getResult();
59 assertFalse("Authenticated", authenticated);
60 }
61
62 public void testDigestPasswordValid() throws Exception {
63 String username = "Bert";
64 String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
65 String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk=";
66 String creationTime = "2006-06-01T23:48:42Z";
67 PasswordValidationCallback.DigestPasswordRequest request =
68 new PasswordValidationCallback.DigestPasswordRequest(username, passwordDigest, nonce, creationTime);
69 PasswordValidationCallback callback = new PasswordValidationCallback(request);
70 handler.handleInternal(callback);
71 boolean authenticated = callback.getResult();
72 assertTrue("Authenticated", authenticated);
73
74 }
75
76 public void testDigestPasswordInvalid() throws Exception {
77 String username = "Bert";
78 String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
79 String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk";
80 String creationTime = "2006-06-01T23:48:42Z";
81 PasswordValidationCallback.DigestPasswordRequest request =
82 new PasswordValidationCallback.DigestPasswordRequest(username, passwordDigest, nonce, creationTime);
83 PasswordValidationCallback callback = new PasswordValidationCallback(request);
84 handler.handleInternal(callback);
85 boolean authenticated = callback.getResult();
86 assertFalse("Authenticated", authenticated);
87
88 }
89 }