001: /*
002: * $Id: KeyInfoStrategy.java,v 1.3 2006/09/29 12:04:56 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.keyinfo;
028:
029: import com.sun.xml.wss.impl.MessageConstants;
030: import com.sun.xml.wss.impl.SecurableSoapMessage;
031: import com.sun.xml.wss.XWSSecurityException;
032:
033: import com.sun.xml.wss.core.SecurityTokenReference;
034: import com.sun.xml.wss.core.KeyInfoHeaderBlock;
035:
036: import java.security.cert.X509Certificate;
037:
038: /**
039: * The interface for different KeyInfo Schemes
040: * @author XWS Security team
041: * @author K.Venugopal@sun.com
042: */
043: public abstract class KeyInfoStrategy {
044:
045: public static KeyInfoStrategy getInstance(String strategy) {
046: //TODO: For now.
047: if (MessageConstants.KEY_INDETIFIER_TYPE == strategy
048: || MessageConstants.KEY_INDETIFIER_TYPE
049: .equals(strategy)) {
050: return new KeyIdentifierStrategy();
051: } else if (MessageConstants.THUMB_PRINT_TYPE == strategy
052: || MessageConstants.THUMB_PRINT_TYPE.equals(strategy)) {
053: return new KeyIdentifierStrategy(
054: KeyIdentifierStrategy.THUMBPRINT);
055: } else if (MessageConstants.EK_SHA1_TYPE == strategy
056: || MessageConstants.EK_SHA1_TYPE.equals(strategy)) {
057: return new KeyIdentifierStrategy(
058: KeyIdentifierStrategy.ENCRYPTEDKEYSHA1);
059: } else if (MessageConstants.KEY_NAME_TYPE == strategy
060: || MessageConstants.KEY_NAME_TYPE.equals(strategy)) {
061: return new KeyNameStrategy();
062: } else if (MessageConstants.DIRECT_REFERENCE_TYPE == strategy
063: || MessageConstants.DIRECT_REFERENCE_TYPE
064: .equals(strategy)) {
065: return new DirectReferenceStrategy();
066: } else if (MessageConstants.X509_ISSUER_TYPE == strategy
067: || MessageConstants.X509_ISSUER_TYPE.equals(strategy)) {
068: return new X509IssuerSerialStrategy();
069: } else if (MessageConstants.BINARY_SECRET == strategy
070: || MessageConstants.BINARY_SECRET.equals(strategy)) {
071: return new BinarySecretStrategy();
072: }
073: return null;
074: }
075:
076: /**
077: * insert the Key Information into a ds:KeyInfo using the
078: * appropriate scheme
079: *
080: * @param keyInfo
081: * the KeyInfo block into which the Key Information has to be inserted.
082: * @param secureMsg the SecurableSoapMessage
083: * @param x509TokenId value of the <xwss:X509Token>/@id in config file
084: * @throws XWSSecurityException
085: * if there was a problem in inserting the key information
086: */
087: public abstract void insertKey(KeyInfoHeaderBlock keyInfo,
088: SecurableSoapMessage secureMsg, String x509TokenId)
089: throws XWSSecurityException;
090:
091: /**
092: * insert the Key Information into a SecurityTokenReference using the
093: * appropriate scheme
094: *
095: * @param tokenRef
096: * the SecurityTokenReference into which the Key Information
097: * has to be inserted.
098: * @param secureMsg the SecurableSoapMessage
099: * @throws XWSSecurityException
100: * if there was a problem in inserting the key information
101: */
102: public abstract void insertKey(SecurityTokenReference tokenRef,
103: SecurableSoapMessage secureMsg) throws XWSSecurityException;
104:
105: /**
106: * Sets the certificate corresponding to the security operation
107: */
108: public abstract void setCertificate(X509Certificate cert);
109:
110: public abstract String getAlias();
111: }
|