001: /*
002: * $Id: ProcessingContextImpl.java,v 1.9 2007/05/10 09:22:41 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;
028:
029: import com.sun.xml.ws.security.IssuedTokenContext;
030: import java.util.Map;
031: import java.util.Hashtable;
032: import java.util.HashMap;
033: import java.util.List;
034: import java.util.ArrayList;
035: import javax.xml.soap.SOAPMessage;
036:
037: import com.sun.xml.wss.ProcessingContext;
038: import com.sun.xml.wss.XWSSecurityException;
039:
040: import com.sun.xml.wss.impl.policy.SecurityPolicy;
041: import com.sun.xml.wss.impl.policy.StaticPolicyContext;
042: import com.sun.xml.wss.impl.policy.mls.MessagePolicy;
043:
044: import org.w3c.dom.Element;
045:
046: public class ProcessingContextImpl extends ProcessingContext {
047:
048: protected WSSAssertion wssAssertion = null;
049:
050: protected Hashtable issuedTokenContextMap = null;
051:
052: // Security runtime would populate received client creds into it
053: // when it is an incoming Trust or SC message
054: private static final String TRUST_CLIENT_CREDENTIALS = "TrustClientCredentialHolder";
055: private static final String ISSUED_SAML_TOKEN = "IssuedSAMLToken";
056: private static final String SAMLID_VS_KEY_CACHE = "SAMLID_VS_KEY_CACHE";
057: private static final String INCOMING_ASSERTION_ID = "Incoming_Saml_Assertion_Id";
058:
059: // Hack required for DecryptionProcessor
060: protected AlgorithmSuite algoSuite = null;
061: // for Issued Token
062: protected boolean policyHasIssuedToken = false;
063:
064: protected IssuedTokenContext secureConversationContext = null;
065: protected IssuedTokenContext trustContext = null;
066:
067: protected MessagePolicy inferredSecurityPolicy = new MessagePolicy();
068:
069: protected List signConfirmIds = new ArrayList();
070:
071: // private OperationResolver operationResolver = null;
072: private boolean isTrustMsg = false;
073:
074: private long timestampTimeout = 0;
075:
076: /**
077: *Default constructor
078: */
079: public ProcessingContextImpl() {
080: }
081:
082: /**
083: *constructor
084: */
085: public ProcessingContextImpl(Map invocationProps) {
086: properties = invocationProps;
087: }
088:
089: /**
090: * Constructor
091: * @param context the static policy context for this request
092: * @param securityPolicy the SecurityPolicy to be applied for this request
093: * @param message the SOAPMessage
094: * @throws XWSSecurityException if there was an error in creating the ProcessingContext
095: */
096: public ProcessingContextImpl(StaticPolicyContext context,
097: SecurityPolicy securityPolicy, SOAPMessage message)
098: throws XWSSecurityException {
099: super (context, securityPolicy, message);
100: }
101:
102: /**
103: * copy operator
104: * @param ctx1 the ProcessingContext to which to copy
105: * @param ctx2 the ProcessingContext from which to copy
106: * @throws XWSSecurityException if there was an error during the copy operation
107: */
108: public void copy(ProcessingContext ctxx1, ProcessingContext ctxx2)
109: throws XWSSecurityException {
110: if (ctxx2 instanceof ProcessingContextImpl) {
111: ProcessingContextImpl ctx1 = (ProcessingContextImpl) ctxx1;
112: ProcessingContextImpl ctx2 = (ProcessingContextImpl) ctxx2;
113: super .copy(ctx1, ctx2);
114: ctx1.setIssuedTokenContextMap(ctx2
115: .getIssuedTokenContextMap());
116: ctx1.setAlgorithmSuite(ctx2.getAlgorithmSuite());
117: ctx1.setSecureConversationContext(ctx2
118: .getSecureConversationContext());
119: ctx1.setWSSAssertion(ctx2.getWSSAssertion());
120: ctx1.inferredSecurityPolicy = ctx2
121: .getInferredSecurityPolicy();
122: //ctx1.setOperationResolver(ctx2.getOperationResolver());
123: ctx1.isTrustMessage(ctx2.isTrustMessage());
124: ctx1.hasIssuedToken(ctx2.hasIssuedToken());
125: ctx1.setTimestampTimeout(ctx2.getTimestampTimeout());
126: } else {
127: super .copy(ctxx1, ctxx2);
128: }
129: }
130:
131: public void setIssuedTokenContextMap(Hashtable issuedTokenContextMap) {
132: this .issuedTokenContextMap = issuedTokenContextMap;
133: }
134:
135: public Hashtable getIssuedTokenContextMap() {
136: return issuedTokenContextMap;
137: }
138:
139: /* (non-Javadoc)
140: * @return SecurableSoapMessage
141: */
142: public SecurableSoapMessage getSecurableSoapMessage() {
143: return secureMessage;
144: }
145:
146: public IssuedTokenContext getIssuedTokenContext(String policyID) {
147: if (issuedTokenContextMap == null) {
148: //throw new RuntimeException("Internal Error: IssuedTokenContext(s) not initialized in ProcessingContext");
149: return null;
150: }
151: return (IssuedTokenContext) issuedTokenContextMap.get(policyID);
152: }
153:
154: public void setIssuedTokenContext(
155: IssuedTokenContext issuedTokenContext, String policyID) {
156: if (issuedTokenContextMap == null) {
157: //TODO: This is temporary for testing
158: // Once integrated we must throw an RT exception from here
159: issuedTokenContextMap = new Hashtable();
160: }
161: issuedTokenContextMap.put(policyID, issuedTokenContext);
162: }
163:
164: public void setTrustCredentialHolder(IssuedTokenContext ctx) {
165: getExtraneousProperties().put(TRUST_CLIENT_CREDENTIALS, ctx);
166: }
167:
168: public IssuedTokenContext getTrustCredentialHolder() {
169: return (IssuedTokenContext) getExtraneousProperties().get(
170: TRUST_CLIENT_CREDENTIALS);
171: }
172:
173: public Element getIssuedSAMLToken() {
174: return (Element) getExtraneousProperties().get(
175: ISSUED_SAML_TOKEN);
176: }
177:
178: public void setIssuedSAMLToken(Element elem) {
179: getExtraneousProperties().put(ISSUED_SAML_TOKEN, elem);
180: }
181:
182: public void setIncomingAssertionId(String assid) {
183: getExtraneousProperties().put(INCOMING_ASSERTION_ID, assid);
184: }
185:
186: public String getIncomingAssertionId() {
187: return (String) getExtraneousProperties().get(
188: INCOMING_ASSERTION_ID);
189: }
190:
191: public void setSecureConversationContext(IssuedTokenContext ctx) {
192: secureConversationContext = ctx;
193: }
194:
195: public IssuedTokenContext getSecureConversationContext() {
196: return secureConversationContext;
197: }
198:
199: public void setTrustContext(IssuedTokenContext ctx) {
200: trustContext = ctx;
201: }
202:
203: public IssuedTokenContext getTrustContext() {
204: return trustContext;
205: }
206:
207: //TODO:Having to add AlgorithmSuite here because we need
208: // it in the KeyResolver (Encryption)
209: public AlgorithmSuite getAlgorithmSuite() {
210: return algoSuite;
211: }
212:
213: public void setAlgorithmSuite(AlgorithmSuite suite) {
214: algoSuite = suite;
215: }
216:
217: public void setWSSAssertion(WSSAssertion wssAssertion) {
218: this .wssAssertion = wssAssertion;
219: }
220:
221: public WSSAssertion getWSSAssertion() {
222: return wssAssertion;
223: }
224:
225: public MessagePolicy getInferredSecurityPolicy() {
226: return inferredSecurityPolicy;
227: }
228:
229: public HashMap getSamlIdVSKeyCache() {
230: if (getExtraneousProperties().get(SAMLID_VS_KEY_CACHE) == null) {
231: getExtraneousProperties().put(SAMLID_VS_KEY_CACHE,
232: new HashMap());
233: }
234: return (HashMap) getExtraneousProperties().get(
235: SAMLID_VS_KEY_CACHE);
236: }
237:
238: // public void setOperationResolver(OperationResolver operationResolver){
239: // this.operationResolver = operationResolver;
240: // }
241: //
242: // public OperationResolver getOperationResolver(){
243: // return operationResolver;
244: // }
245:
246: public void isTrustMessage(boolean isTrust) {
247: this .isTrustMsg = isTrust;
248: }
249:
250: public boolean isTrustMessage() {
251: return isTrustMsg;
252: }
253:
254: public List getSignatureConfirmationIds() {
255: return signConfirmIds;
256: }
257:
258: public boolean hasIssuedToken() {
259: return policyHasIssuedToken;
260: }
261:
262: public void hasIssuedToken(boolean flag) {
263: policyHasIssuedToken = flag;
264: }
265:
266: public long getTimestampTimeout() {
267: return this .timestampTimeout;
268: }
269:
270: public void setTimestampTimeout(long timeout) {
271: this.timestampTimeout = timeout;
272: }
273: }
|