| <?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.Assertion; |
| 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.RampartUsernameTokenValidator; |
| 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.WSSecurityEngine; |
| 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.Collection; |
| 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="L120"> private MessageContext msgContext = null;</span> |
| |
| <span class="fc" id="L122"> private RampartPolicyData policyData = null;</span> |
| |
| <span class="fc" id="L124"> private WSSecHeader secHeader = null;</span> |
| |
| <span class="fc" id="L126"> private WSSConfig config = null;</span> |
| |
| <span class="fc" id="L128"> private int timeToLive = 300;</span> |
| |
| <span class="fc" id="L130"> 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="L146"> private int wstVersion = RahasConstants.VERSION_05_12;</span> |
| |
| <span class="fc" id="L148"> 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="L172"> public RampartMessageData(MessageContext msgCtx, boolean sender) throws RampartException {</span> |
| |
| <span class="fc" id="L174"> this.msgContext = msgCtx;</span> |
| |
| try { |
| |
| // Set the WSSConfig |
| <span class="fc" id="L179"> this.config = WSSConfig.getNewInstance();</span> |
| |
| //Update the UsernameToken validator |
| <span class="fc" id="L182"> this.config.setValidator(WSSecurityEngine.USERNAME_TOKEN, RampartUsernameTokenValidator.class);</span> |
| |
| // 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="L186"> AxisService axisService = msgCtx.getAxisService(); </span> |
| |
| <span class="pc bpc" id="L188" title="1 of 4 branches missed."> if(axisService != null && axisService.getParameter(PARAM_CLIENT_SIDE) != null) {</span> |
| <span class="fc" id="L189"> this.isInitiator = true;</span> |
| } else { |
| <span class="fc bfc" id="L191" 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="L193" title="1 of 4 branches missed."> if(this.isInitiator && axisService != null ) {</span> |
| <span class="fc" id="L194"> Parameter clientSideParam = new Parameter();</span> |
| <span class="fc" id="L195"> clientSideParam.setName(PARAM_CLIENT_SIDE);</span> |
| <span class="fc" id="L196"> clientSideParam.setLocked(true);</span> |
| <span class="fc" id="L197"> msgCtx.getAxisService().addParameter(clientSideParam);</span> |
| } |
| } |
| |
| <span class="fc bfc" id="L201" title="All 2 branches covered."> if(msgCtx.getProperty(KEY_RAMPART_POLICY) != null) {</span> |
| <span class="fc" id="L202"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_POLICY);</span> |
| } |
| |
| |
| // Checking which flow we are in |
| <span class="fc" id="L207"> 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="L212" 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="L214" title="All 2 branches missed."> if ( this.servicePolicy == null ) {</span> |
| <span class="nc" id="L215"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_IN_POLICY);</span> |
| } else { |
| <span class="nc" id="L217"> 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="L224" 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="L226" title="All 2 branches missed."> if (this.servicePolicy == null) {</span> |
| <span class="nc" id="L227"> this.servicePolicy = (Policy)msgCtx.getProperty(KEY_RAMPART_OUT_POLICY);</span> |
| } else { |
| <span class="nc" id="L229"> 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="L241" title="All 2 branches covered."> if (this.servicePolicy == null) {</span> |
| try { |
| <span class="fc" id="L243"> this.servicePolicy = msgCtx.getEffectivePolicy();</span> |
| <span class="fc" id="L244"> } catch (NullPointerException e) {</span> |
| //TODO remove this once AXIS2-4114 is fixed |
| <span class="pc bpc" id="L246" title="1 of 2 branches missed."> if (axisService != null) {</span> |
| <span class="fc" id="L247"> Collection<PolicyComponent> policyList = new ArrayList<PolicyComponent>();</span> |
| <span class="fc" id="L248"> policyList.addAll(axisService.getPolicySubject().getAttachedPolicyComponents());</span> |
| <span class="fc" id="L249"> AxisConfiguration axisConfiguration = axisService.getAxisConfiguration();</span> |
| <span class="fc" id="L250"> policyList.addAll(axisConfiguration.getPolicySubject().getAttachedPolicyComponents());</span> |
| <span class="fc" id="L251"> this.servicePolicy = PolicyUtil.getMergedPolicy(policyList, axisService);</span> |
| } |
| <span class="fc" id="L253"> }</span> |
| } |
| |
| <span class="pc bpc" id="L256" title="1 of 2 branches missed."> if(this.servicePolicy == null) {</span> |
| <span class="nc" id="L257"> Parameter param = msgCtx.getParameter(RampartMessageData.KEY_RAMPART_POLICY);</span> |
| <span class="nc bnc" id="L258" title="All 2 branches missed."> if(param != null) {</span> |
| <span class="nc" id="L259"> OMElement policyElem = param.getParameterElement().getFirstElement();</span> |
| <span class="nc" id="L260"> this.servicePolicy = PolicyEngine.getPolicy(policyElem);</span> |
| } |
| } |
| |
| <span class="pc bpc" id="L264" title="1 of 2 branches missed."> if(this.servicePolicy != null){</span> |
| <span class="fc" id="L265"> List<Assertion> it = this.servicePolicy.getAlternatives().next();</span> |
| |
| //Process policy and build policy data |
| <span class="fc" id="L268"> this.policyData = RampartPolicyBuilder.build(it);</span> |
| |
| //Set the version |
| <span class="fc" id="L271"> setWSSecurityVersions(this.policyData.getWebServiceSecurityPolicyNS());</span> |
| } |
| |
| |
| <span class="pc bpc" id="L275" title="1 of 2 branches missed."> 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="L280"> this.document = Axis2Util.getDocumentFromSOAPEnvelope(msgCtx.getEnvelope(), true);</span> |
| <span class="fc" id="L281"> msgCtx.setEnvelope((SOAPEnvelope)this.document.getDocumentElement());</span> |
| |
| <span class="fc" id="L283"> this.soapConstants = WSSecurityUtil.getSOAPConstants(this.document.getDocumentElement());</span> |
| |
| // Update the Rampart Config if RampartConfigCallbackHandler is present in the |
| // RampartConfig |
| |
| <span class="fc" id="L288"> RampartConfigCallbackHandler rampartConfigCallbackHandler = RampartUtil</span> |
| .getRampartConfigCallbackHandler(msgCtx, policyData); |
| |
| <span class="fc bfc" id="L291" title="All 2 branches covered."> if (rampartConfigCallbackHandler != null) {</span> |
| <span class="fc" id="L292"> rampartConfigCallbackHandler.update(policyData.getRampartConfig());</span> |
| } |
| |
| // Update TTL and max skew time |
| <span class="fc" id="L296"> RampartConfig policyDataRampartConfig = policyData.getRampartConfig();</span> |
| <span class="fc bfc" id="L297" title="All 2 branches covered."> if (policyDataRampartConfig != null) {</span> |
| <span class="fc" id="L298"> String timeToLiveString = policyDataRampartConfig.getTimestampTTL();</span> |
| <span class="pc bpc" id="L299" title="2 of 4 branches missed."> if (timeToLiveString != null && !timeToLiveString.equals("")) {</span> |
| <span class="fc" id="L300"> this.setTimeToLive(Integer.parseInt(timeToLiveString));</span> |
| } |
| |
| <span class="fc" id="L303"> String maxSkewString = policyDataRampartConfig.getTimestampMaxSkew();</span> |
| <span class="pc bpc" id="L304" title="2 of 4 branches missed."> if (maxSkewString != null && !maxSkewString.equals("")) {</span> |
| <span class="fc" id="L305"> this.setTimestampMaxSkew(Integer.parseInt(maxSkewString));</span> |
| } |
| } |
| |
| //Check for RST and RSTR for an SCT |
| <span class="fc" id="L310"> String wsaAction = msgContext.getWSAAction();</span> |
| <span class="fc bfc" id="L311" 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="L314"> setTrustParameters();</span> |
| <span class="fc bfc" id="L315" 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="L318"> setTrustParameters();</span> |
| } |
| } |
| |
| |
| <span class="fc" id="L323"> this.sender = sender;</span> |
| |
| <span class="fc" id="L325"> OperationContext opCtx = this.msgContext.getOperationContext();</span> |
| |
| <span class="fc bfc" id="L327" 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="L330" title="2 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="L334"> 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="L338"> msgContext.setProperty(SCT_ID, inMsgCtx.getProperty(SCT_ID));</span> |
| } |
| } |
| |
| <span class="fc bfc" id="L342" title="All 4 branches covered."> if(this.isInitiator && !this.sender) {</span> |
| MessageContext outMsgCtx; |
| <span class="pc bpc" id="L344" 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="L349"> msgContext.setProperty(SCT_ID, outMsgCtx.getProperty(SCT_ID));</span> |
| } |
| } |
| |
| // Check whether RampartConfig is present |
| <span class="pc bpc" id="L354" title="1 of 4 branches missed."> if (this.policyData != null && this.policyData.getRampartConfig() != null) {</span> |
| |
| <span class="fc" id="L356"> boolean timestampPrecisionInMilliseconds = this.policyData</span> |
| .getRampartConfig().isDefaultTimestampPrecisionInMs(); |
| <span class="fc" id="L358"> boolean timestampStrict = this.policyData.getRampartConfig().isTimeStampStrict();</span> |
| |
| |
| // We do not need earlier logic as now WSS4J returns a new instance of WSSConfig, rather |
| // than a singleton instance. Therefore modifying logic as follows, |
| <span class="fc" id="L363"> this.config.setTimeStampStrict(timestampStrict);</span> |
| <span class="fc" id="L364"> this.config.setPrecisionInMilliSeconds(timestampPrecisionInMilliseconds);</span> |
| |
| } |
| |
| // To handle scenarios where password type is not set by default. |
| <span class="fc" id="L369"> this.config.setHandleCustomPasswordTypes(true);</span> |
| |
| <span class="pc bpc" id="L371" title="1 of 2 branches missed."> if (axisService != null) { </span> |
| <span class="fc" id="L372"> this.customClassLoader = axisService.getClassLoader(); </span> |
| } |
| |
| <span class="pc bpc" id="L375" title="1 of 4 branches missed."> if(this.sender && this.policyData != null) {</span> |
| <span class="fc" id="L376"> this.secHeader = new WSSecHeader();</span> |
| <span class="fc" id="L377"> secHeader.insertSecurityHeader(this.document);</span> |
| } |
| |
| <span class="nc" id="L380"> } catch (AxisFault e) {</span> |
| <span class="nc" id="L381"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="nc" id="L382"> } catch (WSSPolicyException e) {</span> |
| <span class="nc" id="L383"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="nc" id="L384"> } catch (WSSecurityException e) {</span> |
| <span class="nc" id="L385"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="fc" id="L386"> }</span> |
| |
| <span class="fc" id="L388"> }</span> |
| |
| private void setWSSecurityVersions(String namespace) throws RampartException { |
| |
| <span class="pc bpc" id="L392" title="2 of 4 branches missed."> if (namespace == null || namespace.equals("")) {</span> |
| <span class="nc" id="L393"> throw new RampartException("Security policy namespace cannot be null.");</span> |
| } |
| |
| <span class="fc bfc" id="L396" title="All 2 branches covered."> if (SP11Constants.SP_NS.equals(namespace)) {</span> |
| <span class="fc" id="L397"> this.wstVersion = RahasConstants.VERSION_05_02;</span> |
| <span class="fc" id="L398"> this.secConvVersion = ConversationConstants.VERSION_05_02;</span> |
| <span class="pc bpc" id="L399" title="1 of 2 branches missed."> } else if (SP12Constants.SP_NS.equals(namespace)) {</span> |
| <span class="fc" id="L400"> this.wstVersion = RahasConstants.VERSION_05_12;</span> |
| <span class="fc" id="L401"> this.secConvVersion = ConversationConstants.VERSION_05_12;</span> |
| } else { |
| <span class="nc" id="L403"> throw new RampartException("Invalid namespace received, " + namespace);</span> |
| } |
| |
| <span class="fc" id="L406"> }</span> |
| |
| private void setTrustParameters() throws RampartException { |
| |
| <span class="fc bfc" id="L410" title="All 2 branches covered."> if (this.policyData.getIssuerPolicy() == null) {</span> |
| <span class="fc" id="L411"> return;</span> |
| } |
| |
| <span class="fc" id="L414"> this.servicePolicy = this.policyData.getIssuerPolicy();</span> |
| |
| <span class="fc" id="L416"> RampartConfig rampartConfig = policyData.getRampartConfig();</span> |
| <span class="pc bpc" id="L417" title="1 of 2 branches missed."> if (rampartConfig != null) {</span> |
| /* |
| * Copy crypto info into the new issuer policy |
| */ |
| <span class="fc" id="L421"> RampartConfig rc = new RampartConfig();</span> |
| <span class="fc" id="L422"> rc.setEncrCryptoConfig(rampartConfig.getEncrCryptoConfig());</span> |
| <span class="fc" id="L423"> rc.setSigCryptoConfig(rampartConfig.getSigCryptoConfig());</span> |
| <span class="fc" id="L424"> rc.setDecCryptoConfig(rampartConfig.getDecCryptoConfig());</span> |
| <span class="fc" id="L425"> rc.setUser(rampartConfig.getUser());</span> |
| <span class="fc" id="L426"> rc.setUserCertAlias(rc.getUserCertAlias());</span> |
| <span class="fc" id="L427"> rc.setEncryptionUser(rampartConfig.getEncryptionUser());</span> |
| <span class="fc" id="L428"> rc.setPwCbClass(rampartConfig.getPwCbClass());</span> |
| <span class="fc" id="L429"> rc.setSSLConfig(rampartConfig.getSSLConfig());</span> |
| |
| <span class="fc" id="L431"> this.servicePolicy.addAssertion(rc);</span> |
| } |
| |
| <span class="fc" id="L434"> List<Assertion> it = this.servicePolicy.getAlternatives().next();</span> |
| |
| //Process policy and build policy data |
| try { |
| <span class="fc" id="L438"> this.policyData = RampartPolicyBuilder.build(it);</span> |
| <span class="nc" id="L439"> } catch (WSSPolicyException e) {</span> |
| <span class="nc" id="L440"> throw new RampartException("errorInExtractingMsgProps", e);</span> |
| <span class="fc" id="L441"> }</span> |
| |
| <span class="fc" id="L443"> }</span> |
| |
| /** |
| * @return Returns the document. |
| */ |
| public Document getDocument() { |
| <span class="fc" id="L449"> return document;</span> |
| } |
| |
| /** |
| * @return Returns the timeToLive. |
| */ |
| public int getTimeToLive() { |
| <span class="nc" id="L456"> return timeToLive;</span> |
| } |
| |
| /** |
| * @param timeToLive The timeToLive to set. |
| */ |
| public void setTimeToLive(int timeToLive) { |
| <span class="fc" id="L463"> this.timeToLive = timeToLive;</span> |
| <span class="fc" id="L464"> }</span> |
| |
| /** |
| * @return Returns the timestampMaxSkew. |
| */ |
| public int getTimestampMaxSkew() { |
| <span class="nc" id="L470"> return timestampMaxSkew;</span> |
| } |
| |
| /** |
| * @param timestampMaxSkew The timestampMaxSkew to set. |
| */ |
| public void setTimestampMaxSkew(int timestampMaxSkew) { |
| <span class="fc" id="L477"> this.timestampMaxSkew = timestampMaxSkew;</span> |
| <span class="fc" id="L478"> }</span> |
| |
| /** |
| * @return Returns the config. |
| */ |
| public WSSConfig getConfig() { |
| <span class="fc" id="L484"> return config;</span> |
| } |
| |
| /** |
| * @param config |
| * The config to set. |
| */ |
| public void setConfig(WSSConfig config) { |
| <span class="nc" id="L492"> this.config = config;</span> |
| <span class="nc" id="L493"> }</span> |
| |
| /** |
| * @return Returns the msgContext. |
| */ |
| public MessageContext getMsgContext() { |
| <span class="fc" id="L499"> return msgContext;</span> |
| } |
| |
| /** |
| * @return Returns the policyData. |
| */ |
| public RampartPolicyData getPolicyData() { |
| <span class="fc" id="L506"> return policyData;</span> |
| } |
| |
| /** |
| * @return Returns the secHeader. |
| */ |
| public WSSecHeader getSecHeader() { |
| <span class="fc" id="L513"> return secHeader;</span> |
| } |
| |
| /** |
| * @param secHeader |
| * The secHeader to set. |
| */ |
| public void setSecHeader(WSSecHeader secHeader) { |
| <span class="nc" id="L521"> this.secHeader = secHeader;</span> |
| <span class="nc" id="L522"> }</span> |
| |
| /** |
| * @return Returns the issuedEncryptionTokenId. |
| */ |
| public String getIssuedEncryptionTokenId() { |
| <span class="fc" id="L528"> return issuedEncryptionTokenId;</span> |
| } |
| |
| /** |
| * @param issuedEncryptionTokenId The issuedEncryptionTokenId to set. |
| */ |
| public void setIssuedEncryptionTokenId(String issuedEncryptionTokenId) { |
| <span class="nc" id="L535"> this.issuedEncryptionTokenId = issuedEncryptionTokenId;</span> |
| <span class="nc" id="L536"> }</span> |
| |
| /** |
| * @return Returns the issuedSignatureTokenId. |
| */ |
| public String getIssuedSignatureTokenId() { |
| <span class="nc bnc" id="L542" title="All 2 branches missed."> if(this.isInitiator) {</span> |
| <span class="nc" id="L543"> 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="L548"> List<WSHandlerResult> results</span> |
| = (List<WSHandlerResult>)this.msgContext.getProperty(WSHandlerConstants.RECV_RESULTS); |
| <span class="nc bnc" id="L550" title="All 2 branches missed."> for (WSHandlerResult result : results) {</span> |
| <span class="nc" id="L551"> List<WSSecurityEngineResult> wsSecEngineResults = result.getResults();</span> |
| |
| <span class="nc bnc" id="L553" title="All 2 branches missed."> for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) {</span> |
| <span class="nc" id="L554"> final Integer actInt =</span> |
| (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); |
| <span class="nc bnc" id="L556" title="All 2 branches missed."> if (WSConstants.ST_UNSIGNED == actInt) {</span> |
| <span class="nc" id="L557"> final Object assertion =</span> |
| wsSecEngineResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION); |
| <span class="nc" id="L559"> SAMLAssertionHandler samlAssertionHandler</span> |
| = SAMLAssertionHandlerFactory.createAssertionHandler(assertion); |
| |
| <span class="nc" id="L562"> return samlAssertionHandler.getAssertionId();</span> |
| } |
| |
| <span class="nc" id="L565"> }</span> |
| <span class="nc" id="L566"> }</span> |
| <span class="nc" id="L567"> return null;</span> |
| } |
| } |
| |
| /** |
| * @param issuedSignatureTokenId The issuedSignatureTokenId to set. |
| */ |
| public void setIssuedSignatureTokenId(String issuedSignatureTokenId) { |
| <span class="nc" id="L575"> this.issuedSignatureTokenId = issuedSignatureTokenId;</span> |
| <span class="nc" id="L576"> }</span> |
| |
| /** |
| * @return Returns the secConvTokenId. |
| */ |
| public String getSecConvTokenId() { |
| <span class="fc" id="L582"> String id = null;</span> |
| |
| <span class="fc bfc" id="L584" title="All 2 branches covered."> if(this.isInitiator) {</span> |
| <span class="fc" id="L585"> String contextIdentifierKey = RampartUtil.getContextIdentifierKey(this.msgContext);</span> |
| <span class="fc" id="L586"> id = (String) RampartUtil.getContextMap(this.msgContext).get(contextIdentifierKey);</span> |
| <span class="fc" id="L587"> } else {</span> |
| //get the sec context id from the req msg ctx |
| <span class="fc" id="L589"> List<WSHandlerResult> results = (List<WSHandlerResult>)this.msgContext.getProperty(WSHandlerConstants.RECV_RESULTS);</span> |
| <span class="fc bfc" id="L590" title="All 2 branches covered."> for (WSHandlerResult result : results) {</span> |
| <span class="fc" id="L591"> List<WSSecurityEngineResult> wsSecEngineResults = result.getResults();</span> |
| |
| <span class="fc bfc" id="L593" title="All 2 branches covered."> for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) {</span> |
| <span class="fc" id="L594"> final Integer actInt =</span> |
| (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); |
| <span class="fc bfc" id="L596" title="All 2 branches covered."> if (WSConstants.SCT == actInt) {</span> |
| <span class="fc" id="L597"> final SecurityContextToken sct =</span> |
| ((SecurityContextToken) wsSecEngineResult |
| .get(WSSecurityEngineResult.TAG_SECURITY_CONTEXT_TOKEN)); |
| <span class="fc" id="L600"> id = sct.getID();</span> |
| } |
| |
| <span class="fc" id="L603"> }</span> |
| <span class="fc" id="L604"> }</span> |
| } |
| |
| <span class="pc bpc" id="L607" 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="L610"> id = (String)this.msgContext.getProperty(SCT_ID);</span> |
| } |
| |
| <span class="fc" id="L613"> return id;</span> |
| } |
| |
| /** |
| * @param secConvTokenId The secConvTokenId to set. |
| */ |
| public void setSecConvTokenId(String secConvTokenId) { |
| <span class="fc" id="L620"> String contextIdentifierKey = RampartUtil.getContextIdentifierKey(this.msgContext);</span> |
| <span class="fc" id="L621"> RampartUtil.getContextMap(this.msgContext).put(</span> |
| contextIdentifierKey, |
| secConvTokenId); |
| <span class="fc" id="L624"> }</span> |
| |
| |
| |
| /** |
| * @return Returns the tokenStorage. |
| */ |
| public TokenStorage getTokenStorage() throws RampartException { |
| |
| <span class="fc bfc" id="L633" title="All 2 branches covered."> if(this.tokenStorage != null) {</span> |
| <span class="fc" id="L634"> return this.tokenStorage;</span> |
| } |
| |
| <span class="fc" id="L637"> TokenStorage storage = (TokenStorage) this.msgContext.getConfigurationContext().getProperty(</span> |
| TokenStorage.TOKEN_STORAGE_KEY); |
| |
| <span class="fc bfc" id="L640" title="All 2 branches covered."> if (storage != null) {</span> |
| <span class="fc" id="L641"> this.tokenStorage = storage;</span> |
| } else { |
| <span class="pc bpc" id="L643" title="1 of 4 branches missed."> if (this.policyData.getRampartConfig() != null &&</span> |
| this.policyData.getRampartConfig().getTokenStoreClass() != null) { |
| <span class="nc" id="L645"> Class stClass = null;</span> |
| <span class="nc" id="L646"> String storageClass = this.policyData.getRampartConfig()</span> |
| .getTokenStoreClass(); |
| try { |
| <span class="nc" id="L649"> stClass = Loader.loadClass(this.customClassLoader, storageClass);</span> |
| <span class="nc" id="L650"> } catch (ClassNotFoundException e) {</span> |
| <span class="nc" id="L651"> throw new RampartException(</span> |
| "WSHandler: cannot load token storage class: " |
| + storageClass, e); |
| <span class="nc" id="L654"> }</span> |
| try { |
| <span class="nc" id="L656"> this.tokenStorage = (TokenStorage) stClass.newInstance();</span> |
| <span class="nc" id="L657"> } catch (java.lang.Exception e) {</span> |
| <span class="nc" id="L658"> throw new RampartException(</span> |
| "Cannot create instance of token storage: " |
| + storageClass, e); |
| <span class="nc" id="L661"> }</span> |
| <span class="nc" id="L662"> } else {</span> |
| <span class="fc" id="L663"> this.tokenStorage = new SimpleTokenStore();</span> |
| |
| } |
| |
| //Set the storage instance |
| <span class="fc" id="L668"> this.msgContext.getConfigurationContext().setProperty(</span> |
| TokenStorage.TOKEN_STORAGE_KEY, this.tokenStorage); |
| } |
| |
| |
| <span class="fc" id="L673"> return tokenStorage;</span> |
| } |
| |
| /** |
| * @param tokenStorage The tokenStorage to set. |
| */ |
| public void setTokenStorage(TokenStorage tokenStorage) { |
| <span class="nc" id="L680"> this.tokenStorage = tokenStorage;</span> |
| <span class="nc" id="L681"> }</span> |
| |
| /** |
| * @return Returns the wstVersion. |
| */ |
| public int getWstVersion() { |
| <span class="fc" id="L687"> return wstVersion;</span> |
| } |
| |
| /** |
| * @return Returns the secConvVersion. |
| */ |
| public int getSecConvVersion() { |
| <span class="fc" id="L694"> return secConvVersion;</span> |
| } |
| |
| /** |
| * @return Returns the servicePolicy. |
| */ |
| public Policy getServicePolicy() { |
| <span class="fc" id="L701"> return servicePolicy;</span> |
| } |
| |
| |
| /** |
| * @return Returns the timestampId. |
| */ |
| public String getTimestampId() { |
| <span class="fc" id="L709"> return timestampId;</span> |
| } |
| |
| /** |
| * @param timestampId The timestampId to set. |
| */ |
| public void setTimestampId(String timestampId) { |
| <span class="fc" id="L716"> this.timestampId = timestampId;</span> |
| <span class="fc" id="L717"> }</span> |
| |
| /** |
| * @return Returns the Initiator value |
| */ |
| public boolean isInitiator() { |
| <span class="fc" id="L723"> 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="L731"> 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="L740"> 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> |