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.jaas;
18:
19: import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
20: import junit.framework.TestCase;
21:
22: public class JaasPlainTextPasswordValidationCallbackHandlerTest extends
23: TestCase {
24:
25: private JaasPlainTextPasswordValidationCallbackHandler callbackHandler;
26:
27: protected void setUp() throws Exception {
28: System.setProperty("java.security.auth.login.config",
29: getClass().getResource("jaas.config").toString());
30: callbackHandler = new JaasPlainTextPasswordValidationCallbackHandler();
31: callbackHandler.setLoginContextName("PlainText");
32: }
33:
34: public void testAuthenticateUserPlainTextValid() throws Exception {
35: PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest(
36: "Bert", "Ernie");
37: PasswordValidationCallback callback = new PasswordValidationCallback(
38: request);
39: callbackHandler.handleInternal(callback);
40: boolean authenticated = callback.getResult();
41: assertTrue("Not authenticated", authenticated);
42: }
43:
44: public void testAuthenticateUserPlainTextInvalid() throws Exception {
45: PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest(
46: "Bert", "Big bird");
47: PasswordValidationCallback callback = new PasswordValidationCallback(
48: request);
49: callbackHandler.handleInternal(callback);
50: boolean authenticated = callback.getResult();
51: assertFalse("Authenticated", authenticated);
52: }
53:
54: }
|