001: /*
002: * $Id: EncryptionKeyCallback.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 javax.crypto.SecretKey;
035:
036: /**
037: * CallBack implementation for encryption key.
038: *
039: * @author XWS-Security Team
040: */
041: public class EncryptionKeyCallback extends XWSSCallback implements
042: Callback {
043:
044: public static interface Request {
045: }
046:
047: private Request request;
048:
049: public EncryptionKeyCallback(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 must be set on the request.
060: */
061: public static abstract class X509CertificateRequest implements
062: Request {
063:
064: X509Certificate certificate;
065:
066: public void setX509Certificate(X509Certificate certificate) {
067: this .certificate = certificate;
068: }
069:
070: public X509Certificate getX509Certificate() {
071: return certificate;
072: }
073: }
074:
075: /**
076: * A Callback initialized with this request should be handled if there's
077: * some default X.509 certificate to be used for encryption.
078: */
079: public static class DefaultX509CertificateRequest extends
080: X509CertificateRequest {
081: }
082:
083: /**
084: * A Callback initialized with this request should be handled if the
085: * X.509 certificate to be used for encryption is mapped to some alias.
086: */
087: public static class AliasX509CertificateRequest extends
088: X509CertificateRequest {
089:
090: private String alias;
091:
092: /**
093: * Constructor.
094: *
095: * @param alias <code>String</code> representing the alias of the X509Certificate.
096: *
097: */
098: public AliasX509CertificateRequest(String alias) {
099: this .alias = alias;
100: }
101:
102: /**
103: * Get the alias stored in this Request.
104: *
105: * @return <code>java.lang.String</code>
106: */
107: public String getAlias() {
108: return alias;
109: }
110: }
111:
112: /**
113: * A CallbackHandler handling an instance of this request should make
114: * sure that a symmetric key must be set on the request.
115: */
116: public static abstract class SymmetricKeyRequest implements Request {
117:
118: SecretKey symmetricKey;
119:
120: /**
121: * Constructor.
122: *
123: * @param symmetricKey <code>javax.crypto.SecretKey</code> representing the
124: * SymmetricKey to be used for Encryption.
125: */
126: public void setSymmetricKey(SecretKey symmetricKey) {
127: this .symmetricKey = symmetricKey;
128: }
129:
130: /**
131: * Get the SymmetricKey stored in this Request.
132: *
133: * @return <code>javax.crypto.SecretKey</code>.
134: *
135: */
136: public SecretKey getSymmetricKey() {
137: return symmetricKey;
138: }
139: }
140:
141: /**
142: * A CallbackHandler handling an instance of this request should make
143: * sure that a symmetric key alias must be set on the request.
144: */
145: public static class AliasSymmetricKeyRequest extends
146: SymmetricKeyRequest {
147:
148: private String alias;
149:
150: /**
151: * Constructor.
152: *
153: * @param alias <code>java.lang.String</code> representing the alias of the
154: * SymmetricKey to be used for Encryption.
155: */
156: public AliasSymmetricKeyRequest(String alias) {
157: this .alias = alias;
158: }
159:
160: /**
161: * Get the alias stored in this Request.
162: *
163: * @return <code>java.lang.String</code> - alias of the SymmetricKey
164: */
165: public String getAlias() {
166: return alias;
167: }
168: }
169:
170: /*Request for an X.509 certificate given the Public Key
171: * This is an optional request and need not be handled
172: * by the handler.
173: *
174: * The runtime makes a callback with this request to obtain
175: * the certificate corresponding to the PublicKey.
176: */
177: public static class PublicKeyBasedRequest extends
178: X509CertificateRequest {
179:
180: PublicKey pubKey = null;
181:
182: /**
183: * Constructor.
184: *
185: * @param pk <code>java.security.PublicKey</code> representing the PublicKey
186: * to be used for Encryption.
187: */
188: public PublicKeyBasedRequest(PublicKey pk) {
189: pubKey = pk;
190: }
191:
192: /**
193: * Get the PublicKey stored in this Request.
194: *
195: * @return <code>java.security.PublicKey</code>
196: */
197: public PublicKey getPublicKey() {
198: return pubKey;
199: }
200:
201: }
202:
203: }
|