| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>RampartMessageData.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="right"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Coverage Report</a> > <a href="index.html" class="el_package">org.apache.rampart</a> > <span class="el_source">RampartMessageData.java</span></div><h1>RampartMessageData.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2004,2005 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package org.apache.rampart; |
| |
| import org.apache.axiom.om.OMElement; |
| import org.apache.axiom.soap.SOAPEnvelope; |
| import org.apache.axis2.AxisFault; |
| import org.apache.axis2.context.MessageContext; |
| import org.apache.axis2.context.OperationContext; |
| import org.apache.axis2.description.AxisService; |
| import org.apache.axis2.description.Parameter; |
| import org.apache.axis2.engine.AxisConfiguration; |
| import org.apache.axis2.util.PolicyUtil; |
| import org.apache.axis2.wsdl.WSDLConstants; |
| import org.apache.neethi.Policy; |
| import org.apache.neethi.PolicyComponent; |
| import org.apache.neethi.PolicyEngine; |
| import org.apache.rahas.RahasConstants; |
| import org.apache.rahas.SimpleTokenStore; |
| import org.apache.rahas.TokenStorage; |
| import org.apache.rampart.handler.WSSHandlerConstants; |
| import org.apache.rampart.policy.RampartPolicyBuilder; |
| import org.apache.rampart.policy.RampartPolicyData; |
| import org.apache.rampart.policy.model.RampartConfig; |
| import org.apache.rampart.saml.SAMLAssertionHandler; |
| import org.apache.rampart.saml.SAMLAssertionHandlerFactory; |
| import org.apache.rampart.util.Axis2Util; |
| import org.apache.rampart.util.RampartUtil; |
| import org.apache.ws.secpolicy.SP11Constants; |
| import org.apache.ws.secpolicy.SP12Constants; |
| import org.apache.ws.secpolicy.WSSPolicyException; |
| import org.apache.ws.security.SOAPConstants; |
| import org.apache.ws.security.WSConstants; |
| import org.apache.ws.security.WSSConfig; |
| import org.apache.ws.security.WSSecurityEngineResult; |
| import org.apache.ws.security.WSSecurityException; |
| import org.apache.ws.security.conversation.ConversationConstants; |
| import org.apache.ws.security.handler.WSHandlerConstants; |
| import org.apache.ws.security.handler.WSHandlerResult; |
| import org.apache.ws.security.message.WSSecHeader; |
| import org.apache.ws.security.message.token.SecurityContextToken; |
| import org.apache.ws.security.util.Loader; |
| import org.apache.ws.security.util.WSSecurityUtil; |
| import org.w3c.dom.Document; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| public class RampartMessageData { |
| |
| /** |
| * Axis2 parameter name to be used in the client's axis2 xml |
| */ |
| public final static String KEY_RAMPART_POLICY = "rampartPolicy"; |
| |
| public final static String KEY_RAMPART_IN_POLICY = "rampartInPolicy"; |
| |
| public final static String KEY_RAMPART_OUT_POLICY = "rampartOutPolicy"; |
| |
| /** |
| * Key to hold the populated RampartPolicyData object |
| */ |
| public final static String RAMPART_POLICY_DATA = "rampartPolicyData"; |
| |
| public final static String RAMPART_STS_POLICY = "rampartStsPolicy"; |
| |
| /** |
| * Key to hold the custom issued token identifier |
| */ |
| public final static String KEY_CUSTOM_ISSUED_TOKEN = "customIssuedToken"; |
| |
| /** |
| * Key to hold username which was used to authenticate |
| */ |
| public final static String USERNAME = "username"; |
| |
| /** |
| * |
| */ |
| public final static String SIGNATURE_CERT_ALIAS = "signatureCertAlias"; |
| |
| /** |
| * Key to hold the WS-Trust version |
| */ |
| public final static String KEY_WST_VERSION = "wstVersion"; |
| |
| public final static String PARAM_CLIENT_SIDE = "CLIENT_SIDE"; |
| |
| /** |
| * Key to hold the WS-SecConv version |
| */ |
| public final static String KEY_WSSC_VERSION = "wscVersion"; |
| |
| public static final String KEY_SCT_ISSUER_POLICY = "sct-issuer-policy"; |
| |
| public final static String CANCEL_REQUEST = "cancelrequest"; |
| |
| public final static String SCT_ID = "sctID"; |
| |
| public final static String X509_CERT ="X509Certificate"; |
| |
| <span class="fc" id="L116"> private MessageContext msgContext = null;</span> |
| |
| <span class="fc" id="L118"> private RampartPolicyData policyData = null;</span> |
| |
| <span class="fc" id="L120"> private WSSecHeader secHeader = null;</span> |
| |
| <span class="fc" id="L122"> private WSSConfig config = null;</span> |
| |
| <span class="fc" id="L124"> private int timeToLive = 300;</span> |
| |
| <span class="fc" id="L126"> private int timestampMaxSkew = 0;</span> |
| |
| private String timestampId; |
| |
| private Document document; |
| |
| private TokenStorage tokenStorage; |
| |
| /** |
| * WS-Trust version to use. |
| * |
| * Possible values: |
| * RahasConstants.VERSION_05_02 |
| * RahasConstants.VERSION_05_12 |
| */ |
| |
| <span class="fc" id="L142"> private int wstVersion = RahasConstants.VERSION_05_12;</span> |
| |
| <span class="fc" id="L144"> private int secConvVersion = ConversationConstants.VERSION_05_12;</span> |
| |
| /* |
| * IssuedTokens or SecurityContextTokens can be used |
| * as the encryption token, signature token |
| */ |
| private String issuedEncryptionTokenId; |
| |
| private String issuedSignatureTokenId; |
| |
| /** |
| * The service policy extracted from the message context. |
| * If policy is specified in the RampartConfig <b>this</b> will take precedence |
| */ |
| private Policy servicePolicy; |
| |
| private boolean isInitiator; |
| |
| private boolean sender; |
| |
| private ClassLoader customClassLoader; |
| |
| private SOAPConstants soapConstants; |
| |
| <span class="fc" id="L168"> public RampartMessageData(MessageContext msgCtx, boolean sender) throws RampartException {</span> |
| |
| <span class="fc" id="L170"> this.msgContext = msgCtx;</span> |
| |
| try { |
| |
| // First obtain the axis service as we have to do a null check, there can be situations |
| // where Axis Service is null |
| <span class="fc" id="L176"> AxisService axisService = msgCtx.getAxisService(); </span> |
| |
| <span class="pc bpc" id="L178" title="1 of 4 branches missed."> if(axisService != null && axisService.getParameter(PARAM_CLIENT_SIDE) != null) {</span> |
| <span class="fc" id="L179"> this.isInitiator = true;</span> |
| } else { |
| <span class="fc bfc" id="L181" title="All 2 branches covered."> this.isInitiator = !msgCtx.isServerSide();</span> |
| //TODO if Axis Service is null at this point, do we have to create a dummy one ?? |
| <span class="pc bpc" id="L183" title="1 of 4 branches missed."> if(this.isInitiator && axisService != null ) {</span> |
| <span class="fc" id="L184"> Parameter clientSideParam = new Parameter();</span> |
| <span class="fc" id="L185"> clientSideParam.setName(PARAM_CLIENT_SIDE);</span> |
| <span class="fc" id="L186"> clientSideParam.setLocked(true);</span> |
| <span class="fc" id="L187"> msgCtx.getAxisService().addParameter(clientSideParam);</span> |
| } |
| } |
| |
| <span class="fc bfc" id="L191" title="All 2 branches covered."> if(msgCtx.getProperty(KEY_RAMPART_POLICY) != null) {</span> |
| <span class="fc" id="L192"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_POLICY);</span> |
| } |
| |
| |
| // Checking which flow we are in |
| <span class="fc" id="L197"> int flow = msgCtx.getFLOW();</span> |
| |
| // If we are IN flow or IN_FAULT flow and the KEY_RAMPART_IN_POLICY is set , we set the |
| // merge that policy to the KEY_RAMPART_POLICY if it is present. Else we set |
| // KEY_RAMPART_IN_POLICY as the service policy |
| <span class="pc bpc" id="L202" title="1 of 6 branches missed."> if ( (flow == MessageContext.IN_FLOW || flow == MessageContext.IN_FAULT_FLOW ) </span> |
| && msgCtx.getProperty(KEY_RAMPART_IN_POLICY) != null) { |
| <span class="nc bnc" id="L204" title="All 2 branches missed."> if ( this.servicePolicy == null ) {</span> |
| <span class="nc" id="L205"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_IN_POLICY);</span> |
| } else { |
| <span class="nc" id="L207"> this.servicePolicy = this.servicePolicy.merge((Policy)msgCtx</span> |
| .getProperty(KEY_RAMPART_IN_POLICY)); |
| } |
| |
| // If we are OUT flow or OUT_FAULT flow and the KEY_RAMPART_OUT_POLICY is set , we set |
| // the merge that policy to the KEY_RAMPART_POLICY if it is present. Else we set |
| // KEY_RAMPART_OUT_POLICY as the service policy |
| <span class="pc bpc" id="L214" title="1 of 6 branches missed."> } else if ( (flow == MessageContext.OUT_FLOW || flow == MessageContext.OUT_FAULT_FLOW ) </span> |
| && msgCtx.getProperty(KEY_RAMPART_OUT_POLICY) != null) { |
| <span class="nc bnc" id="L216" title="All 2 branches missed."> if (this.servicePolicy == null) {</span> |
| <span class="nc" id="L217"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_OUT_POLICY);</span> |
| } else { |
| <span class="nc" id="L219"> this.servicePolicy = this.servicePolicy.merge((Policy)msgCtx</span> |
| .getProperty(KEY_RAMPART_OUT_POLICY)); |
| } |
| } |
| |
| /* |
| * Init policy: |
| * When creating the RampartMessageData instance we |
| * extract the service policy is set in the msgCtx. |
| * If it is missing then try to obtain from the configuration files. |
| */ |
| |
| <span class="fc bfc" id="L231" title="All 2 branches covered."> if (this.servicePolicy == null) {</span> |
| try { |
| <span class="fc" id="L233"> this.servicePolicy = msgCtx.getEffectivePolicy();</span> |
| <span class="fc" id="L234"> } catch (NullPointerException e) {</span> |
| //TODO remove this once AXIS2-4114 is fixed |
| <span class="pc bpc" id="L236" title="1 of 2 branches missed."> if (axisService != null) {</span> |
| <span class="fc" id="L237"> List<PolicyComponent> policyList = new ArrayList<PolicyComponent>();</span> |
| <span class="fc" id="L238"> policyList.addAll(axisService.getPolicySubject().getAttachedPolicyComponents());</span> |
| <span class="fc" id="L239"> AxisConfiguration axisConfiguration = axisService.getAxisConfiguration();</span> |
| <span class="fc" id="L240"> policyList.addAll(axisConfiguration.getPolicySubject().getAttachedPolicyComponents());</span> |
| <span class="fc" id="L241"> this.servicePolicy = PolicyUtil.getMergedPolicy(policyList, axisService);</span> |
| } |
| <span class="fc" id="L243"> }</span> |
| } |
| |
| <span class="fc bfc" id="L246" title="All 2 branches covered."> if(this.servicePolicy == null) {</span> |
| <span class="fc" id="L247"> Parameter param = msgCtx.getParameter(RampartMessageData.KEY_RAMPART_POLICY);</span> |
| <span class="pc bpc" id="L248" title="1 of 2 branches missed."> if(param != null) {</span> |
| <span class="nc" id="L249"> OMElement policyElem = param.getParameterElement().getFirstElement();</span> |
| <span class="nc" id="L250"> this.servicePolicy = PolicyEngine.getPolicy(policyElem);</span> |
| } |
| } |
| |
| <span class="fc bfc" id="L254" title="All 2 branches covered."> if(this.servicePolicy != null){</span> |
| <span class="fc" id="L255"> List it = (List)this.servicePolicy.getAlternatives().next();</span> |
| |
| //Process policy and build policy data |
| <span class="fc" id="L258"> this.policyData = RampartPolicyBuilder.build(it);</span> |
| |
| //Set the version |
| <span class="fc" id="L261"> setWSSecurityVersions(this.policyData.getWebServiceSecurityPolicyNS());</span> |
| } |
| |
| |
| <span class="fc bfc" id="L265" title="All 2 branches covered."> if(this.policyData != null) {</span> |
| |
| // Get the SOAP envelope as document, then create a security |
| // header and insert into the document (Envelope) |
| // WE SHOULD ONLY DO THE CONVERTION IF THERE IS AN APPLICABLE POLICY |
| <span class="fc" id="L270"> this.document = Axis2Util.getDocumentFromSOAPEnvelope(msgCtx.getEnvelope(), true);</span> |
| <span class="fc" id="L271"> msgCtx.setEnvelope((SOAPEnvelope)this.document.getDocumentElement());</span> |
| |
| <span class="fc" id="L273"> this.soapConstants = WSSecurityUtil.getSOAPConstants(this.document.getDocumentElement());</span> |
| |
| // Update the Rampart Config if RampartConfigCallbackHandler is present in the |
| // RampartConfig |
| |
| <span class="fc" id="L278"> RampartConfigCallbackHandler rampartConfigCallbackHandler = RampartUtil</span> |
| .getRampartConfigCallbackHandler(msgCtx, policyData); |
| |
| <span class="fc bfc" id="L281" title="All 2 branches covered."> if (rampartConfigCallbackHandler != null) {</span> |
| <span class="fc" id="L282"> rampartConfigCallbackHandler.update(policyData.getRampartConfig());</span> |
| } |
| |
| // Update TTL and max skew time |
| <span class="fc" id="L286"> RampartConfig policyDataRampartConfig = policyData.getRampartConfig();</span> |
| <span class="pc bpc" id="L287" title="1 of 2 branches missed."> if (policyDataRampartConfig != null) {</span> |
| <span class="fc" id="L288"> String timeToLiveString = policyDataRampartConfig.getTimestampTTL();</span> |
| <span class="pc bpc" id="L289" title="2 of 4 branches missed."> if (timeToLiveString != null && !timeToLiveString.equals("")) {</span> |
| <span class="fc" id="L290"> this.setTimeToLive(Integer.parseInt(timeToLiveString));</span> |
| } |
| |
| <span class="fc" id="L293"> String maxSkewString = policyDataRampartConfig.getTimestampMaxSkew();</span> |
| <span class="pc bpc" id="L294" title="2 of 4 branches missed."> if (maxSkewString != null && !maxSkewString.equals("")) {</span> |
| <span class="fc" id="L295"> this.setTimestampMaxSkew(Integer.parseInt(maxSkewString));</span> |
| } |
| } |
| |
| //Check for RST and RSTR for an SCT |
| <span class="fc" id="L300"> String wsaAction = msgContext.getWSAAction();</span> |
| <span class="fc bfc" id="L301" title="All 4 branches covered."> if(WSSHandlerConstants.RST_ACTON_SCT.equals(wsaAction)</span> |
| || WSSHandlerConstants.RSTR_ACTON_SCT.equals(wsaAction)) { |
| //submissive version |
| <span class="fc" id="L304"> setTrustParameters();</span> |
| <span class="fc bfc" id="L305" title="All 4 branches covered."> }else if(WSSHandlerConstants.RST_ACTON_SCT_STANDARD.equals(wsaAction)</span> |
| || WSSHandlerConstants.RSTR_ACTON_SCT_STANDARD.equals(wsaAction)) { |
| //standard policy spec 1.2 |
| <span class="fc" id="L308"> setTrustParameters();</span> |
| } |
| } |
| |
| |
| <span class="fc" id="L313"> this.sender = sender;</span> |
| |
| <span class="fc" id="L315"> OperationContext opCtx = this.msgContext.getOperationContext();</span> |
| |
| <span class="fc bfc" id="L317" title="All 4 branches covered."> if(!this.isInitiator && this.sender) {</span> |
| //Get hold of the incoming msg ctx |
| MessageContext inMsgCtx; |
| <span class="pc bpc" id="L320" title="1 of 6 branches missed."> if (opCtx != null</span> |
| && (inMsgCtx = opCtx |
| .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)) != null |
| && msgContext.getProperty(WSHandlerConstants.RECV_RESULTS) == null) { |
| <span class="fc" id="L324"> msgContext.setProperty(WSHandlerConstants.RECV_RESULTS, </span> |
| inMsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS)); |
| |
| //If someone set the sct_id externally use it at the receiver |
| <span class="fc" id="L328"> msgContext.setProperty(SCT_ID, inMsgCtx.getProperty(SCT_ID));</span> |
| } |
| } |
| |
| <span class="fc bfc" id="L332" title="All 4 branches covered."> if(this.isInitiator && !this.sender) {</span> |
| MessageContext outMsgCtx; |
| <span class="pc bpc" id="L334" title="1 of 4 branches missed."> if (opCtx != null</span> |
| && (outMsgCtx = opCtx |
| .getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE)) != null) { |
| |
| //If someone set the sct_id externally use it at the receiver |
| <span class="fc" id="L339"> msgContext.setProperty(SCT_ID, outMsgCtx.getProperty(SCT_ID));</span> |
| } |
| } |
| |
| // Check whether RampartConfig is present |
| <span class="pc bpc" id="L344" title="1 of 4 branches missed."> if (this.policyData != null && this.policyData.getRampartConfig() != null) {</span> |
| |
| <span class="fc" id="L346"> boolean timestampPrecisionInMilliseconds = Boolean.valueOf(this.policyData</span> |
| .getRampartConfig().getTimestampPrecisionInMilliseconds()).booleanValue(); |
| |
| // This is not the default behavior, we clone the default WSSConfig to prevent this |
| // affecting globally |
| <span class="pc bpc" id="L351" title="1 of 2 branches missed."> if (timestampPrecisionInMilliseconds == WSSConfig.getNewInstance()</span> |
| .isPrecisionInMilliSeconds()) { |
| <span class="fc" id="L353"> this.config = WSSConfig.getNewInstance();</span> |
| } else { |
| <span class="nc" id="L355"> this.config = RampartUtil.getWSSConfigInstance();</span> |
| <span class="nc" id="L356"> this.config.setPrecisionInMilliSeconds(timestampPrecisionInMilliseconds); </span> |
| } |
| <span class="fc" id="L358"> } else {</span> |
| <span class="fc" id="L359"> this.config = WSSConfig.getNewInstance();</span> |
| } |
| |
| // To handle scenarios where password type is not set by default. |
| <span class="fc" id="L363"> this.config.setHandleCustomPasswordTypes(true);</span> |
| |
| <span class="pc bpc" id="L365" title="1 of 2 branches missed."> if (axisService != null) { </span> |
| <span class="fc" id="L366"> this.customClassLoader = axisService.getClassLoader(); </span> |
| } |
| |
| <span class="fc bfc" id="L369" title="All 4 branches covered."> if(this.sender && this.policyData != null) {</span> |
| <span class="fc" id="L370"> this.secHeader = new WSSecHeader();</span> |
| <span class="fc" id="L371"> secHeader.insertSecurityHeader(this.document);</span> |
| } |
| |
| <span class="nc" id="L374"> } catch (AxisFault e) {</span> |
| <span class="nc" id="L375"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="nc" id="L376"> } catch (WSSPolicyException e) {</span> |
| <span class="nc" id="L377"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="nc" id="L378"> } catch (WSSecurityException e) {</span> |
| <span class="nc" id="L379"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="fc" id="L380"> }</span> |
| |
| <span class="fc" id="L382"> }</span> |
| |
| private void setWSSecurityVersions(String namespace) throws RampartException { |
| |
| <span class="pc bpc" id="L386" title="2 of 4 branches missed."> if (namespace == null || namespace.equals("")) {</span> |
| <span class="nc" id="L387"> throw new RampartException("Security policy namespace cannot be null.");</span> |
| } |
| |
| <span class="fc bfc" id="L390" title="All 2 branches covered."> if (SP11Constants.SP_NS.equals(namespace)) {</span> |
| <span class="fc" id="L391"> this.wstVersion = RahasConstants.VERSION_05_02;</span> |
| <span class="fc" id="L392"> this.secConvVersion = ConversationConstants.VERSION_05_02;</span> |
| <span class="pc bpc" id="L393" title="1 of 2 branches missed."> } else if (SP12Constants.SP_NS.equals(namespace)) {</span> |
| <span class="fc" id="L394"> this.wstVersion = RahasConstants.VERSION_05_12;</span> |
| <span class="fc" id="L395"> this.secConvVersion = ConversationConstants.VERSION_05_12;</span> |
| } else { |
| <span class="nc" id="L397"> throw new RampartException("Invalid namespace received, " + namespace);</span> |
| } |
| |
| <span class="fc" id="L400"> }</span> |
| |
| private void setTrustParameters() throws RampartException { |
| |
| <span class="fc bfc" id="L404" title="All 2 branches covered."> if (this.policyData.getIssuerPolicy() == null) {</span> |
| <span class="fc" id="L405"> return;</span> |
| } |
| |
| <span class="fc" id="L408"> this.servicePolicy = this.policyData.getIssuerPolicy();</span> |
| |
| <span class="fc" id="L410"> RampartConfig rampartConfig = policyData.getRampartConfig();</span> |
| <span class="pc bpc" id="L411" title="1 of 2 branches missed."> if (rampartConfig != null) {</span> |
| /* |
| * Copy crypto info into the new issuer policy |
| */ |
| <span class="fc" id="L415"> RampartConfig rc = new RampartConfig();</span> |
| <span class="fc" id="L416"> rc.setEncrCryptoConfig(rampartConfig.getEncrCryptoConfig());</span> |
| <span class="fc" id="L417"> rc.setSigCryptoConfig(rampartConfig.getSigCryptoConfig());</span> |
| <span class="fc" id="L418"> rc.setDecCryptoConfig(rampartConfig.getDecCryptoConfig());</span> |
| <span class="fc" id="L419"> rc.setUser(rampartConfig.getUser());</span> |
| <span class="fc" id="L420"> rc.setUserCertAlias(rc.getUserCertAlias());</span> |
| <span class="fc" id="L421"> rc.setEncryptionUser(rampartConfig.getEncryptionUser());</span> |
| <span class="fc" id="L422"> rc.setPwCbClass(rampartConfig.getPwCbClass());</span> |
| <span class="fc" id="L423"> rc.setSSLConfig(rampartConfig.getSSLConfig());</span> |
| |
| <span class="fc" id="L425"> this.servicePolicy.addAssertion(rc);</span> |
| } |
| |
| <span class="fc" id="L428"> List it = (List) this.servicePolicy.getAlternatives().next();</span> |
| |
| //Process policy and build policy data |
| try { |
| <span class="fc" id="L432"> this.policyData = RampartPolicyBuilder.build(it);</span> |
| <span class="nc" id="L433"> } catch (WSSPolicyException e) {</span> |
| <span class="nc" id="L434"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="fc" id="L435"> }</span> |
| |
| <span class="fc" id="L437"> }</span> |
| |
| /** |
| * @return Returns the document. |
| */ |
| public Document getDocument() { |
| <span class="fc" id="L443"> return document;</span> |
| } |
| |
| /** |
| * @param document The document to set. |
| * @deprecated document is derived from MessageContext passed in constructor |
| */ |
| public void setDocument(Document document) { |
| <span class="nc" id="L451"> this.document = document;</span> |
| <span class="nc" id="L452"> }</span> |
| |
| /** |
| * @return Returns the timeToLive. |
| */ |
| public int getTimeToLive() { |
| <span class="nc" id="L458"> return timeToLive;</span> |
| } |
| |
| /** |
| * @param timeToLive The timeToLive to set. |
| */ |
| public void setTimeToLive(int timeToLive) { |
| <span class="fc" id="L465"> this.timeToLive = timeToLive;</span> |
| <span class="fc" id="L466"> }</span> |
| |
| /** |
| * @return Returns the timestampMaxSkew. |
| */ |
| public int getTimestampMaxSkew() { |
| <span class="nc" id="L472"> return timestampMaxSkew;</span> |
| } |
| |
| /** |
| * @param timestampMaxSkew The timestampMaxSkew to set. |
| */ |
| public void setTimestampMaxSkew(int timestampMaxSkew) { |
| <span class="fc" id="L479"> this.timestampMaxSkew = timestampMaxSkew;</span> |
| <span class="fc" id="L480"> }</span> |
| |
| /** |
| * @return Returns the config. |
| */ |
| public WSSConfig getConfig() { |
| <span class="fc" id="L486"> return config;</span> |
| } |
| |
| /** |
| * @param config |
| * The config to set. |
| */ |
| public void setConfig(WSSConfig config) { |
| <span class="nc" id="L494"> this.config = config;</span> |
| <span class="nc" id="L495"> }</span> |
| |
| /** |
| * @return Returns the msgContext. |
| */ |
| public MessageContext getMsgContext() { |
| <span class="fc" id="L501"> return msgContext;</span> |
| } |
| |
| /** |
| * @param msgContext The msgContext to set. |
| * @deprecated MessageContext is set in constructor |
| */ |
| public void setMsgContext(MessageContext msgContext) { |
| <span class="nc" id="L509"> this.msgContext = msgContext;</span> |
| <span class="nc" id="L510"> }</span> |
| |
| /** |
| * @return Returns the policyData. |
| */ |
| public RampartPolicyData getPolicyData() { |
| <span class="fc" id="L516"> return policyData;</span> |
| } |
| |
| /** |
| * @param policyData The policyData to set. |
| * @deprecated Policy data determined within constructor |
| */ |
| public void setPolicyData(RampartPolicyData policyData) throws RampartException { |
| <span class="nc" id="L524"> this.policyData = policyData;</span> |
| |
| try { |
| //if client side then check whether sig conf enabled |
| //and get hold of the stored signature values |
| <span class="nc bnc" id="L529" title="All 6 branches missed."> if(this.isInitiator && !this.sender && policyData.isSignatureConfirmation()) {</span> |
| <span class="nc" id="L530"> OperationContext opCtx = msgContext.getOperationContext();</span> |
| <span class="nc" id="L531"> MessageContext outMsgCtx = opCtx</span> |
| .getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); |
| <span class="nc" id="L533"> msgContext.setProperty(WSHandlerConstants.SEND_SIGV, outMsgCtx</span> |
| .getProperty(WSHandlerConstants.SEND_SIGV)); |
| } |
| <span class="nc" id="L536"> } catch (AxisFault e) {</span> |
| <span class="nc" id="L537"> throw new RampartException("errorGettingSignatureValuesForSigconf", e);</span> |
| <span class="nc" id="L538"> }</span> |
| <span class="nc" id="L539"> }</span> |
| |
| /** |
| * @return Returns the secHeader. |
| */ |
| public WSSecHeader getSecHeader() { |
| <span class="fc" id="L545"> return secHeader;</span> |
| } |
| |
| /** |
| * @param secHeader |
| * The secHeader to set. |
| */ |
| public void setSecHeader(WSSecHeader secHeader) { |
| <span class="nc" id="L553"> this.secHeader = secHeader;</span> |
| <span class="nc" id="L554"> }</span> |
| |
| /** |
| * @return Returns the issuedEncryptionTokenId. |
| */ |
| public String getIssuedEncryptionTokenId() { |
| <span class="fc" id="L560"> return issuedEncryptionTokenId;</span> |
| } |
| |
| /** |
| * @param issuedEncryptionTokenId The issuedEncryptionTokenId to set. |
| */ |
| public void setIssuedEncryptionTokenId(String issuedEncryptionTokenId) { |
| <span class="nc" id="L567"> this.issuedEncryptionTokenId = issuedEncryptionTokenId;</span> |
| <span class="nc" id="L568"> }</span> |
| |
| /** |
| * @return Returns the issuedSignatureTokenId. |
| */ |
| public String getIssuedSignatureTokenId() { |
| <span class="nc bnc" id="L574" title="All 2 branches missed."> if(this.isInitiator) {</span> |
| <span class="nc" id="L575"> return issuedSignatureTokenId;</span> |
| } else { |
| //Pick the first SAML token |
| //TODO : This is a hack , MUST FIX |
| //get the sec context id from the req msg ctx |
| <span class="nc" id="L580"> List<WSHandlerResult> results</span> |
| = (List<WSHandlerResult>)this.msgContext.getProperty(WSHandlerConstants.RECV_RESULTS); |
| <span class="nc bnc" id="L582" title="All 2 branches missed."> for (WSHandlerResult result : results) {</span> |
| <span class="nc" id="L583"> List<WSSecurityEngineResult> wsSecEngineResults = result.getResults();</span> |
| |
| <span class="nc bnc" id="L585" title="All 2 branches missed."> for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) {</span> |
| <span class="nc" id="L586"> final Integer actInt =</span> |
| (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); |
| <span class="nc bnc" id="L588" title="All 2 branches missed."> if (WSConstants.ST_UNSIGNED == actInt) {</span> |
| <span class="nc" id="L589"> final Object assertion =</span> |
| wsSecEngineResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION); |
| <span class="nc" id="L591"> SAMLAssertionHandler samlAssertionHandler</span> |
| = SAMLAssertionHandlerFactory.createAssertionHandler(assertion); |
| |
| <span class="nc" id="L594"> return samlAssertionHandler.getAssertionId();</span> |
| } |
| |
| <span class="nc" id="L597"> }</span> |
| <span class="nc" id="L598"> }</span> |
| <span class="nc" id="L599"> return null;</span> |
| } |
| } |
| |
| /** |
| * @param issuedSignatureTokenId The issuedSignatureTokenId to set. |
| */ |
| public void setIssuedSignatureTokenId(String issuedSignatureTokenId) { |
| <span class="nc" id="L607"> this.issuedSignatureTokenId = issuedSignatureTokenId;</span> |
| <span class="nc" id="L608"> }</span> |
| |
| /** |
| * @return Returns the secConvTokenId. |
| */ |
| public String getSecConvTokenId() { |
| <span class="fc" id="L614"> String id = null;</span> |
| |
| <span class="fc bfc" id="L616" title="All 2 branches covered."> if(this.isInitiator) {</span> |
| <span class="fc" id="L617"> String contextIdentifierKey = RampartUtil.getContextIdentifierKey(this.msgContext);</span> |
| <span class="fc" id="L618"> id = (String) RampartUtil.getContextMap(this.msgContext).get(contextIdentifierKey);</span> |
| <span class="fc" id="L619"> } else {</span> |
| //get the sec context id from the req msg ctx |
| <span class="fc" id="L621"> List<WSHandlerResult> results = (List<WSHandlerResult>)this.msgContext.getProperty(WSHandlerConstants.RECV_RESULTS);</span> |
| <span class="fc bfc" id="L622" title="All 2 branches covered."> for (WSHandlerResult result : results) {</span> |
| <span class="fc" id="L623"> List<WSSecurityEngineResult> wsSecEngineResults = result.getResults();</span> |
| |
| <span class="fc bfc" id="L625" title="All 2 branches covered."> for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) {</span> |
| <span class="fc" id="L626"> final Integer actInt =</span> |
| (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); |
| <span class="fc bfc" id="L628" title="All 2 branches covered."> if (WSConstants.SCT == actInt) {</span> |
| <span class="fc" id="L629"> final SecurityContextToken sct =</span> |
| ((SecurityContextToken) wsSecEngineResult |
| .get(WSSecurityEngineResult.TAG_SECURITY_CONTEXT_TOKEN)); |
| <span class="fc" id="L632"> id = sct.getID();</span> |
| } |
| |
| <span class="fc" id="L635"> }</span> |
| <span class="fc" id="L636"> }</span> |
| } |
| |
| <span class="pc bpc" id="L639" title="1 of 4 branches missed."> if(id == null || id.length() == 0) {</span> |
| //If we can't find the sec conv token id up to this point then |
| //check if someone has specified which one to use |
| <span class="fc" id="L642"> id = (String)this.msgContext.getProperty(SCT_ID);</span> |
| } |
| |
| <span class="fc" id="L645"> return id;</span> |
| } |
| |
| /** |
| * @param secConvTokenId The secConvTokenId to set. |
| */ |
| public void setSecConvTokenId(String secConvTokenId) { |
| <span class="fc" id="L652"> String contextIdentifierKey = RampartUtil.getContextIdentifierKey(this.msgContext);</span> |
| <span class="fc" id="L653"> RampartUtil.getContextMap(this.msgContext).put(</span> |
| contextIdentifierKey, |
| secConvTokenId); |
| <span class="fc" id="L656"> }</span> |
| |
| |
| |
| /** |
| * @return Returns the tokenStorage. |
| */ |
| public TokenStorage getTokenStorage() throws RampartException { |
| |
| <span class="fc bfc" id="L665" title="All 2 branches covered."> if(this.tokenStorage != null) {</span> |
| <span class="fc" id="L666"> return this.tokenStorage;</span> |
| } |
| |
| <span class="fc" id="L669"> TokenStorage storage = (TokenStorage) this.msgContext.getConfigurationContext().getProperty(</span> |
| TokenStorage.TOKEN_STORAGE_KEY); |
| |
| <span class="fc bfc" id="L672" title="All 2 branches covered."> if (storage != null) {</span> |
| <span class="fc" id="L673"> this.tokenStorage = storage;</span> |
| } else { |
| <span class="pc bpc" id="L675" title="2 of 4 branches missed."> if (this.policyData.getRampartConfig() != null &&</span> |
| this.policyData.getRampartConfig().getTokenStoreClass() != null) { |
| <span class="nc" id="L677"> Class stClass = null;</span> |
| <span class="nc" id="L678"> String storageClass = this.policyData.getRampartConfig()</span> |
| .getTokenStoreClass(); |
| try { |
| <span class="nc" id="L681"> stClass = Loader.loadClass(this.customClassLoader, storageClass);</span> |
| <span class="nc" id="L682"> } catch (ClassNotFoundException e) {</span> |
| <span class="nc" id="L683"> throw new RampartException(</span> |
| "WSHandler: cannot load token storage class: " |
| + storageClass, e); |
| <span class="nc" id="L686"> }</span> |
| try { |
| <span class="nc" id="L688"> this.tokenStorage = (TokenStorage) stClass.newInstance();</span> |
| <span class="nc" id="L689"> } catch (java.lang.Exception e) {</span> |
| <span class="nc" id="L690"> throw new RampartException(</span> |
| "Cannot create instance of token storage: " |
| + storageClass, e); |
| <span class="nc" id="L693"> }</span> |
| <span class="nc" id="L694"> } else {</span> |
| <span class="fc" id="L695"> this.tokenStorage = new SimpleTokenStore();</span> |
| |
| } |
| |
| //Set the storage instance |
| <span class="fc" id="L700"> this.msgContext.getConfigurationContext().setProperty(</span> |
| TokenStorage.TOKEN_STORAGE_KEY, this.tokenStorage); |
| } |
| |
| |
| <span class="fc" id="L705"> return tokenStorage;</span> |
| } |
| |
| /** |
| * @param tokenStorage The tokenStorage to set. |
| */ |
| public void setTokenStorage(TokenStorage tokenStorage) { |
| <span class="nc" id="L712"> this.tokenStorage = tokenStorage;</span> |
| <span class="nc" id="L713"> }</span> |
| |
| /** |
| * @return Returns the wstVersion. |
| */ |
| public int getWstVersion() { |
| <span class="fc" id="L719"> return wstVersion;</span> |
| } |
| |
| /** |
| * @param wstVersion The wstVersion to set. |
| * @deprecated This is defined by the class. |
| */ |
| public void setWstVersion(int wstVersion) { |
| <span class="nc" id="L727"> this.wstVersion = wstVersion;</span> |
| <span class="nc" id="L728"> }</span> |
| |
| /** |
| * @return Returns the secConvVersion. |
| */ |
| public int getSecConvVersion() { |
| <span class="fc" id="L734"> return secConvVersion;</span> |
| } |
| |
| /** |
| * @return Returns the servicePolicy. |
| */ |
| public Policy getServicePolicy() { |
| <span class="fc" id="L741"> return servicePolicy;</span> |
| } |
| |
| /** |
| * @param servicePolicy The servicePolicy to set. |
| * @deprecated servicePolicy determined in constructor |
| */ |
| public void setServicePolicy(Policy servicePolicy) { |
| <span class="nc" id="L749"> this.servicePolicy = servicePolicy;</span> |
| <span class="nc" id="L750"> }</span> |
| |
| /** |
| * @return Returns the timestampId. |
| */ |
| public String getTimestampId() { |
| <span class="fc" id="L756"> return timestampId;</span> |
| } |
| |
| /** |
| * @param timestampId The timestampId to set. |
| */ |
| public void setTimestampId(String timestampId) { |
| <span class="fc" id="L763"> this.timestampId = timestampId;</span> |
| <span class="fc" id="L764"> }</span> |
| |
| /** |
| * @return Returns the Initiator value |
| */ |
| public boolean isInitiator() { |
| <span class="fc" id="L770"> return isInitiator;</span> |
| } |
| |
| /** |
| * Returns the custom class loader if we are using one |
| * @return Returns the custom class loader if we are using one |
| */ |
| public ClassLoader getCustomClassLoader() { |
| <span class="fc" id="L778"> return customClassLoader;</span> |
| } |
| |
| /** |
| * Returns an <code>org.apache.ws.security.SOAPConstants</code> instance |
| * with soap version information of this request. |
| * @return Returns soap version information of this request |
| */ |
| public SOAPConstants getSoapConstants() { |
| <span class="fc" id="L787"> return soapConstants;</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.6.1.201212231917</span></div></body></html> |