01: /*
02: * $Id: CertificateValidationCallback.java,v 1.3 2006/09/29 12:04:51 kumarjayanti Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
25: */
26:
27: package com.sun.xml.wss.impl.callback;
28:
29: import javax.security.auth.callback.Callback;
30:
31: import java.security.cert.X509Certificate;
32:
33: /**
34: * This Callback is intended for X.509 certificate validation
35: * A validator that implements the CertificateValidator interface
36: * should be set on the callback by the callback handler.
37: *
38: * @author XWS-Security Team.
39: */
40: public class CertificateValidationCallback extends XWSSCallback
41: implements Callback {
42:
43: private boolean result = false;
44:
45: private CertificateValidator validator;
46:
47: private X509Certificate certificate;
48:
49: public CertificateValidationCallback(X509Certificate certificate) {
50: this .certificate = certificate;
51: }
52:
53: public boolean getResult() {
54: try {
55: if (validator != null)
56: result = validator.validate(certificate);
57: } catch (Exception e) {
58: return false;
59: }
60: return result;
61: }
62:
63: /**
64: * This method must be invoked while handling this CallBack.
65: */
66: public void setValidator(CertificateValidator validator) {
67: this .validator = validator;
68: }
69:
70: public static interface CertificateValidator {
71:
72: /**
73: * Certificate validator.
74: * @param certificate <code>java.security.cert.X509Certificate</code>
75: * @return true if the certificate is valid else false
76: */
77: public boolean validate(X509Certificate certificate)
78: throws CertificateValidationException;
79: }
80:
81: public static class CertificateValidationException extends
82: Exception {
83:
84: public CertificateValidationException(String message) {
85: super (message);
86: }
87:
88: public CertificateValidationException(String message,
89: Throwable cause) {
90: super (message, cause);
91: }
92:
93: public CertificateValidationException(Throwable cause) {
94: super(cause);
95: }
96: }
97: }
|