Modified: axis/site/axis2/java/rampart-staging/code-coverage/org.apache.rampart/PolicyBasedResultsValidator.java.html URL: http://svn.apache.org/viewvc/axis/site/axis2/java/rampart-staging/code-coverage/org.apache.rampart/PolicyBasedResultsValidator.java.html?rev=1725383&r1=1725382&r2=1725383&view=diff ============================================================================== --- axis/site/axis2/java/rampart-staging/code-coverage/org.apache.rampart/PolicyBasedResultsValidator.java.html (original) +++ axis/site/axis2/java/rampart-staging/code-coverage/org.apache.rampart/PolicyBasedResultsValidator.java.html Mon Jan 18 23:07:55 2016 @@ -39,19 +39,18 @@ import org.jaxen.JaxenException; import javax.xml.namespace.QName; import java.math.BigInteger; -import java.security.KeyStore; import java.security.cert.X509Certificate; import java.util.*; -<span class="fc" id="L46">public class PolicyBasedResultsValidator implements ExtendedPolicyValidatorCallbackHandler {</span> +<span class="fc" id="L45">public class PolicyBasedResultsValidator implements ExtendedPolicyValidatorCallbackHandler {</span> -<span class="fc" id="L48"> private static Log log = LogFactory.getLog(PolicyBasedResultsValidator.class);</span> +<span class="fc" id="L47"> private static Log log = LogFactory.getLog(PolicyBasedResultsValidator.class);</span> public void validate(ValidatorData data, Vector results) throws RampartException { -<span class="nc" id="L52"> List<WSSecurityEngineResult> resultsList = new ArrayList<WSSecurityEngineResult>(results);</span> -<span class="nc" id="L53"> this.validate(data, resultsList);</span> -<span class="nc" id="L54"> }</span> +<span class="nc" id="L51"> List<WSSecurityEngineResult> resultsList = new ArrayList<WSSecurityEngineResult>(results);</span> +<span class="nc" id="L52"> this.validate(data, resultsList);</span> +<span class="nc" id="L53"> }</span> /** * {@inheritDoc} @@ -59,113 +58,113 @@ import java.util.*; public void validate(ValidatorData data, List<WSSecurityEngineResult> results) throws RampartException { -<span class="fc" id="L62"> RampartMessageData rmd = data.getRampartMessageData();</span> +<span class="fc" id="L61"> RampartMessageData rmd = data.getRampartMessageData();</span> -<span class="fc" id="L64"> RampartPolicyData rpd = rmd.getPolicyData();</span> +<span class="fc" id="L63"> RampartPolicyData rpd = rmd.getPolicyData();</span> //If there's Security policy present and no results //then we should throw an error -<span class="pc bpc" id="L68" title="2 of 4 branches missed."> if(rpd != null && results == null) {</span> -<span class="nc" id="L69"> throw new RampartException("noSecurityResults");</span> +<span class="pc bpc" id="L67" title="2 of 4 branches missed."> if(rpd != null && results == null) {</span> +<span class="nc" id="L68"> throw new RampartException("noSecurityResults");</span> } //Check presence of timestamp -<span class="fc" id="L73"> WSSecurityEngineResult tsResult = null;</span> -<span class="pc bpc" id="L74" title="1 of 4 branches missed."> if(rpd != null && rpd.isIncludeTimestamp()) {</span> -<span class="fc" id="L75"> tsResult = </span> +<span class="fc" id="L72"> WSSecurityEngineResult tsResult = null;</span> +<span class="pc bpc" id="L73" title="1 of 4 branches missed."> if(rpd != null && rpd.isIncludeTimestamp()) {</span> +<span class="fc" id="L74"> tsResult = </span> WSSecurityUtil.fetchActionResult(results, WSConstants.TS); -<span class="pc bpc" id="L77" title="3 of 4 branches missed."> if(tsResult == null && !rpd.isIncludeTimestampOptional()) {</span> -<span class="nc" id="L78"> throw new RampartException("timestampMissing");</span> +<span class="pc bpc" id="L76" title="3 of 4 branches missed."> if(tsResult == null && !rpd.isIncludeTimestampOptional()) {</span> +<span class="nc" id="L77"> throw new RampartException("timestampMissing");</span> } } //sig/encr -<span class="fc" id="L84"> List<WSEncryptionPart> encryptedParts = RampartUtil.getEncryptedParts(rmd);</span> -<span class="pc bpc" id="L85" title="2 of 6 branches missed."> if(rpd != null && rpd.isSignatureProtection() && isSignatureRequired(rmd)) {</span> +<span class="fc" id="L83"> List<WSEncryptionPart> encryptedParts = RampartUtil.getEncryptedParts(rmd);</span> +<span class="pc bpc" id="L84" title="2 of 6 branches missed."> if(rpd != null && rpd.isSignatureProtection() && isSignatureRequired(rmd)) {</span> -<span class="fc" id="L87"> String sigId = RampartUtil.getSigElementId(rmd);</span> +<span class="fc" id="L86"> String sigId = RampartUtil.getSigElementId(rmd);</span> -<span class="fc" id="L89"> encryptedParts.add(RampartUtil.createEncryptionPart(WSConstants.SIG_LN, sigId, WSConstants.SIG_NS,</span> +<span class="fc" id="L88"> encryptedParts.add(RampartUtil.createEncryptionPart(WSConstants.SIG_LN, sigId, WSConstants.SIG_NS,</span> RampartConstants.XML_ENCRYPTION_MODIFIER_ELEMENT)); } -<span class="fc" id="L93"> List<WSEncryptionPart> signatureParts = RampartUtil.getSignedParts(rmd);</span> +<span class="fc" id="L92"> List<WSEncryptionPart> signatureParts = RampartUtil.getSignedParts(rmd);</span> //Timestamp is not included in sig parts -<span class="pc bpc" id="L96" title="1 of 2 branches missed."> if (rpd != null) {</span> -<span class="pc bpc" id="L97" title="1 of 4 branches missed."> if (tsResult != null || !rpd.isIncludeTimestampOptional()) {</span> -<span class="fc bfc" id="L98" title="All 4 branches covered."> if (rpd.isIncludeTimestamp()</span> +<span class="pc bpc" id="L95" title="1 of 2 branches missed."> if (rpd != null) {</span> +<span class="pc bpc" id="L96" title="1 of 4 branches missed."> if (tsResult != null || !rpd.isIncludeTimestampOptional()) {</span> +<span class="fc bfc" id="L97" title="All 4 branches covered."> if (rpd.isIncludeTimestamp()</span> && !rpd.isTransportBinding()) { -<span class="fc" id="L100"> signatureParts.add(RampartUtil.createEncryptionPart(WSConstants.TIMESTAMP_TOKEN_LN, "timestamp"));</span> +<span class="fc" id="L99"> signatureParts.add(RampartUtil.createEncryptionPart(WSConstants.TIMESTAMP_TOKEN_LN, "timestamp"));</span> } } } -<span class="fc bfc" id="L105" title="All 2 branches covered."> if(!rmd.isInitiator()) {</span> +<span class="fc bfc" id="L104" title="All 2 branches covered."> if(!rmd.isInitiator()) {</span> //Just an indicator for EndorsingSupportingToken signature -<span class="fc" id="L108"> SupportingToken endSupportingToken = null;</span> -<span class="pc bpc" id="L109" title="1 of 2 branches missed."> if (rpd != null) {</span> -<span class="fc" id="L110"> endSupportingToken = rpd.getEndorsingSupportingTokens();</span> +<span class="fc" id="L107"> SupportingToken endSupportingToken = null;</span> +<span class="pc bpc" id="L108" title="1 of 2 branches missed."> if (rpd != null) {</span> +<span class="fc" id="L109"> endSupportingToken = rpd.getEndorsingSupportingTokens();</span> } -<span class="pc bpc" id="L113" title="1 of 4 branches missed."> if(endSupportingToken != null && !endSupportingToken.isOptional()) {</span> -<span class="fc" id="L114"> SignedEncryptedParts endSignedParts = endSupportingToken.getSignedParts();</span> -<span class="pc bpc" id="L115" title="8 of 10 branches missed."> if((endSignedParts != null && !endSignedParts.isOptional() &&</span> +<span class="pc bpc" id="L112" title="1 of 4 branches missed."> if(endSupportingToken != null && !endSupportingToken.isOptional()) {</span> +<span class="fc" id="L113"> SignedEncryptedParts endSignedParts = endSupportingToken.getSignedParts();</span> +<span class="pc bpc" id="L114" title="8 of 10 branches missed."> if((endSignedParts != null && !endSignedParts.isOptional() &&</span> (endSignedParts.isBody() || endSignedParts.getHeaders().size() > 0)) || rpd.isIncludeTimestamp()) { -<span class="fc" id="L120"> signatureParts.add(RampartUtil.createEncryptionPart("EndorsingSupportingTokens",</span> +<span class="fc" id="L119"> signatureParts.add(RampartUtil.createEncryptionPart("EndorsingSupportingTokens",</span> "EndorsingSupportingTokens")); } } //Just an indicator for SignedEndorsingSupportingToken signature -<span class="fc" id="L125"> SupportingToken sgndEndSupportingToken = null;</span> -<span class="pc bpc" id="L126" title="1 of 2 branches missed."> if (rpd != null) {</span> -<span class="fc" id="L127"> sgndEndSupportingToken = rpd.getSignedEndorsingSupportingTokens();</span> - } -<span class="pc bpc" id="L129" title="3 of 4 branches missed."> if(sgndEndSupportingToken != null && !sgndEndSupportingToken.isOptional()) {</span> -<span class="nc" id="L130"> SignedEncryptedParts sgndEndSignedParts = sgndEndSupportingToken.getSignedParts();</span> -<span class="nc bnc" id="L131" title="All 10 branches missed."> if((sgndEndSignedParts != null && !sgndEndSignedParts.isOptional() &&</span> +<span class="fc" id="L124"> SupportingToken sgndEndSupportingToken = null;</span> +<span class="pc bpc" id="L125" title="1 of 2 branches missed."> if (rpd != null) {</span> +<span class="fc" id="L126"> sgndEndSupportingToken = rpd.getSignedEndorsingSupportingTokens();</span> + } +<span class="pc bpc" id="L128" title="3 of 4 branches missed."> if(sgndEndSupportingToken != null && !sgndEndSupportingToken.isOptional()) {</span> +<span class="nc" id="L129"> SignedEncryptedParts sgndEndSignedParts = sgndEndSupportingToken.getSignedParts();</span> +<span class="nc bnc" id="L130" title="All 10 branches missed."> if((sgndEndSignedParts != null && !sgndEndSignedParts.isOptional() &&</span> (sgndEndSignedParts.isBody() || sgndEndSignedParts.getHeaders().size() > 0)) || rpd.isIncludeTimestamp()) { -<span class="nc" id="L136"> signatureParts.add(RampartUtil.createEncryptionPart("SignedEndorsingSupportingTokens",</span> +<span class="nc" id="L135"> signatureParts.add(RampartUtil.createEncryptionPart("SignedEndorsingSupportingTokens",</span> "SignedEndorsingSupportingTokens")); } } -<span class="pc bpc" id="L141" title="1 of 2 branches missed."> if (rpd != null) {</span> -<span class="fc" id="L142"> List<SupportingToken> supportingToks = rpd.getSupportingTokensList();</span> -<span class="fc bfc" id="L143" title="All 2 branches covered."> for (SupportingToken supportingToken : supportingToks) {</span> -<span class="pc bpc" id="L144" title="2 of 4 branches missed."> if (supportingToken != null && !supportingToken.isOptional()) {</span> -<span class="fc" id="L145"> SupportingPolicyData policyData = new SupportingPolicyData();</span> -<span class="fc" id="L146"> policyData.build(supportingToken);</span> -<span class="fc" id="L147"> encryptedParts.addAll(RampartUtil.getSupportingEncryptedParts(rmd, policyData));</span> -<span class="fc" id="L148"> signatureParts.addAll(RampartUtil.getSupportingSignedParts(rmd, policyData));</span> +<span class="pc bpc" id="L140" title="1 of 2 branches missed."> if (rpd != null) {</span> +<span class="fc" id="L141"> List<SupportingToken> supportingToks = rpd.getSupportingTokensList();</span> +<span class="fc bfc" id="L142" title="All 2 branches covered."> for (SupportingToken supportingToken : supportingToks) {</span> +<span class="pc bpc" id="L143" title="2 of 4 branches missed."> if (supportingToken != null && !supportingToken.isOptional()) {</span> +<span class="fc" id="L144"> SupportingPolicyData policyData = new SupportingPolicyData();</span> +<span class="fc" id="L145"> policyData.build(supportingToken);</span> +<span class="fc" id="L146"> encryptedParts.addAll(RampartUtil.getSupportingEncryptedParts(rmd, policyData));</span> +<span class="fc" id="L147"> signatureParts.addAll(RampartUtil.getSupportingSignedParts(rmd, policyData));</span> } -<span class="fc" id="L150"> }</span> +<span class="fc" id="L149"> }</span> } } -<span class="fc" id="L154"> validateEncrSig(data,encryptedParts, signatureParts, results);</span> +<span class="fc" id="L153"> validateEncrSig(data,encryptedParts, signatureParts, results);</span> -<span class="pc bpc" id="L156" title="1 of 4 branches missed."> if(rpd != null && !rpd.isTransportBinding()) {</span> -<span class="fc" id="L157"> validateProtectionOrder(data, results);</span> +<span class="pc bpc" id="L155" title="1 of 4 branches missed."> if(rpd != null && !rpd.isTransportBinding()) {</span> +<span class="fc" id="L156"> validateProtectionOrder(data, results);</span> } -<span class="fc" id="L160"> validateEncryptedParts(data, encryptedParts, results);</span> +<span class="fc" id="L159"> validateEncryptedParts(data, encryptedParts, results);</span> -<span class="fc" id="L162"> validateSignedPartsHeaders(data, signatureParts, results);</span> +<span class="fc" id="L161"> validateSignedPartsHeaders(data, signatureParts, results);</span> -<span class="fc" id="L164"> validateRequiredElements(data);</span> +<span class="fc" id="L163"> validateRequiredElements(data);</span> //Supporting tokens -<span class="fc bfc" id="L167" title="All 2 branches covered."> if(!rmd.isInitiator()) {</span> -<span class="fc" id="L168"> validateSupportingTokens(data, results);</span> +<span class="fc bfc" id="L166" title="All 2 branches covered."> if(!rmd.isInitiator()) {</span> +<span class="fc" id="L167"> validateSupportingTokens(data, results);</span> } /* @@ -178,16 +177,16 @@ import java.util.*; */ // Extract the signature action result from the action vector -<span class="fc" id="L181"> WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(</span> +<span class="fc" id="L180"> WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(</span> results, WSConstants.SIGN); -<span class="fc bfc" id="L184" title="All 2 branches covered."> if (actionResult != null) {</span> -<span class="fc" id="L185"> X509Certificate returnCert = (X509Certificate) actionResult</span> +<span class="fc bfc" id="L183" title="All 2 branches covered."> if (actionResult != null) {</span> +<span class="fc" id="L184"> X509Certificate returnCert = (X509Certificate) actionResult</span> .get(WSSecurityEngineResult.TAG_X509_CERTIFICATE); -<span class="fc bfc" id="L188" title="All 2 branches covered."> if (returnCert != null) {</span> -<span class="pc bpc" id="L189" title="1 of 2 branches missed."> if (!verifyTrust(returnCert, rmd)) {</span> -<span class="nc" id="L190"> throw new RampartException ("trustVerificationError");</span> +<span class="fc bfc" id="L187" title="All 2 branches covered."> if (returnCert != null) {</span> +<span class="pc bpc" id="L188" title="1 of 2 branches missed."> if (!verifyTrust(returnCert, rmd)) {</span> +<span class="nc" id="L189"> throw new RampartException ("trustVerificationError");</span> } } } @@ -196,8 +195,9 @@ import java.util.*; * Perform further checks on the timestamp that was transmitted in the * header. * In the following implementation the timestamp is valid if : - * Timestamp->Created < 'now' < Timestamp->Expires (Last test already handled by WSS4J) - * + * Timestamp->Created < 'now' < Timestamp->Expires. + * (Last test handled by WSS4J also if timeStampStrict enabled) + * * Note: the method verifyTimestamp(Timestamp) allows custom * implementations with other validation algorithms for subclasses. */ @@ -261,12 +261,12 @@ import java.util.*; <span class="fc" id="L261"> boolean encrDataFound = false;</span> <span class="fc bfc" id="L262" title="All 2 branches covered."> for (WSSecurityEngineResult result : list) {</span> <span class="fc" id="L263"> ArrayList dataRefURIs = (ArrayList) result.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);</span> -<span class="pc bpc" id="L264" title="1 of 4 branches missed."> if (dataRefURIs != null && dataRefURIs.size() != 0) {</span> -<span class="fc" id="L265"> encrDataFound = true;</span> +<span class="pc bpc" id="L264" title="3 of 4 branches missed."> if (dataRefURIs != null && dataRefURIs.size() != 0) {</span> +<span class="nc" id="L265"> encrDataFound = true;</span> } <span class="fc" id="L267"> }</span> //TODO check whether the encrptedDataFound is an UsernameToken -<span class="pc bpc" id="L269" title="1 of 4 branches missed."> if(encrDataFound && !isUsernameTokenPresent(data)) {</span> +<span class="pc bpc" id="L269" title="3 of 4 branches missed."> if(encrDataFound && !isUsernameTokenPresent(data)) {</span> //Unexpected encryption <span class="nc" id="L271"> throw new RampartException("unexprectedEncryptedPart");</span> } @@ -316,29 +316,46 @@ import java.util.*; <span class="fc" id="L316"> UsernameToken ut = (UsernameToken) token;</span> //Check presence of a UsernameToken <span class="fc" id="L318"> WSSecurityEngineResult utResult = WSSecurityUtil.fetchActionResult(results, WSConstants.UT);</span> -<span class="pc bpc" id="L319" title="3 of 4 branches missed."> if (utResult == null && !ut.isOptional()) {</span> -<span class="nc" id="L320"> throw new RampartException("usernameTokenMissing");</span> + +<span class="pc bpc" id="L320" title="3 of 4 branches missed."> if (utResult == null && !ut.isOptional()) {</span> +<span class="nc" id="L321"> throw new RampartException("usernameTokenMissing");</span> + } + +<span class="fc" id="L324"> org.apache.ws.security.message.token.UsernameToken wssUt = </span> + (org.apache.ws.security.message.token.UsernameToken) utResult.get(WSSecurityEngineResult.TAG_USERNAME_TOKEN); + +<span class="pc bpc" id="L327" title="3 of 4 branches missed."> if(ut.isNoPassword() && wssUt.getPassword() != null) {</span> +<span class="nc" id="L328"> throw new RampartException("invalidUsernameTokenType");</span> + } + +<span class="fc bfc" id="L331" title="All 4 branches covered."> if(ut.isHashPassword() && !wssUt.isHashed()) {</span> +<span class="fc" id="L332"> throw new RampartException("invalidUsernameTokenType");</span> +<span class="pc bpc" id="L333" title="2 of 6 branches missed."> } else if (!ut.isHashPassword() && (wssUt.getPassword() == null ||</span> + !wssUt.getPasswordType().equals(WSConstants.PASSWORD_TEXT))) { +<span class="nc" id="L335"> throw new RampartException("invalidUsernameTokenType");</span> } + + -<span class="fc bfc" id="L323" title="All 2 branches covered."> } else if (token instanceof IssuedToken) {</span> -<span class="fc" id="L324"> WSSecurityEngineResult samlResult = WSSecurityUtil.fetchActionResult(results, WSConstants.ST_SIGNED);</span> +<span class="fc bfc" id="L340" title="All 2 branches covered."> } else if (token instanceof IssuedToken) {</span> +<span class="fc" id="L341"> WSSecurityEngineResult samlResult = WSSecurityUtil.fetchActionResult(results, WSConstants.ST_SIGNED);</span> // Then check for unsigned saml tokens -<span class="pc bpc" id="L326" title="1 of 2 branches missed."> if (samlResult == null) {</span> -<span class="nc" id="L327"> log.debug("No signed SAMLToken found. Looking for unsigned SAMLTokens");</span> -<span class="nc" id="L328"> samlResult = WSSecurityUtil.fetchActionResult(results, WSConstants.ST_UNSIGNED);</span> - } -<span class="pc bpc" id="L330" title="1 of 2 branches missed."> if (samlResult == null) {</span> -<span class="nc" id="L331"> throw new RampartException("samlTokenMissing");</span> - } -<span class="pc bpc" id="L333" title="1 of 2 branches missed."> } else if (token instanceof X509Token) {</span> -<span class="fc" id="L334"> X509Token x509Token = (X509Token) token;</span> -<span class="fc" id="L335"> WSSecurityEngineResult x509Result = WSSecurityUtil.fetchActionResult(results, WSConstants.BST);</span> -<span class="pc bpc" id="L336" title="3 of 4 branches missed."> if (x509Result == null && !x509Token.isOptional()) {</span> -<span class="nc" id="L337"> throw new RampartException("binaryTokenMissing");</span> +<span class="pc bpc" id="L343" title="1 of 2 branches missed."> if (samlResult == null) {</span> +<span class="nc" id="L344"> log.debug("No signed SAMLToken found. Looking for unsigned SAMLTokens");</span> +<span class="nc" id="L345"> samlResult = WSSecurityUtil.fetchActionResult(results, WSConstants.ST_UNSIGNED);</span> + } +<span class="pc bpc" id="L347" title="1 of 2 branches missed."> if (samlResult == null) {</span> +<span class="nc" id="L348"> throw new RampartException("samlTokenMissing");</span> + } +<span class="pc bpc" id="L350" title="1 of 2 branches missed."> } else if (token instanceof X509Token) {</span> +<span class="fc" id="L351"> X509Token x509Token = (X509Token) token;</span> +<span class="fc" id="L352"> WSSecurityEngineResult x509Result = WSSecurityUtil.fetchActionResult(results, WSConstants.BST);</span> +<span class="pc bpc" id="L353" title="3 of 4 branches missed."> if (x509Result == null && !x509Token.isOptional()) {</span> +<span class="nc" id="L354"> throw new RampartException("binaryTokenMissing");</span> } } -<span class="fc" id="L340"> }</span> -<span class="fc" id="L341"> }</span> +<span class="fc" id="L357"> }</span> +<span class="fc" id="L358"> }</span> @@ -350,334 +367,352 @@ import java.util.*; protected void validateProtectionOrder(ValidatorData data, List<WSSecurityEngineResult> results) throws RampartException { -<span class="fc" id="L353"> String protectionOrder = data.getRampartMessageData().getPolicyData().getProtectionOrder();</span> -<span class="fc" id="L354"> List<Integer> sigEncrActions = this.getSigEncrActions(results);</span> +<span class="fc" id="L370"> String protectionOrder = data.getRampartMessageData().getPolicyData().getProtectionOrder();</span> +<span class="fc" id="L371"> List<Integer> sigEncrActions = this.getSigEncrActions(results);</span> -<span class="fc bfc" id="L356" title="All 2 branches covered."> if(sigEncrActions.size() < 2) {</span> +<span class="fc bfc" id="L373" title="All 2 branches covered."> if(sigEncrActions.size() < 2) {</span> //There are no results to COMPARE -<span class="fc" id="L358"> return;</span> +<span class="fc" id="L375"> return;</span> } -<span class="fc" id="L361"> boolean sigNotPresent = true; </span> -<span class="fc" id="L362"> boolean encrNotPresent = true;</span> +<span class="fc" id="L378"> boolean sigNotPresent = true; </span> +<span class="fc" id="L379"> boolean encrNotPresent = true;</span> -<span class="fc bfc" id="L364" title="All 2 branches covered."> for (Object sigEncrAction : sigEncrActions) {</span> -<span class="fc" id="L365"> Integer act = (Integer) sigEncrAction;</span> -<span class="fc bfc" id="L366" title="All 2 branches covered."> if (act == WSConstants.SIGN) {</span> -<span class="fc" id="L367"> sigNotPresent = false;</span> -<span class="pc bpc" id="L368" title="1 of 2 branches missed."> } else if (act == WSConstants.ENCR) {</span> -<span class="fc" id="L369"> encrNotPresent = false;</span> +<span class="fc bfc" id="L381" title="All 2 branches covered."> for (Object sigEncrAction : sigEncrActions) {</span> +<span class="fc" id="L382"> Integer act = (Integer) sigEncrAction;</span> +<span class="fc bfc" id="L383" title="All 2 branches covered."> if (act == WSConstants.SIGN) {</span> +<span class="fc" id="L384"> sigNotPresent = false;</span> +<span class="pc bpc" id="L385" title="1 of 2 branches missed."> } else if (act == WSConstants.ENCR) {</span> +<span class="fc" id="L386"> encrNotPresent = false;</span> } -<span class="fc" id="L371"> }</span> +<span class="fc" id="L388"> }</span> // Only one action is present, so there is no order to check -<span class="pc bpc" id="L374" title="1 of 4 branches missed."> if ( sigNotPresent || encrNotPresent ) {</span> -<span class="fc" id="L375"> return;</span> +<span class="pc bpc" id="L391" title="1 of 4 branches missed."> if ( sigNotPresent || encrNotPresent ) {</span> +<span class="fc" id="L392"> return;</span> } -<span class="fc" id="L379"> boolean done = false;</span> -<span class="fc bfc" id="L380" title="All 2 branches covered."> if(SPConstants.SIGN_BEFORE_ENCRYPTING.equals(protectionOrder)) {</span> +<span class="fc" id="L396"> boolean done = false;</span> +<span class="fc bfc" id="L397" title="All 2 branches covered."> if(SPConstants.SIGN_BEFORE_ENCRYPTING.equals(protectionOrder)) {</span> -<span class="fc" id="L382"> boolean sigFound = false;</span> -<span class="fc" id="L383"> for (Iterator iter = sigEncrActions.iterator(); </span> -<span class="pc bpc" id="L384" title="1 of 4 branches missed."> iter.hasNext() || !done;) {</span> -<span class="fc" id="L385"> Integer act = (Integer) iter.next();</span> -<span class="pc bpc" id="L386" title="1 of 4 branches missed."> if(act == WSConstants.ENCR && ! sigFound ) {</span> +<span class="fc" id="L399"> boolean sigFound = false;</span> +<span class="fc" id="L400"> for (Iterator iter = sigEncrActions.iterator(); </span> +<span class="pc bpc" id="L401" title="1 of 4 branches missed."> iter.hasNext() || !done;) {</span> +<span class="fc" id="L402"> Integer act = (Integer) iter.next();</span> +<span class="pc bpc" id="L403" title="1 of 4 branches missed."> if(act == WSConstants.ENCR && ! sigFound ) {</span> // We found ENCR and SIGN has not been found - break and fail -<span class="nc" id="L388"> break;</span> +<span class="nc" id="L405"> break;</span> } -<span class="fc bfc" id="L390" title="All 2 branches covered."> if(act == WSConstants.SIGN) {</span> -<span class="fc" id="L391"> sigFound = true;</span> -<span class="pc bpc" id="L392" title="1 of 2 branches missed."> } else if(sigFound) {</span> +<span class="fc bfc" id="L407" title="All 2 branches covered."> if(act == WSConstants.SIGN) {</span> +<span class="fc" id="L408"> sigFound = true;</span> +<span class="pc bpc" id="L409" title="1 of 2 branches missed."> } else if(sigFound) {</span> //We have an ENCR action after sig -<span class="fc" id="L394"> done = true;</span> +<span class="fc" id="L411"> done = true;</span> } -<span class="fc" id="L396"> }</span> +<span class="fc" id="L413"> }</span> -<span class="fc" id="L398"> } else {</span> -<span class="fc" id="L399"> boolean encrFound = false;</span> -<span class="fc bfc" id="L400" title="All 2 branches covered."> for (Object sigEncrAction : sigEncrActions) {</span> -<span class="fc" id="L401"> Integer act = (Integer) sigEncrAction;</span> -<span class="pc bpc" id="L402" title="1 of 4 branches missed."> if (act == WSConstants.SIGN && !encrFound) {</span> +<span class="fc" id="L415"> } else {</span> +<span class="fc" id="L416"> boolean encrFound = false;</span> +<span class="fc bfc" id="L417" title="All 2 branches covered."> for (Object sigEncrAction : sigEncrActions) {</span> +<span class="fc" id="L418"> Integer act = (Integer) sigEncrAction;</span> +<span class="pc bpc" id="L419" title="1 of 4 branches missed."> if (act == WSConstants.SIGN && !encrFound) {</span> // We found SIGN and ENCR has not been found - break and fail -<span class="nc" id="L404"> break;</span> +<span class="nc" id="L421"> break;</span> } -<span class="fc bfc" id="L406" title="All 2 branches covered."> if (act == WSConstants.ENCR) {</span> -<span class="fc" id="L407"> encrFound = true;</span> -<span class="pc bpc" id="L408" title="1 of 2 branches missed."> } else if (encrFound) {</span> +<span class="fc bfc" id="L423" title="All 2 branches covered."> if (act == WSConstants.ENCR) {</span> +<span class="fc" id="L424"> encrFound = true;</span> +<span class="pc bpc" id="L425" title="1 of 2 branches missed."> } else if (encrFound) {</span> //We have an ENCR action after sig -<span class="fc" id="L410"> done = true;</span> +<span class="fc" id="L427"> done = true;</span> } -<span class="fc" id="L412"> }</span> +<span class="fc" id="L429"> }</span> } -<span class="pc bpc" id="L415" title="1 of 2 branches missed."> if(!done) {</span> -<span class="nc" id="L416"> throw new RampartException("protectionOrderMismatch");</span> +<span class="pc bpc" id="L432" title="1 of 2 branches missed."> if(!done) {</span> +<span class="nc" id="L433"> throw new RampartException("protectionOrderMismatch");</span> } -<span class="fc" id="L418"> }</span> +<span class="fc" id="L435"> }</span> protected List<Integer> getSigEncrActions(List<WSSecurityEngineResult> results) { -<span class="fc" id="L422"> List<Integer> sigEncrActions = new ArrayList<Integer>();</span> -<span class="fc bfc" id="L423" title="All 2 branches covered."> for (WSSecurityEngineResult result : results) {</span> -<span class="fc" id="L424"> Integer action = (Integer) (result)</span> +<span class="fc" id="L439"> List<Integer> sigEncrActions = new ArrayList<Integer>();</span> +<span class="fc bfc" id="L440" title="All 2 branches covered."> for (WSSecurityEngineResult result : results) {</span> +<span class="fc" id="L441"> Integer action = (Integer) (result)</span> .get(WSSecurityEngineResult.TAG_ACTION); -<span class="fc bfc" id="L427" title="All 4 branches covered."> if (WSConstants.SIGN == action || WSConstants.ENCR == action) {</span> -<span class="fc" id="L428"> sigEncrActions.add(action);</span> +<span class="fc bfc" id="L444" title="All 4 branches covered."> if (WSConstants.SIGN == action || WSConstants.ENCR == action) {</span> +<span class="fc" id="L445"> sigEncrActions.add(action);</span> } -<span class="fc" id="L431"> }</span> -<span class="fc" id="L432"> return sigEncrActions;</span> +<span class="fc" id="L448"> }</span> +<span class="fc" id="L449"> return sigEncrActions;</span> } protected void validateEncryptedParts(ValidatorData data, List<WSEncryptionPart> encryptedParts, List<WSSecurityEngineResult> results) throws RampartException { -<span class="fc" id="L439"> RampartMessageData rmd = data.getRampartMessageData();</span> +<span class="fc" id="L456"> RampartMessageData rmd = data.getRampartMessageData();</span> -<span class="fc" id="L441"> ArrayList encrRefs = getEncryptedReferences(results);</span> +<span class="fc" id="L458"> ArrayList encrRefs = getEncryptedReferences(results);</span> -<span class="fc" id="L443"> RampartPolicyData rpd = rmd.getPolicyData();</span> +<span class="fc" id="L460"> RampartPolicyData rpd = rmd.getPolicyData();</span> // build the list of encrypted nodes based on the dataRefs xpath expressions -<span class="fc" id="L446"> SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();</span> -<span class="fc" id="L447"> Set namespaces = RampartUtil.findAllPrefixNamespaces(envelope,</span> +<span class="fc" id="L463"> SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();</span> +<span class="fc" id="L464"> Set namespaces = RampartUtil.findAllPrefixNamespaces(envelope,</span> rpd.getDeclaredNamespaces()); -<span class="fc" id="L450"> Map decryptedElements = new HashMap();</span> -<span class="fc bfc" id="L451" title="All 2 branches covered."> for (Object encrRef : encrRefs) {</span> -<span class="fc" id="L452"> WSDataRef dataRef = (WSDataRef) encrRef;</span> +<span class="fc" id="L467"> Map decryptedElements = new HashMap();</span> +<span class="fc bfc" id="L468" title="All 2 branches covered."> for (Object encrRef : encrRefs) {</span> +<span class="fc" id="L469"> WSDataRef dataRef = (WSDataRef) encrRef;</span> -<span class="pc bpc" id="L454" title="2 of 4 branches missed."> if (dataRef == null || dataRef.getXpath() == null) {</span> -<span class="nc" id="L455"> continue;</span> +<span class="pc bpc" id="L471" title="2 of 4 branches missed."> if (dataRef == null || dataRef.getXpath() == null) {</span> +<span class="nc" id="L472"> continue;</span> } try { -<span class="fc" id="L459"> XPath xp = new AXIOMXPath(dataRef.getXpath());</span> +<span class="fc" id="L476"> XPath xp = new AXIOMXPath(dataRef.getXpath());</span> -<span class="fc bfc" id="L461" title="All 2 branches covered."> for (Object namespaceObject : namespaces) {</span> -<span class="fc" id="L462"> OMNamespace tmpNs = (OMNamespace) namespaceObject;</span> -<span class="fc" id="L463"> xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());</span> -<span class="fc" id="L464"> }</span> +<span class="fc bfc" id="L478" title="All 2 branches covered."> for (Object namespaceObject : namespaces) {</span> +<span class="fc" id="L479"> OMNamespace tmpNs = (OMNamespace) namespaceObject;</span> +<span class="fc" id="L480"> xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());</span> +<span class="fc" id="L481"> }</span> -<span class="fc bfc" id="L466" title="All 2 branches covered."> for (Object o : xp.selectNodes(envelope)) {</span> -<span class="fc" id="L467"> decryptedElements.put(o, dataRef.isContent());</span> -<span class="fc" id="L468"> }</span> +<span class="fc bfc" id="L483" title="All 2 branches covered."> for (Object o : xp.selectNodes(envelope)) {</span> +<span class="fc" id="L484"> decryptedElements.put(o, dataRef.isContent());</span> +<span class="fc" id="L485"> }</span> -<span class="nc" id="L471"> } catch (JaxenException e) {</span> +<span class="nc" id="L488"> } catch (JaxenException e) {</span> // This has to be changed to propagate an instance of a RampartException up -<span class="nc" id="L473"> throw new RampartException("An error occurred while searching for decrypted elements.", e);</span> -<span class="fc" id="L474"> }</span> +<span class="nc" id="L490"> throw new RampartException("An error occurred while searching for decrypted elements.", e);</span> +<span class="fc" id="L491"> }</span> -<span class="fc" id="L476"> }</span> +<span class="fc" id="L493"> }</span> //Check for encrypted body -<span class="pc bpc" id="L479" title="1 of 4 branches missed."> if(rpd.isEncryptBody()&& !rpd.isEncryptBodyOptional()) {</span> +<span class="pc bpc" id="L496" title="1 of 4 branches missed."> if(rpd.isEncryptBody()&& !rpd.isEncryptBodyOptional()) {</span> -<span class="pc bpc" id="L481" title="1 of 2 branches missed."> if( !isRefIdPresent(encrRefs, data.getBodyEncrDataId())){</span> -<span class="nc" id="L482"> throw new RampartException("encryptedPartMissing", </span> +<span class="pc bpc" id="L498" title="1 of 2 branches missed."> if( !isRefIdPresent(encrRefs, data.getBodyEncrDataId())){</span> +<span class="nc" id="L499"> throw new RampartException("encryptedPartMissing", </span> new String[]{data.getBodyEncrDataId()}); } } -<span class="fc bfc" id="L487" title="All 2 branches covered."> for (WSEncryptionPart encryptedPart : encryptedParts) {</span> +<span class="fc bfc" id="L504" title="All 2 branches covered."> for (WSEncryptionPart encryptedPart : encryptedParts) {</span> //This is the encrypted Body and we already checked encrypted body -<span class="fc bfc" id="L490" title="All 2 branches covered."> if (encryptedPart.getName().equals(WSConstants.ELEM_BODY)) {</span> -<span class="fc" id="L491"> continue;</span> +<span class="fc bfc" id="L507" title="All 2 branches covered."> if (encryptedPart.getName().equals(WSConstants.ELEM_BODY)) {</span> +<span class="fc" id="L508"> continue;</span> } -<span class="pc bpc" id="L494" title="1 of 6 branches missed."> if ((WSConstants.SIG_LN.equals(encryptedPart.getName()) &&</span> +<span class="pc bpc" id="L511" title="1 of 6 branches missed."> if ((WSConstants.SIG_LN.equals(encryptedPart.getName()) &&</span> WSConstants.SIG_NS.equals(encryptedPart.getNamespace())) || encryptedPart.getEncModifier().equals(WSConstants.ELEM_HEADER)) { -<span class="pc bpc" id="L497" title="1 of 2 branches missed."> if (!isRefIdPresent(encrRefs, new QName(encryptedPart.getNamespace(), encryptedPart.getName()))) {</span> -<span class="nc" id="L498"> throw new RampartException("encryptedPartMissing",</span> +<span class="pc bpc" id="L514" title="1 of 2 branches missed."> if (!isRefIdPresent(encrRefs, new QName(encryptedPart.getNamespace(), encryptedPart.getName()))) {</span> +<span class="nc" id="L515"> throw new RampartException("encryptedPartMissing",</span> new String[]{encryptedPart.getNamespace() + ":" + encryptedPart.getName()}); } continue; } // it is not a header or body part... verify encrypted xpath elements -<span class="fc" id="L505"> String xpath = encryptedPart.getXpath();</span> -<span class="fc" id="L506"> boolean found = false;</span> +<span class="fc" id="L522"> String xpath = encryptedPart.getXpath();</span> +<span class="fc" id="L523"> boolean found = false;</span> try { -<span class="fc" id="L508"> XPath xp = new AXIOMXPath(xpath);</span> +<span class="fc" id="L525"> XPath xp = new AXIOMXPath(xpath);</span> -<span class="fc bfc" id="L510" title="All 2 branches covered."> for (Object namespaceObject : namespaces) {</span> -<span class="fc" id="L511"> OMNamespace tmpNs = (OMNamespace) namespaceObject;</span> -<span class="fc" id="L512"> xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());</span> -<span class="fc" id="L513"> }</span> - -<span class="pc bpc" id="L515" title="1 of 2 branches missed."> for (Object o : xp.selectNodes(envelope)) {</span> -<span class="fc" id="L516"> Object result = decryptedElements.get(o);</span> -<span class="pc bpc" id="L517" title="2 of 4 branches missed."> if (result != null &&</span> +<span class="fc bfc" id="L527" title="All 2 branches covered."> for (Object namespaceObject : namespaces) {</span> +<span class="fc" id="L528"> OMNamespace tmpNs = (OMNamespace) namespaceObject;</span> +<span class="fc" id="L529"> xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());</span> +<span class="fc" id="L530"> }</span> + +<span class="pc bpc" id="L532" title="1 of 2 branches missed."> for (Object o : xp.selectNodes(envelope)) {</span> +<span class="fc" id="L533"> Object result = decryptedElements.get(o);</span> +<span class="pc bpc" id="L534" title="2 of 4 branches missed."> if (result != null &&</span> ("Element".equals(encryptedPart.getEncModifier()) ^ (Boolean) result)) { -<span class="fc" id="L520"> found = true;</span> -<span class="fc" id="L521"> break;</span> +<span class="fc" id="L537"> found = true;</span> +<span class="fc" id="L538"> break;</span> } -<span class="nc" id="L523"> }</span> +<span class="nc" id="L540"> }</span> -<span class="pc bpc" id="L525" title="1 of 2 branches missed."> if (!found) {</span> -<span class="nc" id="L526"> throw new RampartException("encryptedPartMissing",</span> +<span class="pc bpc" id="L542" title="1 of 2 branches missed."> if (!found) {</span> +<span class="nc" id="L543"> throw new RampartException("encryptedPartMissing",</span> new String[]{xpath}); } -<span class="nc" id="L531"> } catch (JaxenException e) {</span> +<span class="nc" id="L548"> } catch (JaxenException e) {</span> // This has to be changed to propagate an instance of a RampartException up -<span class="nc" id="L533"> throw new RampartException("An error occurred while searching for decrypted elements.", e);</span> -<span class="fc" id="L534"> }</span> +<span class="nc" id="L550"> throw new RampartException("An error occurred while searching for decrypted elements.", e);</span> +<span class="fc" id="L551"> }</span> -<span class="fc" id="L536"> }</span> +<span class="fc" id="L553"> }</span> -<span class="fc" id="L538"> }</span> +<span class="fc" id="L555"> }</span> public void validateRequiredElements(ValidatorData data) throws RampartException { -<span class="fc" id="L542"> RampartMessageData rmd = data.getRampartMessageData();</span> +<span class="fc" id="L559"> RampartMessageData rmd = data.getRampartMessageData();</span> -<span class="fc" id="L544"> RampartPolicyData rpd = rmd.getPolicyData();</span> +<span class="fc" id="L561"> RampartPolicyData rpd = rmd.getPolicyData();</span> -<span class="fc" id="L546"> SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();</span> +<span class="fc" id="L563"> SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();</span> -<span class="fc bfc" id="L548" title="All 2 branches covered."> for (String expression : rpd.getRequiredElements()) {</span> +<span class="fc bfc" id="L565" title="All 2 branches covered."> for (String expression : rpd.getRequiredElements()) {</span> -<span class="fc bfc" id="L550" title="All 2 branches covered."> if (!RampartUtil.checkRequiredElements(envelope, rpd.getDeclaredNamespaces(), expression)) {</span> -<span class="fc" id="L551"> throw new RampartException("requiredElementsMissing", new String[]{expression});</span> +<span class="fc bfc" id="L567" title="All 2 branches covered."> if (!RampartUtil.checkRequiredElements(envelope, rpd.getDeclaredNamespaces(), expression)) {</span> +<span class="fc" id="L568"> throw new RampartException("requiredElementsMissing", new String[]{expression});</span> } -<span class="fc" id="L553"> }</span> +<span class="fc" id="L570"> }</span> -<span class="fc" id="L555"> }</span> +<span class="fc" id="L572"> }</span> protected void validateSignedPartsHeaders(ValidatorData data, List<WSEncryptionPart> signatureParts, List<WSSecurityEngineResult> results) throws RampartException { -<span class="fc" id="L561"> RampartMessageData rmd = data.getRampartMessageData();</span> +<span class="fc" id="L578"> RampartMessageData rmd = data.getRampartMessageData();</span> -<span class="fc" id="L563"> Node envelope = rmd.getDocument().getFirstChild();</span> +<span class="fc" id="L580"> Node envelope = rmd.getDocument().getFirstChild();</span> -<span class="fc" id="L565"> WSSecurityEngineResult[] actionResults = fetchActionResults(results, WSConstants.SIGN);</span> +<span class="fc" id="L582"> WSSecurityEngineResult[] actionResults = fetchActionResults(results, WSConstants.SIGN);</span> // Find elements that are signed -<span class="fc" id="L568"> List<QName> actuallySigned = new ArrayList<QName>();</span> -<span class="pc bpc" id="L569" title="1 of 2 branches missed."> if (actionResults != null) {</span> -<span class="fc bfc" id="L570" title="All 2 branches covered."> for (WSSecurityEngineResult actionResult : actionResults) {</span> +<span class="fc" id="L585"> List<QName> actuallySigned = new ArrayList<QName>();</span> +<span class="pc bpc" id="L586" title="1 of 2 branches missed."> if (actionResults != null) {</span> +<span class="fc bfc" id="L587" title="All 2 branches covered."> for (WSSecurityEngineResult actionResult : actionResults) {</span> -<span class="fc" id="L572"> List wsDataRefs = (List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);</span> +<span class="fc" id="L589"> List wsDataRefs = (List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);</span> // if header was encrypted before it was signed, protected // element is 'EncryptedHeader.' the actual element is // first child element -<span class="fc bfc" id="L578" title="All 2 branches covered."> for (Object objectDataReference : wsDataRefs) {</span> -<span class="fc" id="L579"> WSDataRef wsDataRef = (WSDataRef) objectDataReference;</span> -<span class="fc" id="L580"> Element protectedElement = wsDataRef.getProtectedElement();</span> -<span class="fc bfc" id="L581" title="All 2 branches covered."> if (protectedElement.getLocalName().equals("EncryptedHeader")) {</span> -<span class="fc" id="L582"> NodeList nodeList = protectedElement.getChildNodes();</span> -<span class="pc bpc" id="L583" title="1 of 2 branches missed."> for (int x = 0; x < nodeList.getLength(); x++) {</span> -<span class="nc bnc" id="L584" title="All 2 branches missed."> if (nodeList.item(x).getNodeType() == Node.ELEMENT_NODE) {</span> -<span class="nc" id="L585"> String ns = (nodeList.item(x)).getNamespaceURI();</span> -<span class="nc" id="L586"> String ln = (nodeList.item(x)).getLocalName();</span> -<span class="nc" id="L587"> actuallySigned.add(new QName(ns, ln));</span> -<span class="nc" id="L588"> break;</span> +<span class="fc bfc" id="L595" title="All 2 branches covered."> for (Object objectDataReference : wsDataRefs) {</span> +<span class="fc" id="L596"> WSDataRef wsDataRef = (WSDataRef) objectDataReference;</span> +<span class="fc" id="L597"> Element protectedElement = wsDataRef.getProtectedElement();</span> +<span class="fc bfc" id="L598" title="All 2 branches covered."> if (protectedElement.getLocalName().equals("EncryptedHeader")) {</span> +<span class="fc" id="L599"> NodeList nodeList = protectedElement.getChildNodes();</span> +<span class="pc bpc" id="L600" title="1 of 2 branches missed."> for (int x = 0; x < nodeList.getLength(); x++) {</span> +<span class="nc bnc" id="L601" title="All 2 branches missed."> if (nodeList.item(x).getNodeType() == Node.ELEMENT_NODE) {</span> +<span class="nc" id="L602"> String ns = (nodeList.item(x)).getNamespaceURI();</span> +<span class="nc" id="L603"> String ln = (nodeList.item(x)).getLocalName();</span> +<span class="nc" id="L604"> actuallySigned.add(new QName(ns, ln));</span> +<span class="nc" id="L605"> break;</span> } } -<span class="fc" id="L591"> } else {</span> -<span class="fc" id="L592"> String ns = protectedElement.getNamespaceURI();</span> -<span class="fc" id="L593"> String ln = protectedElement.getLocalName();</span> -<span class="fc" id="L594"> actuallySigned.add(new QName(ns, ln));</span> +<span class="fc" id="L608"> } else {</span> +<span class="fc" id="L609"> String ns = protectedElement.getNamespaceURI();</span> +<span class="fc" id="L610"> String ln = protectedElement.getLocalName();</span> +<span class="fc" id="L611"> actuallySigned.add(new QName(ns, ln));</span> } -<span class="fc" id="L596"> }</span> +<span class="fc" id="L613"> }</span> } } -<span class="fc bfc" id="L601" title="All 2 branches covered."> for (WSEncryptionPart wsep : signatureParts) {</span> -<span class="fc bfc" id="L602" title="All 2 branches covered."> if (wsep.getName().equals(WSConstants.ELEM_BODY)) {</span> +<span class="fc bfc" id="L618" title="All 2 branches covered."> for (WSEncryptionPart wsep : signatureParts) {</span> +<span class="fc bfc" id="L619" title="All 2 branches covered."> if (wsep.getName().equals(WSConstants.ELEM_BODY)) {</span> QName bodyQName; -<span class="fc bfc" id="L606" title="All 2 branches covered."> if (WSConstants.URI_SOAP11_ENV.equals(envelope.getNamespaceURI())) {</span> -<span class="fc" id="L607"> bodyQName = new SOAP11Constants().getBodyQName();</span> +<span class="fc bfc" id="L623" title="All 2 branches covered."> if (WSConstants.URI_SOAP11_ENV.equals(envelope.getNamespaceURI())) {</span> +<span class="fc" id="L624"> bodyQName = new SOAP11Constants().getBodyQName();</span> } else { -<span class="fc" id="L609"> bodyQName = new SOAP12Constants().getBodyQName();</span> +<span class="fc" id="L626"> bodyQName = new SOAP12Constants().getBodyQName();</span> } -<span class="pc bpc" id="L612" title="3 of 4 branches missed."> if (!actuallySigned.contains(bodyQName) && !rmd.getPolicyData().isSignBodyOptional()) {</span> +<span class="pc bpc" id="L629" title="3 of 4 branches missed."> if (!actuallySigned.contains(bodyQName) && !rmd.getPolicyData().isSignBodyOptional()) {</span> // soap body is not signed -<span class="nc" id="L614"> throw new RampartException("bodyNotSigned");</span> +<span class="nc" id="L631"> throw new RampartException("bodyNotSigned");</span> } -<span class="pc bpc" id="L617" title="1 of 4 branches missed."> } else if (wsep.getName().equals(WSConstants.ELEM_HEADER) ||</span> +<span class="pc bpc" id="L634" title="1 of 4 branches missed."> } else if (wsep.getName().equals(WSConstants.ELEM_HEADER) ||</span> wsep.getXpath() != null) { // TODO earlier this was wsep.getType() == WSConstants.PART_TYPE_ELEMENT // This means that encrypted element of an XPath expression type. Therefore we are checking // now whether an XPath expression exists. - Verify -<span class="fc" id="L623"> Element element = WSSecurityUtil.findElement(</span> +<span class="fc" id="L640"> Element element = WSSecurityUtil.findElement(</span> envelope, wsep.getName(), wsep.getNamespace()); -<span class="pc bpc" id="L626" title="1 of 2 branches missed."> if (element == null) {</span> +<span class="pc bpc" id="L643" title="1 of 2 branches missed."> if (element == null) {</span> // The signedpart header or element we are checking is not present in // soap envelope - this is allowed -<span class="nc" id="L629"> continue;</span> +<span class="nc" id="L646"> continue;</span> } // header or the element present in soap envelope - verify that it is part of signature -<span class="pc bpc" id="L633" title="1 of 2 branches missed."> if (actuallySigned.contains(new QName(element.getNamespaceURI(), element.getLocalName()))) {</span> -<span class="fc" id="L634"> continue;</span> +<span class="pc bpc" id="L650" title="1 of 2 branches missed."> if (actuallySigned.contains(new QName(element.getNamespaceURI(), element.getLocalName()))) {</span> +<span class="fc" id="L651"> continue;</span> } -<span class="nc bnc" id="L637" title="All 2 branches missed."> String msg = wsep.getXpath() != null ?</span> +<span class="nc bnc" id="L654" title="All 2 branches missed."> String msg = wsep.getXpath() != null ?</span> "signedPartHeaderNotSigned" : "signedElementNotSigned"; // header or the element defined in policy is present but not signed -<span class="nc" id="L641"> throw new RampartException(msg, new String[]{wsep.getNamespace() + ":" + wsep.getName()});</span> +<span class="nc" id="L658"> throw new RampartException(msg, new String[]{wsep.getNamespace() + ":" + wsep.getName()});</span> } -<span class="fc" id="L644"> }</span> -<span class="fc" id="L645"> }</span> +<span class="fc" id="L661"> }</span> +<span class="fc" id="L662"> }</span> protected boolean isSignatureRequired(RampartMessageData rmd) { -<span class="fc" id="L649"> RampartPolicyData rpd = rmd.getPolicyData();</span> -<span class="pc bpc" id="L650" title="6 of 16 branches missed."> return (rpd.isSymmetricBinding() && rpd.getSignatureToken() != null) ||</span> +<span class="fc" id="L666"> RampartPolicyData rpd = rmd.getPolicyData();</span> +<span class="pc bpc" id="L667" title="6 of 16 branches missed."> return (rpd.isSymmetricBinding() && rpd.getSignatureToken() != null) ||</span> (!rpd.isSymmetricBinding() && !rpd.isTransportBinding() && ((rpd.getInitiatorToken() != null && rmd.isInitiator()) || rpd.getRecipientToken() != null && !rmd.isInitiator())); } - + /* - * Verify that ts->Created is before 'now' - * - testing that timestamp has not expired ('now' is before ts->Expires) is handled earlier by WSS4J - * TODO must write unit tests - */ + * Verify whether timestamp of the message is valid. + * If timeStampStrict is enabled in rampartConfig; testing of timestamp has not expired + * ('now' is before ts->Expires) is also handled earlier by WSS4J without timeskew. + * TODO must write unit tests + */ protected boolean verifyTimestamp(Timestamp timestamp, RampartMessageData rmd) throws RampartException { -<span class="fc" id="L664"> Date createdTime = timestamp.getCreated();</span> -<span class="pc bpc" id="L665" title="1 of 2 branches missed."> if (createdTime != null) {</span> -<span class="fc" id="L666"> long now = Calendar.getInstance().getTimeInMillis();</span> - - // adjust 'now' with allowed timeskew -<span class="fc" id="L669"> long maxSkew = RampartUtil.getTimestampMaxSkew( rmd );</span> -<span class="pc bpc" id="L670" title="1 of 2 branches missed."> if( maxSkew > 0 ) {</span> -<span class="fc" id="L671"> now += (maxSkew * 1000);</span> +<span class="fc" id="L682"> long maxSkew = RampartUtil.getTimestampMaxSkew(rmd);</span> + + //Verify that ts->Created is before 'now' +<span class="fc" id="L685"> Date createdTime = timestamp.getCreated();</span> +<span class="pc bpc" id="L686" title="1 of 2 branches missed."> if (createdTime != null) {</span> +<span class="fc" id="L687"> long now = Calendar.getInstance().getTimeInMillis();</span> + + //calculate the tolerance limit for timeskew of the 'Created' in timestamp +<span class="pc bpc" id="L690" title="1 of 2 branches missed."> if (maxSkew > 0) {</span> +<span class="fc" id="L691"> now += (maxSkew * 1000);</span> } - + // fail if ts->Created is after 'now' -<span class="pc bpc" id="L675" title="1 of 2 branches missed."> if( createdTime.getTime() > now ) {</span> -<span class="nc" id="L676"> return false;</span> +<span class="pc bpc" id="L695" title="1 of 2 branches missed."> if (createdTime.getTime() > now) {</span> +<span class="nc" id="L696"> return false;</span> + } + } + + //Verify that ts->Expires is after now. +<span class="fc" id="L701"> Date expires = timestamp.getExpires();</span> + +<span class="pc bpc" id="L703" title="1 of 2 branches missed."> if (expires != null) {</span> +<span class="fc" id="L704"> long now = Calendar.getInstance().getTimeInMillis();</span> + //calculate the tolerance limit for timeskew of the 'Expires' in timestamp +<span class="pc bpc" id="L706" title="1 of 2 branches missed."> if (maxSkew > 0) {</span> +<span class="fc" id="L707"> now -= (maxSkew * 1000);</span> + } + //fail if ts->Expires is before 'now' +<span class="pc bpc" id="L710" title="1 of 2 branches missed."> if (expires.getTime() < now) {</span> +<span class="nc" id="L711"> return false;</span> } } -<span class="fc" id="L680"> return true;</span> +<span class="fc" id="L715"> return true;</span> } /** @@ -698,11 +733,11 @@ import java.util.*; protected boolean verifyTrust(X509Certificate cert, RampartMessageData rmd) throws RampartException { // If no certificate was transmitted, do not trust the signature -<span class="pc bpc" id="L701" title="1 of 2 branches missed."> if (cert == null) {</span> -<span class="nc" id="L702"> return false;</span> +<span class="pc bpc" id="L736" title="1 of 2 branches missed."> if (cert == null) {</span> +<span class="nc" id="L737"> return false;</span> } -<span class="fc" id="L705"> Crypto crypto = RampartUtil.getSignatureCrypto(</span> +<span class="fc" id="L740"> Crypto crypto = RampartUtil.getSignatureCrypto(</span> rmd.getPolicyData().getRampartConfig(), rmd.getCustomClassLoader()); @@ -714,7 +749,7 @@ import java.util.*; // TODO this validation we are doing in SignatureProcessor.handleToken (WSS4J) So why we need to do again ? // investigate -<span class="fc" id="L717"> return isCertificateTrusted(cert, crypto);</span> +<span class="fc" id="L752"> return isCertificateTrusted(cert, crypto);</span> } @@ -741,13 +776,13 @@ import java.util.*; X509Certificate cert, Crypto crypto ) throws RampartException { -<span class="fc" id="L744"> String subjectString = cert.getSubjectX500Principal().getName();</span> -<span class="fc" id="L745"> String issuerString = cert.getIssuerX500Principal().getName();</span> -<span class="fc" id="L746"> BigInteger issuerSerial = cert.getSerialNumber();</span> - -<span class="pc bpc" id="L748" title="1 of 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L749"> log.debug("Transmitted certificate has subject " + subjectString);</span> -<span class="nc" id="L750"> log.debug(</span> +<span class="fc" id="L779"> String subjectString = cert.getSubjectX500Principal().getName();</span> +<span class="fc" id="L780"> String issuerString = cert.getIssuerX500Principal().getName();</span> +<span class="fc" id="L781"> BigInteger issuerSerial = cert.getSerialNumber();</span> + +<span class="pc bpc" id="L783" title="1 of 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L784"> log.debug("Transmitted certificate has subject " + subjectString);</span> +<span class="nc" id="L785"> log.debug(</span> "Transmitted certificate has issuer " + issuerString + " (serial " + issuerSerial + ")" ); @@ -756,41 +791,41 @@ import java.util.*; // // FIRST step - Search the keystore for the transmitted certificate // -<span class="pc bpc" id="L759" title="1 of 2 branches missed."> if (isCertificateInKeyStore(crypto, cert)) {</span> -<span class="fc" id="L760"> return true;</span> +<span class="pc bpc" id="L794" title="1 of 2 branches missed."> if (isCertificateInKeyStore(crypto, cert)) {</span> +<span class="fc" id="L795"> return true;</span> } // // SECOND step - Search for the issuer cert (chain) of the transmitted certificate in the // keystore or the truststore // -<span class="nc" id="L767"> CryptoType cryptoType = new CryptoType(CryptoType.TYPE.SUBJECT_DN);</span> -<span class="nc" id="L768"> cryptoType.setSubjectDN(issuerString);</span> -<span class="nc" id="L769"> X509Certificate[] foundCerts = new X509Certificate[0];</span> +<span class="nc" id="L802"> CryptoType cryptoType = new CryptoType(CryptoType.TYPE.SUBJECT_DN);</span> +<span class="nc" id="L803"> cryptoType.setSubjectDN(issuerString);</span> +<span class="nc" id="L804"> X509Certificate[] foundCerts = new X509Certificate[0];</span> try { -<span class="nc" id="L771"> foundCerts = crypto.getX509Certificates(cryptoType);</span> -<span class="nc" id="L772"> } catch (WSSecurityException e) {</span> -<span class="nc" id="L773"> throw new RampartException("noCertForSubject", e);</span> -<span class="nc" id="L774"> }</span> +<span class="nc" id="L806"> foundCerts = crypto.getX509Certificates(cryptoType);</span> +<span class="nc" id="L807"> } catch (WSSecurityException e) {</span> +<span class="nc" id="L808"> throw new RampartException("noCertForSubject", e);</span> +<span class="nc" id="L809"> }</span> // If the certs have not been found, the issuer is not in the keystore/truststore // As a direct result, do not trust the transmitted certificate -<span class="nc bnc" id="L778" title="All 4 branches missed."> if (foundCerts == null || foundCerts.length < 1) {</span> -<span class="nc bnc" id="L779" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L780"> log.debug(</span> +<span class="nc bnc" id="L813" title="All 4 branches missed."> if (foundCerts == null || foundCerts.length < 1) {</span> +<span class="nc bnc" id="L814" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L815"> log.debug(</span> "No certs found in keystore for issuer " + issuerString + " of certificate for " + subjectString ); } -<span class="nc" id="L785"> return false;</span> +<span class="nc" id="L820"> return false;</span> } // // THIRD step // Check the certificate trust path for the issuer cert chain // -<span class="nc bnc" id="L792" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L793"> log.debug(</span> +<span class="nc bnc" id="L827" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L828"> log.debug(</span> "Preparing to validate certificate path for issuer " + issuerString ); } @@ -798,10 +833,10 @@ import java.util.*; // Form a certificate chain from the transmitted certificate // and the certificate(s) of the issuer from the keystore/truststore // -<span class="nc" id="L801"> X509Certificate[] x509certs = new X509Certificate[foundCerts.length + 1];</span> -<span class="nc" id="L802"> x509certs[0] = cert;</span> -<span class="nc bnc" id="L803" title="All 2 branches missed."> for (int j = 0; j < foundCerts.length; j++) {</span> -<span class="nc" id="L804"> x509certs[j + 1] = (X509Certificate)foundCerts[j];</span> +<span class="nc" id="L836"> X509Certificate[] x509certs = new X509Certificate[foundCerts.length + 1];</span> +<span class="nc" id="L837"> x509certs[0] = cert;</span> +<span class="nc bnc" id="L838" title="All 2 branches missed."> for (int j = 0; j < foundCerts.length; j++) {</span> +<span class="nc" id="L839"> x509certs[j + 1] = (X509Certificate)foundCerts[j];</span> } // @@ -810,26 +845,26 @@ import java.util.*; // // TODO we need to configure enable revocation ... try { -<span class="nc bnc" id="L813" title="All 2 branches missed."> if (crypto.verifyTrust(x509certs, false)) {</span> -<span class="nc bnc" id="L814" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L815"> log.debug(</span> +<span class="nc bnc" id="L848" title="All 2 branches missed."> if (crypto.verifyTrust(x509certs, false)) {</span> +<span class="nc bnc" id="L849" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L850"> log.debug(</span> "Certificate path has been verified for certificate with subject " + subjectString ); } -<span class="nc" id="L820"> return true;</span> +<span class="nc" id="L855"> return true;</span> } -<span class="nc" id="L822"> } catch (WSSecurityException e) {</span> -<span class="nc" id="L823"> throw new RampartException("certPathVerificationFailed", e);</span> -<span class="nc" id="L824"> }</span> +<span class="nc" id="L857"> } catch (WSSecurityException e) {</span> +<span class="nc" id="L858"> throw new RampartException("certPathVerificationFailed", e);</span> +<span class="nc" id="L859"> }</span> -<span class="nc bnc" id="L826" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L827"> log.debug(</span> +<span class="nc bnc" id="L861" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L862"> log.debug(</span> "Certificate path could not be verified for certificate with subject " + subjectString ); } -<span class="nc" id="L832"> return false;</span> +<span class="nc" id="L867"> return false;</span> } /** @@ -844,81 +879,81 @@ import java.util.*; Crypto crypto, X509Certificate cert ) throws RampartException { -<span class="fc" id="L847"> String issuerString = cert.getIssuerX500Principal().getName();</span> -<span class="fc" id="L848"> BigInteger issuerSerial = cert.getSerialNumber();</span> +<span class="fc" id="L882"> String issuerString = cert.getIssuerX500Principal().getName();</span> +<span class="fc" id="L883"> BigInteger issuerSerial = cert.getSerialNumber();</span> -<span class="fc" id="L850"> CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL);</span> -<span class="fc" id="L851"> cryptoType.setIssuerSerial(issuerString, issuerSerial);</span> -<span class="fc" id="L852"> X509Certificate[] foundCerts = new X509Certificate[0];</span> +<span class="fc" id="L885"> CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL);</span> +<span class="fc" id="L886"> cryptoType.setIssuerSerial(issuerString, issuerSerial);</span> +<span class="fc" id="L887"> X509Certificate[] foundCerts = new X509Certificate[0];</span> try { -<span class="fc" id="L854"> foundCerts = crypto.getX509Certificates(cryptoType);</span> -<span class="nc" id="L855"> } catch (WSSecurityException e) {</span> -<span class="nc" id="L856"> throw new RampartException("noCertificatesForIssuer", new String[]{issuerString,</span> +<span class="fc" id="L889"> foundCerts = crypto.getX509Certificates(cryptoType);</span> +<span class="nc" id="L890"> } catch (WSSecurityException e) {</span> +<span class="nc" id="L891"> throw new RampartException("noCertificatesForIssuer", new String[]{issuerString,</span> issuerSerial.toString()}, e); -<span class="fc" id="L858"> }</span> +<span class="fc" id="L893"> }</span> // // If a certificate has been found, the certificates must be compared // to ensure against phony DNs (compare encoded form including signature) // -<span class="pc bpc" id="L864" title="3 of 6 branches missed."> if (foundCerts != null && foundCerts[0] != null && foundCerts[0].equals(cert)) {</span> -<span class="pc bpc" id="L865" title="1 of 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L866"> log.debug(</span> +<span class="pc bpc" id="L899" title="3 of 6 branches missed."> if (foundCerts != null && foundCerts[0] != null && foundCerts[0].equals(cert)) {</span> +<span class="pc bpc" id="L900" title="1 of 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L901"> log.debug(</span> "Direct trust for certificate with " + cert.getSubjectX500Principal().getName() ); } -<span class="fc" id="L870"> return true;</span> +<span class="fc" id="L905"> return true;</span> } -<span class="nc bnc" id="L872" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> -<span class="nc" id="L873"> log.debug(</span> +<span class="nc bnc" id="L907" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span> +<span class="nc" id="L908"> log.debug(</span> "No certificate found for subject from issuer with " + issuerString + " (serial " + issuerSerial + ")" ); } -<span class="nc" id="L878"> return false;</span> +<span class="nc" id="L913"> return false;</span> } protected ArrayList getEncryptedReferences(List<WSSecurityEngineResult> results) { //there can be multiple ref lists -<span class="fc" id="L885"> List<WSSecurityEngineResult> encrResults = getResults(results, WSConstants.ENCR);</span> +<span class="fc" id="L920"> List<WSSecurityEngineResult> encrResults = getResults(results, WSConstants.ENCR);</span> -<span class="fc" id="L887"> ArrayList refs = new ArrayList();</span> +<span class="fc" id="L922"> ArrayList refs = new ArrayList();</span> -<span class="fc bfc" id="L889" title="All 2 branches covered."> for (WSSecurityEngineResult engineResult : encrResults) {</span> -<span class="fc" id="L890"> ArrayList dataRefUris = (ArrayList) engineResult</span> +<span class="fc bfc" id="L924" title="All 2 branches covered."> for (WSSecurityEngineResult engineResult : encrResults) {</span> +<span class="fc" id="L925"> ArrayList dataRefUris = (ArrayList) engineResult</span> .get(WSSecurityEngineResult.TAG_DATA_REF_URIS); //take only the ref list processing results -<span class="fc bfc" id="L894" title="All 2 branches covered."> if (dataRefUris != null) {</span> -<span class="fc" id="L895"> for (Iterator iterator = dataRefUris.iterator(); iterator</span> -<span class="fc bfc" id="L896" title="All 2 branches covered."> .hasNext(); ) {</span> -<span class="fc" id="L897"> WSDataRef uri = (WSDataRef) iterator.next();</span> -<span class="fc" id="L898"> refs.add(uri);</span> -<span class="fc" id="L899"> }</span> +<span class="fc bfc" id="L929" title="All 2 branches covered."> if (dataRefUris != null) {</span> +<span class="fc" id="L930"> for (Iterator iterator = dataRefUris.iterator(); iterator</span> +<span class="fc bfc" id="L931" title="All 2 branches covered."> .hasNext(); ) {</span> +<span class="fc" id="L932"> WSDataRef uri = (WSDataRef) iterator.next();</span> +<span class="fc" id="L933"> refs.add(uri);</span> +<span class="fc" id="L934"> }</span> } -<span class="fc" id="L901"> }</span> +<span class="fc" id="L936"> }</span> -<span class="fc" id="L903"> return refs;</span> +<span class="fc" id="L938"> return refs;</span> } protected List<WSSecurityEngineResult> getResults(List<WSSecurityEngineResult> results, int action) { -<span class="fc" id="L910"> List<WSSecurityEngineResult> list = new ArrayList<WSSecurityEngineResult>();</span> +<span class="fc" id="L945"> List<WSSecurityEngineResult> list = new ArrayList<WSSecurityEngineResult>();</span> -<span class="fc bfc" id="L912" title="All 2 branches covered."> for (WSSecurityEngineResult result : results) {</span> +<span class="fc bfc" id="L947" title="All 2 branches covered."> for (WSSecurityEngineResult result : results) {</span> // Check the result of every action whether it matches the given // action -<span class="fc" id="L915"> Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);</span> -<span class="fc bfc" id="L916" title="All 2 branches covered."> if (actInt == action) {</span> -<span class="fc" id="L917"> list.add(result);</span> +<span class="fc" id="L950"> Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);</span> +<span class="fc bfc" id="L951" title="All 2 branches covered."> if (actInt == action) {</span> +<span class="fc" id="L952"> list.add(result);</span> } -<span class="fc" id="L919"> }</span> +<span class="fc" id="L954"> }</span> -<span class="fc" id="L921"> return list;</span> +<span class="fc" id="L956"> return list;</span> } protected boolean isUsernameTokenPresent(ValidatorData data) { @@ -926,63 +961,63 @@ import java.util.*; //TODO This can be integrated with supporting token processing // which also checks whether Username Tokens present -<span class="fc" id="L929"> RampartPolicyData rpd = data.getRampartMessageData().getPolicyData();</span> +<span class="nc" id="L964"> RampartPolicyData rpd = data.getRampartMessageData().getPolicyData();</span> -<span class="fc" id="L931"> List<SupportingToken> supportingToks = rpd.getSupportingTokensList();</span> -<span class="pc bpc" id="L932" title="1 of 2 branches missed."> for (SupportingToken suppTok : supportingToks) {</span> -<span class="nc bnc" id="L933" title="All 2 branches missed."> if (isUsernameTokenPresent(suppTok)) {</span> -<span class="nc" id="L934"> return true;</span> +<span class="nc" id="L966"> List<SupportingToken> supportingToks = rpd.getSupportingTokensList();</span> +<span class="nc bnc" id="L967" title="All 2 branches missed."> for (SupportingToken suppTok : supportingToks) {</span> +<span class="nc bnc" id="L968" title="All 2 branches missed."> if (isUsernameTokenPresent(suppTok)) {</span> +<span class="nc" id="L969"> return true;</span> } -<span class="nc" id="L936"> }</span> +<span class="nc" id="L971"> }</span> -<span class="fc" id="L938"> SupportingToken signedSuppToken = rpd.getSignedSupportingTokens();</span> -<span class="pc bpc" id="L939" title="1 of 2 branches missed."> if(isUsernameTokenPresent(signedSuppToken)) {</span> -<span class="fc" id="L940"> return true;</span> +<span class="nc" id="L973"> SupportingToken signedSuppToken = rpd.getSignedSupportingTokens();</span> +<span class="nc bnc" id="L974" title="All 2 branches missed."> if(isUsernameTokenPresent(signedSuppToken)) {</span> +<span class="nc" id="L975"> return true;</span> } -<span class="nc" id="L943"> SupportingToken signedEndSuppToken = rpd.getSignedEndorsingSupportingTokens();</span> -<span class="nc bnc" id="L944" title="All 2 branches missed."> if(isUsernameTokenPresent(signedEndSuppToken)) {</span> -<span class="nc" id="L945"> return true;</span> +<span class="nc" id="L978"> SupportingToken signedEndSuppToken = rpd.getSignedEndorsingSupportingTokens();</span> +<span class="nc bnc" id="L979" title="All 2 branches missed."> if(isUsernameTokenPresent(signedEndSuppToken)) {</span> +<span class="nc" id="L980"> return true;</span> } -<span class="nc" id="L948"> SupportingToken endSuppToken = rpd.getEndorsingSupportingTokens();</span> -<span class="nc" id="L949"> return isUsernameTokenPresent(endSuppToken);</span> +<span class="nc" id="L983"> SupportingToken endSuppToken = rpd.getEndorsingSupportingTokens();</span> +<span class="nc" id="L984"> return isUsernameTokenPresent(endSuppToken);</span> } protected boolean isUsernameTokenPresent(SupportingToken suppTok) { -<span class="pc bpc" id="L956" title="1 of 2 branches missed."> if(suppTok == null) {</span> -<span class="nc" id="L957"> return false;</span> +<span class="nc bnc" id="L991" title="All 2 branches missed."> if(suppTok == null) {</span> +<span class="nc" id="L992"> return false;</span> } -<span class="fc" id="L960"> ArrayList tokens = suppTok.getTokens();</span> -<span class="pc bpc" id="L961" title="1 of 2 branches missed."> for (Iterator iter = tokens.iterator(); iter.hasNext();) {</span> -<span class="fc" id="L962"> Token token = (Token) iter.next();</span> -<span class="pc bpc" id="L963" title="1 of 2 branches missed."> if(token instanceof UsernameToken) {</span> -<span class="fc" id="L964"> return true;</span> +<span class="nc" id="L995"> ArrayList tokens = suppTok.getTokens();</span> +<span class="nc bnc" id="L996" title="All 2 branches missed."> for (Iterator iter = tokens.iterator(); iter.hasNext();) {</span> +<span class="nc" id="L997"> Token token = (Token) iter.next();</span> +<span class="nc bnc" id="L998" title="All 2 branches missed."> if(token instanceof UsernameToken) {</span> +<span class="nc" id="L999"> return true;</span> } -<span class="nc" id="L966"> }</span> +<span class="nc" id="L1001"> }</span> -<span class="nc" id="L968"> return false;</span> +<span class="nc" id="L1003"> return false;</span> } private boolean isRefIdPresent(ArrayList refList , String id) { -<span class="pc bpc" id="L973" title="2 of 4 branches missed."> if(id != null && id.charAt(0) == '#') {</span> -<span class="nc" id="L974"> id = id.substring(1);</span> +<span class="pc bpc" id="L1008" title="2 of 4 branches missed."> if(id != null && id.charAt(0) == '#') {</span> +<span class="nc" id="L1009"> id = id.substring(1);</span> } -<span class="pc bpc" id="L977" title="1 of 2 branches missed."> for (Object aRefList : refList) {</span> -<span class="fc" id="L978"> WSDataRef dataRef = (WSDataRef) aRefList;</span> +<span class="pc bpc" id="L1012" title="1 of 2 branches missed."> for (Object aRefList : refList) {</span> +<span class="fc" id="L1013"> WSDataRef dataRef = (WSDataRef) aRefList;</span> //ArrayList can contain null elements -<span class="pc bpc" id="L981" title="1 of 2 branches missed."> if (dataRef == null) {</span> -<span class="nc" id="L982"> continue;</span> +<span class="pc bpc" id="L1016" title="1 of 2 branches missed."> if (dataRef == null) {</span> +<span class="nc" id="L1017"> continue;</span> } //Try to get the wsuId of the decrypted element -<span class="fc" id="L985"> String dataRefUri = dataRef.getWsuId();</span> +<span class="fc" id="L1020"> String dataRefUri = dataRef.getWsuId();</span> //If not found, try the reference Id of encrypted element ( we set the same Id when we // decrypted element in WSS4J) // TODO wsu id must present. We need to find the scenario where it is not set @@ -990,51 +1025,51 @@ import java.util.*; // dataRefUri = dataRef.getProtectedElement().getAttribute("Id"); // TODO check whether this is correct // earlier it was dataRefUri = dataRef.getDataref(); //} -<span class="pc bpc" id="L993" title="2 of 4 branches missed."> if (dataRefUri != null && dataRefUri.equals(id)) {</span> -<span class="fc" id="L994"> return true;</span> +<span class="pc bpc" id="L1028" title="2 of 4 branches missed."> if (dataRefUri != null && dataRefUri.equals(id)) {</span> +<span class="fc" id="L1029"> return true;</span> } -<span class="nc" id="L996"> }</span> +<span class="nc" id="L1031"> }</span> -<span class="nc" id="L998"> return false;</span> +<span class="nc" id="L1033"> return false;</span> } public static WSSecurityEngineResult[] fetchActionResults(List<WSSecurityEngineResult> wsSecurityEngineResults, int action) { -<span class="fc" id="L1003"> List<WSSecurityEngineResult> wsResult = new ArrayList<WSSecurityEngineResult>();</span> +<span class="fc" id="L1038"> List<WSSecurityEngineResult> wsResult = new ArrayList<WSSecurityEngineResult>();</span> // Find the part of the security result that matches the given action -<span class="fc bfc" id="L1006" title="All 2 branches covered."> for (WSSecurityEngineResult wsSecurityEngineResult : wsSecurityEngineResults) {</span> +<span class="fc bfc" id="L1041" title="All 2 branches covered."> for (WSSecurityEngineResult wsSecurityEngineResult : wsSecurityEngineResults) {</span> // Check the result of every action whether it matches the given action -<span class="fc" id="L1008"> WSSecurityEngineResult result = (WSSecurityEngineResult) wsSecurityEngineResult;</span> -<span class="fc" id="L1009"> int resultAction = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);</span> -<span class="fc bfc" id="L1010" title="All 2 branches covered."> if (resultAction == action) {</span> -<span class="fc" id="L1011"> wsResult.add(wsSecurityEngineResult);</span> +<span class="fc" id="L1043"> WSSecurityEngineResult result = (WSSecurityEngineResult) wsSecurityEngineResult;</span>
[... 44 lines stripped ...]
