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 java.io.IOException;
20 import java.security.cert.X509Certificate;
21 import javax.security.auth.callback.Callback;
22 import javax.security.auth.callback.UnsupportedCallbackException;
23
24 import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
25 import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
26
27 import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class MockValidationCallbackHandler extends AbstractCallbackHandler {
42
43 private boolean isValid = true;
44
45 public MockValidationCallbackHandler() {
46 }
47
48 public MockValidationCallbackHandler(boolean valid) {
49 isValid = valid;
50 }
51
52 @Override
53 protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
54 if (callback instanceof CertificateValidationCallback) {
55 CertificateValidationCallback validationCallback = (CertificateValidationCallback) callback;
56 validationCallback.setValidator(new MockCertificateValidator());
57 }
58 else if (callback instanceof PasswordValidationCallback) {
59 PasswordValidationCallback validationCallback = (PasswordValidationCallback) callback;
60 validationCallback.setValidator(new MockPasswordValidator());
61 }
62 else {
63 throw new UnsupportedCallbackException(callback);
64 }
65 }
66
67 public void setValid(boolean valid) {
68 isValid = valid;
69 }
70
71 private class MockCertificateValidator implements CertificateValidationCallback.CertificateValidator {
72
73 public boolean validate(X509Certificate certificate)
74 throws CertificateValidationCallback.CertificateValidationException {
75 return isValid;
76 }
77 }
78
79 private class MockPasswordValidator implements PasswordValidationCallback.PasswordValidator {
80
81 public boolean validate(PasswordValidationCallback.Request request)
82 throws PasswordValidationCallback.PasswordValidationException {
83 return isValid;
84 }
85 }
86 }