01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.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
25: TestCase {
26:
27: private SimplePasswordValidationCallbackHandler handler;
28:
29: protected void setUp() throws Exception {
30: handler = new SimplePasswordValidationCallbackHandler();
31: Properties users = new Properties();
32: users.setProperty("Bert", "Ernie");
33: handler.setUsers(users);
34: }
35:
36: public void testPlainTextPasswordValid() throws Exception {
37: PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest(
38: "Bert", "Ernie");
39: PasswordValidationCallback callback = new PasswordValidationCallback(
40: request);
41: handler.handleInternal(callback);
42: boolean authenticated = callback.getResult();
43: assertTrue("Not authenticated", authenticated);
44: }
45:
46: public void testPlainTextPasswordInvalid() throws Exception {
47: PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest(
48: "Bert", "Big bird");
49: PasswordValidationCallback callback = new PasswordValidationCallback(
50: request);
51: handler.handleInternal(callback);
52: boolean authenticated = callback.getResult();
53: assertFalse("Authenticated", authenticated);
54: }
55:
56: public void testPlainTextPasswordNoSuchUser() throws Exception {
57: PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest(
58: "Big bird", "Bert");
59: PasswordValidationCallback callback = new PasswordValidationCallback(
60: request);
61: handler.handleInternal(callback);
62: boolean authenticated = callback.getResult();
63: assertFalse("Authenticated", authenticated);
64: }
65:
66: public void testDigestPasswordValid() throws Exception {
67: String username = "Bert";
68: String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
69: String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk=";
70: String creationTime = "2006-06-01T23:48:42Z";
71: PasswordValidationCallback.DigestPasswordRequest request = new PasswordValidationCallback.DigestPasswordRequest(
72: username, passwordDigest, nonce, creationTime);
73: PasswordValidationCallback callback = new PasswordValidationCallback(
74: request);
75: handler.handleInternal(callback);
76: boolean authenticated = callback.getResult();
77: assertTrue("Authenticated", authenticated);
78:
79: }
80:
81: public void testDigestPasswordInvalid() throws Exception {
82: String username = "Bert";
83: String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
84: String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk";
85: String creationTime = "2006-06-01T23:48:42Z";
86: PasswordValidationCallback.DigestPasswordRequest request = new PasswordValidationCallback.DigestPasswordRequest(
87: username, passwordDigest, nonce, creationTime);
88: PasswordValidationCallback callback = new PasswordValidationCallback(
89: request);
90: handler.handleInternal(callback);
91: boolean authenticated = callback.getResult();
92: assertFalse("Authenticated", authenticated);
93:
94: }
95: }
|