001: /*
002: * $Id: SignatureVerificationKeyCallback.java,v 1.3 2006/09/29 12:04:52 kumarjayanti Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.impl.callback;
028:
029: import javax.security.auth.callback.Callback;
030:
031: import java.security.cert.X509Certificate;
032: import java.security.PublicKey;
033:
034: import java.math.BigInteger;
035:
036: /**
037: * CallBack implementation for signature verification key.
038: *
039: * @author XWS-Security Team
040: */
041: public class SignatureVerificationKeyCallback extends XWSSCallback
042: implements Callback {
043:
044: public static interface Request {
045: }
046:
047: private Request request;
048:
049: public SignatureVerificationKeyCallback(Request request) {
050: this .request = request;
051: }
052:
053: public Request getRequest() {
054: return request;
055: }
056:
057: /**
058: * A CallbackHandler handling an instance of this request should make
059: * sure that an X.509 certificate (to be used for signature verification)
060: * must be set on the request.
061: */
062: public static abstract class X509CertificateRequest implements
063: Request {
064:
065: X509Certificate certificate;
066:
067: /**
068: * Set the X509Certificate used for Signature Verification.
069: *
070: * @param certificate <code>java.security.X509Certificate</code> representing
071: * X509Certificate to be used for Signature Verification.
072: *
073: */
074: public void setX509Certificate(X509Certificate certificate) {
075: this .certificate = certificate;
076: }
077:
078: /**
079: * Get the X509Certificate stored in this Request.
080: *
081: * @return <code>java.security.X509Certificate</code>
082: */
083: public X509Certificate getX509Certificate() {
084: return certificate;
085: }
086: }
087:
088: /**
089: * Request for a private key when the X.509 Thumb print
090: * value for a corresponding X.509 Certificate is given.
091: * TODO: extending X509CertificateRequest for now
092: */
093: public static class ThumbprintBasedRequest extends
094: X509CertificateRequest {
095:
096: private byte[] x509Thumbprint;
097:
098: /**
099: * Constructor.
100: * It takes the byte stream of X509ThumbPrint.
101: */
102: public ThumbprintBasedRequest(byte[] x509Thumbprint) {
103: this .x509Thumbprint = x509Thumbprint;
104: }
105:
106: /**
107: * Get the byte stream of X509ThumbPrint set on this request.
108: * @return byte[] X509ThumbPrint value (byte stream).
109: */
110: public byte[] getThumbprintIdentifier() {
111: return x509Thumbprint;
112: }
113: }
114:
115: /**
116: * Request for an X.509 certificate whose X.509 Subject Key Identifier
117: * value is given.
118: */
119: public static class X509SubjectKeyIdentifierBasedRequest extends
120: X509CertificateRequest {
121:
122: private byte[] x509SubjectKeyIdentifier;
123:
124: /**
125: * Constructor.
126: *
127: * @param x509SubjectKeyIdentifier - Byte stream representing the X509SubjectKeyIdentifier
128: * value.
129: */
130: public X509SubjectKeyIdentifierBasedRequest(
131: byte[] x509SubjectKeyIdentifier) {
132: this .x509SubjectKeyIdentifier = x509SubjectKeyIdentifier;
133: }
134:
135: /**
136: * Get the byte stream of X509SubjectKeyIdentifier value stored in this Request.
137: *
138: * @return - byte[] representation of X509SubjectKeyIdentifier value.
139: */
140: public byte[] getSubjectKeyIdentifier() {
141: return x509SubjectKeyIdentifier;
142: }
143: }
144:
145: /**
146: * Request for an X.509 certificate whose Issuer Name and Serial Number
147: * values are given.
148: */
149: public static class X509IssuerSerialBasedRequest extends
150: X509CertificateRequest {
151:
152: private String issuerName;
153: private BigInteger serialNumber;
154:
155: /**
156: * Constructor.
157: *
158: * @param issuerName <code>java.lang.String</code> representing Certificate Issuer Name.
159: * @param serialNumber <code>java.math.BigInteger</code> representing the setial
160: * number of X509Certificate.
161: */
162: public X509IssuerSerialBasedRequest(String issuerName,
163: BigInteger serialNumber) {
164: this .issuerName = issuerName;
165: this .serialNumber = serialNumber;
166: }
167:
168: /**
169: * Get the Certificate Issuer Name.
170: *
171: * @return <code>java.lang.String</code> representing the certificate issuer name.
172: */
173: public String getIssuerName() {
174: return issuerName;
175: }
176:
177: /**
178: * Get the serial number of X509Certificate.
179: *
180: * @return <code>java.math.BigInteger</code> representing the Certificate's serial number.
181: */
182: public BigInteger getSerialNumber() {
183: return serialNumber;
184: }
185: }
186:
187: /**
188: * Request for an X.509 certificate given the Public Key
189: * This is an optional request and need not be handled
190: * by the handler.
191: *
192: * The runtime makes a callback with this request to obtain
193: * the certificate corresponding to the PublicKey. The returned
194: * certificate is stored in the requestor Subject for later use
195: * by the Application.
196: */
197: public static class PublicKeyBasedRequest extends
198: X509CertificateRequest {
199:
200: PublicKey pubKey = null;
201:
202: /**
203: * Constructor.
204: *
205: * @param pk <code>java.security.PublicKey</code> representing the PublicKey
206: * to be used for Signature Verification.
207: */
208: public PublicKeyBasedRequest(PublicKey pk) {
209: pubKey = pk;
210: }
211:
212: /**
213: * Get the PublicKey stored in this Request.
214: *
215: * @return <code>java.security.PublicKey</code> representing the PublicKey used
216: * for Signature Verification.
217: */
218: public PublicKey getPublicKey() {
219: return pubKey;
220: }
221:
222: }
223: }
|