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 java.io.InputStream;
20: import java.security.KeyStore;
21: import java.security.cert.X509Certificate;
22:
23: import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
24: import junit.framework.TestCase;
25:
26: import org.springframework.core.io.ClassPathResource;
27:
28: public class JaasCertificateValidationCallbackHandlerTest extends
29: TestCase {
30:
31: private JaasCertificateValidationCallbackHandler callbackHandler;
32:
33: private CertificateValidationCallback callback;
34:
35: protected void setUp() throws Exception {
36: System.setProperty("java.security.auth.login.config",
37: getClass().getResource("jaas.config").toString());
38: callbackHandler = new JaasCertificateValidationCallbackHandler();
39: callbackHandler.setLoginContextName("Certificate");
40: KeyStore keyStore = KeyStore.getInstance(KeyStore
41: .getDefaultType());
42: InputStream is = null;
43: try {
44: is = new ClassPathResource(
45: "/org/springframework/ws/soap/security/xwss/test-keystore.jks")
46: .getInputStream();
47: keyStore.load(is, "password".toCharArray());
48: } finally {
49: if (is != null) {
50: is.close();
51: }
52: }
53: X509Certificate certificate = (X509Certificate) keyStore
54: .getCertificate("alias");
55: callback = new CertificateValidationCallback(certificate);
56: }
57:
58: public void testValidateCertificateValid() throws Exception {
59: callbackHandler.handleInternal(callback);
60: boolean authenticated = callback.getResult();
61: assertTrue("Not authenticated", authenticated);
62: }
63:
64: }
|