001: /*
002: * $Id: SignatureKeyCallback.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.PrivateKey;
032: import java.security.PublicKey;
033: import java.security.cert.X509Certificate;
034:
035: /**
036: * CallBack implementation for signature key.
037: *
038: * @author XWS-Security Team
039: */
040: public class SignatureKeyCallback extends XWSSCallback implements
041: Callback {
042:
043: public static interface Request {
044: }
045:
046: private Request request;
047:
048: public SignatureKeyCallback(Request request) {
049: this .request = request;
050: }
051:
052: public Request getRequest() {
053: return request;
054: }
055:
056: /**
057: * A CallbackHandler handling an instance of this request should make
058: * sure that a private key and a corresponding X.509 certificate must
059: * be set on the request.
060: */
061: public static abstract class PrivKeyCertRequest implements Request {
062:
063: PrivateKey privateKey;
064:
065: X509Certificate certificate;
066:
067: /**
068: * Set the Private Key used for Signature Calculation.
069: *
070: * @param privateKey <code>java.security.PrivateKey</code> representing the
071: * PrivateKey to be used for Signature value calculation.
072: *
073: */
074: public void setPrivateKey(PrivateKey privateKey) {
075: this .privateKey = privateKey;
076: }
077:
078: /**
079: * Get the PrivateKey stored in this Request.
080: *
081: * @return <code>java.security.PrivateKey<code> - PrivateKey to be used for
082: * Signature value calculation.
083: */
084: public PrivateKey getPrivateKey() {
085: return privateKey;
086: }
087:
088: /**
089: * Set the X509Certificate used for Signature verification.
090: *
091: * @param certificate <code>java.security.X509Certificate</code> to be
092: * used for Signature Verification.
093: *
094: */
095: public void setX509Certificate(X509Certificate certificate) {
096: this .certificate = certificate;
097: }
098:
099: /**
100: * Get the X509Certificate stored in this Request.
101: *
102: * @return <code>java.security.X509Certificate</code> - X509Certificate
103: * to be used for Signature Verification.
104: */
105: public X509Certificate getX509Certificate() {
106: return certificate;
107: }
108: }
109:
110: /**
111: * A Callback initialized with this request should be handled if there's
112: * some default private key to be used for signing.
113: */
114: public static class DefaultPrivKeyCertRequest extends
115: PrivKeyCertRequest {
116: }
117:
118: /**
119: * A Callback initialized with this request should be handled if the
120: * private key to be used for signing is mapped to some alias.
121: */
122: public static class AliasPrivKeyCertRequest extends
123: PrivKeyCertRequest {
124:
125: private String alias;
126:
127: /**
128: * Constructor.
129: *
130: * @param alias <code>java.lang.String</code> representing the alias of
131: * the PrivateKey to be used for Signature calculation.
132: */
133: public AliasPrivKeyCertRequest(String alias) {
134: this .alias = alias;
135: }
136:
137: /**
138: * Get the alias stored in this Request.
139: *
140: * @return <code>java.lang.String</code> representing the alias of the PrivateKey
141: * to be used for Signature calculation.
142: */
143: public String getAlias() {
144: return alias;
145: }
146: }
147:
148: /**
149: * A Callback initialized with this request should be handled if the
150: * private key to be used for signing is to be retrieved given the PublicKey
151: */
152: public static class PublicKeyBasedPrivKeyCertRequest extends
153: PrivKeyCertRequest {
154:
155: private PublicKey pk;
156:
157: /**
158: * Constructor.
159: *
160: * @param publicKey <code>java.security.PublicKey</code>.
161: */
162: public PublicKeyBasedPrivKeyCertRequest(PublicKey publicKey) {
163: this .pk = publicKey;
164: }
165:
166: /**
167: * Get the PublicKey stored in this Request.
168: *
169: * @return <code>java.security.PublicKey</code>.
170: */
171: public PublicKey getPublicKey() {
172: return pk;
173: }
174: }
175: }
|