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