You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2012/08/22 18:25:26 UTC
svn commit: r1376125 [1/3] - in /webservices/wss4j/trunk:
ws-security-common/src/main/java/org/apache/ws/security/common/bsp/
ws-security-dom/src/main/java/org/apache/ws/security/dom/
ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/ ws-sec...
Author: coheigea
Date: Wed Aug 22 16:25:23 2012
New Revision: 1376125
URL: http://svn.apache.org/viewvc?rev=1376125&view=rev
Log:
[WSS-360] - Moving BSPRule stuff to common module
Added:
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/BSPRule.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/BSPEnforcer.java
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSConfig.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSecurityEngine.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/handler/RequestData.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/BinarySecurity.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/KerberosSecurity.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/PKIPathSecurity.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SecurityTokenReference.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SignatureConfirmation.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/Timestamp.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/UsernameToken.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/X509Security.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/BinarySecurityTokenProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedDataProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedKeyProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/ReferenceListProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/SignatureConfirmationProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/SignatureProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/TimestampProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/UsernameTokenProcessor.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/str/EncryptedKeySTRParser.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/str/SecurityTokenRefSTRParser.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/handler/SignatureConfirmationTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/EncryptionTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/SignatureEncryptionTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/TimestampTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/UTDerivedKeyTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/UsernameTokenTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/token/BinarySecurityTokenTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/message/token/WCFUsernameTokenTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/ws/security/dom/misc/FaultCodeTest.java
webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AsymmetricBindingIntegrationTest.java
webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/TransportBindingIntegrationTest.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSConstants.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSSecurityProperties.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSecurityContext.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/WSSecurityContextImpl.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SignatureConfirmationInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSEncryptedKeyInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/InteroperabilityTest.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/SecurityContextTokenTest.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/SignatureTest.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/TimestampTest.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/VulnerabliltyVectorsTest.java
Added: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/BSPRule.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/BSPRule.java?rev=1376125&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/BSPRule.java (added)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/ws/security/common/bsp/BSPRule.java Wed Aug 22 16:25:23 2012
@@ -0,0 +1,198 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ws.security.common.bsp;
+
+/**
+ * A Basic Security Profile rule.
+ */
+public enum BSPRule {
+ R3203("A TIMESTAMP MUST contain exactly one CREATED"),
+ R3224("Any TIMESTAMP MUST NOT contain more than one EXPIRES"),
+ R3221("Any TIMESTAMP containing an EXPIRES MUST contain a CREATED that precedes its sibling EXPIRES"),
+ R3222("Any TIMESTAMP MUST NOT contain anything other than CREATED or EXPIRES elements"),
+ R3220("Any CREATED SHOULD NOT contain a seconds value with more than three digits to the right of the decimal (milliseconds)"),
+ R3229("Any EXPIRES SHOULD NOT contain a seconds value with more than three digits to the right of the decimal (milliseconds)"),
+ R3213("Any CREATED containing second values MUST specify seconds values less than 60"),
+ R3215("Any EXPIRES containing second values MUST specify seconds values less than 60"),
+ R3225("Any CREATED MUST NOT include a ValueType attribute"),
+ R3226("Any EXPIRES MUST NOT include a ValueType attribute"),
+ R3217("Any CREATED MUST contain time values in UTC format as specified by the XML Schema type (dateTime)"),
+ R3223("Any EXPIRES MUST contain time values in UTC format as specified by the XML Schema type (dateTime)"),
+ R3227("A SECURITY_HEADER MUST NOT contain more than one TIMESTAMP"),
+
+ R3061("A SECURITY_TOKEN_REFERENCE MUST provide exactly one token reference"),
+ R3074("Any wsse:11:TokenType Attribute in a SECURITY_TOKEN_REFERENCE MUST specify a value that a TokenType specified by a security token profile for the referenced SECURITY_TOKEN"),
+ R3057("Any STR_REFERENCE MUST NOT reference a SECURITY_TOKEN_REFERENCE"),
+ R3064("Any STR_REFERENCE MUST NOT reference an STR_EMBEDDED"),
+ R3059("Any STR_REFERENCE MUST specify a ValueType attribute with the exception of STR_REFERENCE pointing to a SAML_V2_0_TOKEN or a KERBEROS_TOKEN or an ENCRYPTED_KEY_TOKEN"),
+ R3058("Any STR_REFERENCE ValueType attribute MUST contain a value for the referenced SECURITY_TOKEN specified by the corresponding security token profile"),
+ R3062("Any STR_REFERENCE MUST specify a URI attribute"),
+ R3027("Any SECURITY_TOKEN_REFERENCE MUST NOT contain an STR_KEY_NAME"),
+ R3054("Any STR_KEY_IDENTIFIER MUST specify a ValueType attribute"),
+ R3063("Any STR_KEY_IDENTIFIER ValueType attribute MUST contain a value specified within the security token profile associated with the referenced SECURITY_TOKEN"),
+ R3070("Any STR_KEY_IDENTIFIER that refers to a SECURITY_TOKEN other than a SAML_TOKEN MUST specify an EncodingType attribute"),
+ R3071("Any STR_KEY_IDENTIFIER EncodingType attribute MUST have a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\""),
+ R3060("Any STR_EMBEDDED MUST contain only a single child element which is an INTERNAL_SECURITY_TOKEN"),
+ R3025("Any INTERNAL_SECURITY_TOKEN contained in an STR_EMBEDDED MUST be in the same format as if it were a child of a SECURITY_HEADER"),
+ R3056("Any STR_EMBEDDED MUST NOT contain a wsse:SecurityTokenReference child element"),
+ R3022("Any SECURITY_TOKEN_REFERENCE that references an INTERNAL_SECURITY_TOKEN which has a wsu:Id attribute MUST contain an STR_REFERENCE or STR_EMBEDDED"),
+ R3023("Any SECURITY_TOKEN_REFERENCE that references an INTERNAL_SECURITY_TOKEN that is referenced several times SHOULD contain an STR_REFERENCE rather than an STR_EMBEDDED"),
+ R5204("Any STR_REFERENCE to an INTERNAL_SECURITY_TOKEN having an ID attribute MUST contain a URI attribute with a Shorthand XPointer value"),
+ R5205("Any INTERNAL_SECURITY_TOKEN that is not contained in an STR_EMBEDDED MUST precede all SECURITY_TOKEN_REFERENCE elements that reference it in the SOAP_ENVELOPE"),
+ R3066("Any STR_REFERENCE that is a descendant of a SECURITY_HEADER MUST NOT use a Shorthand XPointer to refer to an INTERNAL_SECURITY_TOKEN located in a SECURITY_HEADER other than the SECURITY_HEADER that contains the STR_REFERENCE"),
+ R3067("Any STR_REFERENCE that is a descendant of an ENCRYPTED_DATA MUST NOT use a Shorthand XPointer to refer to an INTERNAL_SECURITY_TOKEN located in a SECURITY_HEADER other than the SECURITY_HEADER containing a reference (EK_REFERENCE_LIST or an ENC_REFERENCE_LIST) to the ENCRYPTED_DATA"),
+ R3024("Any EXTERNAL_TOKEN_REFERENCE that can use an STR_REFERENCE MUST contain an STR_REFERENCE"),
+ R3211("Any SECURITY_TOKEN_REFERENCE MUST NOT reference a ds:KeyInfo element"),
+
+ R3102("A SIGNATURE MUST NOT be an Enveloping Signature as defined by the XML Signature specification"),
+ R3104("A SIGNATURE SHOULD NOT be an Enveloped Signature as defined by the XML Signature specification"),
+ R3103("A SIGNATURE SHOULD be a Detached Signature as defined by the XML Signature specification"),
+ R3001("Any SIG_REFERENCE SHOULD contain a URI attribute containing a Shorthand XPointer"),
+ R3003("Any SIG_REFERENCE to a SIGNATURE or descendant of a SIGNATURE MUST contain a URI attribute with a reference value that is a Shorthand XPointer to Local ID attribute defined by XML Signature"),
+ R3004("Any SIG_REFERENCE to an element defined in XML Encryption MUST contain a URI attribute with a reference value that is a Shorthand XPointer to Local ID attribute defined by XML Encryption"),
+ R3005("Any SIG_REFERENCE to an element that is not defined in XML Encryption, a SIGNATURE, or a descendant of a SIGNATURE SHOULD contain a URI attribute with a reference value that is a Shorthand XPointer to a wsu:Id attribute"),
+ R3002("Any SIG_REFERENCE to an element that does not have an ID attribute MUST contain a TRANSFORM with an Algorithm attribute value of \"http://www.w3.org/2002/06/xmldsig-filter2\""),
+ R5416("Any SIG_REFERENCE MUST contain a SIG_TRANSFORMS child element"),
+ R5411("Any SIG_TRANSFORMS MUST contain at least one SIG_TRANSFORM child element"),
+ R5423("Any SIG_TRANSFORM Algorithm attribute MUST have a value of \"http://www.w3.org/2001/10/xml-exc-c14n#\" or \"http://www.w3.org/2002/06/xmldsig-filter2\" or \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform\" or \"http://www.w3.org/2000/09/xmldsig#enveloped-signature\" or \"http://docs.oasis-open.org/wss/oasis-wss-SwAProfile-1.1#Attachment-Content-Signature-Transform\" or \"http://docs.oasis-open.org/wss/oasis-wss-SwAProfile-1.1#Attachment-Complete-Signature-Transform\""),
+ R5412("Any SIG_TRANSFORMS MUST contain as its last child a SIG_TRANSFORM with an Algorithm attribute with a value of \"http://www.w3.org/2001/10/xml-exc-c14n#\" or \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform\" or \"http://docs.oasis-open.org/wss/oasis-wss-SwAProfile-1.1#Attachment-Content-Signature-Transform\" or \"http://docs.oasis-open.org/wss/oasis-wss-SwAProfile-1.1#Attachment-Complete-Signature-Transform\""),
+ R5407("Any SIG_TRANSFORM with an Algorithm attribute with a value of \"http://www.w3.org/2001/10/xml-exc-c14n#\" MUST contain an INCLUSIVE_NAMESPACES with an PrefixList attribute unless the PrefixList is empty"),
+ R5413("Any SIG_TRANSFORM with an Algorithm attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform\" MUST have an INCLUSIVE_NAMESPACES with an PrefixList attribute unless the PrefixList is empty"),
+ R3065("Any SIG_TRANSFORM with an Algorithm attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform\" MUST contain a child wsse:TransformationParameters element containing a child ds:CanonicalizationMethod element"),
+ R5404("Any CANONICALIZATION_METHOD Algorithm attribute MUST have a value of \"http://www.w3.org/2001/10/xml-exc-c14n#\" indicating that it uses Exclusive C14N without comments for canonicalization"),
+ R5406("Any CANONICALIZATION_METHOD MUST contain an INCLUSIVE_NAMESPACES with a PrefixList attribute unless the PrefixList is empty"),
+ R5414("A RECEIVER MUST be capable of accepting and processing an INCLUSIVE_NAMESPACES PrefixList attribute containing prefixes in any order within the string"),
+ R5415("A RECEIVER MUST be capable of accepting and processing an INCLUSIVE_NAMESPACES PrefixList attribute containing arbitrary whitespace before, after and between the prefixes within the string"),
+ R5405("Any INCLUSIVE_NAMESPACES MUST contain the prefix of all namespaces that are in-scope and desired to be protected, but not visibly utilized, for the element being signed and its descendants, per Exclusive XML Canonicalization Version 1.0"),
+ R5408("Any INCLUSIVE_NAMESPACES MUST contain the string \"#default\" if a default namespace is in-scope and desired to be protected, but not visibly utilized, for the element being signed and its descendants, per Exclusive XML Canonicalization Version 1.0"),
+ R5420("Any DIGEST_METHOD Algorithm attribute SHOULD have the value \"http://www.w3.org/2000/09/xmldsig#sha1\""),
+ R5421("Any SIGNATURE_METHOD Algorithm attribute SHOULD have a value of \"http://www.w3.org/2000/09/xmldsig#hmac-sha1\" or \"http://www.w3.org/2000/09/xmldsig#rsa-sha1\""),
+ R5401("Any SIGNATURE_METHOD MUST NOT contain a ds:HMACOutputLength child element"),
+ R5402("Any SIG_KEY_INFO MUST contain exactly one child element"),
+ R5417("Any SIG_KEY_INFO MUST contain a SECURITY_TOKEN_REFERENCE child element"),
+ R5403("A SIGNATURE MUST NOT contain a ds:Manifest descendant element"),
+ R5440("A SIGNATURE MUST NOT have any xenc:EncryptedData elements amongst its descendants"),
+ R5441("A SIGNATURE_CONFIRMATION MUST contain a wsu:Id attribute"),
+
+ R3228("A soap:Header element in a SECURE_ENVELOPE MUST NOT contain any child ENCRYPTED_DATA"),
+ R3299("A soap:Header element in a SECURE_ENVELOPE MAY contain ENCRYPTED_HEADER children"),
+ R3230("An ENCRYPTED_HEADER MUST NOT contain any children other than a single required ENCRYPTED_DATA"),
+ R3232("In cases where a wsu:Id does exist on the ENCRYPTED_HEADER, the child ENCRYPTED_DATA MAY contain an Id attribute"),
+ R3205("Any ENC_REFERENCE_LIST produced as part of an encryption step MUST use a single key"),
+ R3231("Any ENC_REFERENCE_LIST MUST contain an xenc:DataReference element for each ENCRYPTED_DATA produced in the associated encryption step"),
+ R3214("Any EK_REFERENCE_LIST MUST contain a xenc:DataReference for each ENCRYPTED_DATA produced in the associated encryption step"),
+ R3208("Any ENCRYPTED_KEY MUST precede any ENCRYPTED_DATA in the same SECURITY_HEADER referenced by the associated EK_REFERENCE_LIST"),
+ R3209("Any ENCRYPTED_KEY MUST NOT specify a Type attribute"),
+ R5622("Any ENCRYPTED_KEY MUST NOT specify a MimeType attribute"),
+ R5623("Any ENCRYPTED_KEY MUST NOT specify a Encoding attribute"),
+ R5602("Any ENCRYPTED_KEY MUST NOT contain a Recipient attribute"),
+ R5603("Any ENCRYPTED_KEY MUST contain an xenc:EncryptionMethod child element"),
+ R5629("An ENCRYPTED_DATA which is not referenced from an ENCRYPTED_KEY MUST contain a ds:KeyInfo"),
+ R5624("In cases where a wsu:Id does not exist on the ENCRYPTED_HEADER, the child ENCRYPTED_DATA MUST contain an ID attribute"),
+ R5627("In cases where an ID does not exist on the ENCRYPTED_DATA, the parent ENCRYPTED_HEADER MUST contain a wsu:Id attribute"),
+ R5601("Any ENCRYPTED_DATA MUST contain an xenc:EncryptionMethod child element"),
+ R5424("Any ENC_KEY_INFO MUST have exactly one child element"),
+ R5426("Any ENC_KEY_INFO MUST contain a child SECURITY_TOKEN_REFERENCE"),
+ R5608("Any ENC_DATA_REFERENCE MUST contain a URI attribute containing a Shorthand XPointer reference value based on either the Id attribute of the referenced ENCRYPTED_DATA or the wsu:Id attribute of the referenced ENCRYPTED_HEADER"),
+ R3006("Any EK_DATA_REFERENCE MUST contain a URI attribute containing a Shorthand XPointer reference value based on either the Id attribute of the referenced ENCRYPTED_DATA or the wsu:Id attribute of the referenced ENCRYPTED_HEADER"),
+ R5613("Any ENC_KEY_REFERENCE MUST contain a URI attribute containing a Shorthand XPointer reference value based on the Id attribute of the referred to ENCRYPTED_KEY"),
+ R3007("Any EK_KEY_REFERENCE MUST contain a URI attribute containing a Shorthand XPointer reference value based on the Id attribute of the referred to ENCRYPTED_KEY"),
+ R5620("Any ED_ENCRYPTION_METHOD Algorithm attribute MUST have a value of \"http://www.w3.org/2001/04/xmlenc#tripledes-cbc\", \"http://www.w3.org/2001/04/xmlenc#aes128-cbc\" or \"http://www.w3.org/2001/04/xmlenc#aes256-cbc\""),
+ R5621("When used for Key Transport, any EK_ENCRYPTION_METHOD Algorithm attribute MUST have a value of \"http://www.w3.org/2001/04/xmlenc#rsa-1_5\" or \"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\""),
+ R5625("When used for Key Wrap, any EK_ENCRYPTION_METHOD Algorithm attribute MUST have a value of \"http://www.w3.org/2001/04/xmlenc#kw-tripledes\", \"http://www.w3.org/2001/04/xmlenc#kw-aes128\", or \"http://www.w3.org/2001/04/xmlenc#kw-aes256\""),
+ R5626("Any EK_ENCRYPTION_METHOD Algorithm attribute MUST have a value of \"http://www.w3.org/2001/04/xmlenc#rsa-1_5\" or \"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\" or \"http://www.w3.org/2001/04/xmlenc#kw-tripledes\" or \"http://www.w3.org/2001/04/xmlenc#kw-aes128\" or \"http://www.w3.org/2001/04/xmlenc#kw-aes256\""),
+ R5614("A HEADER encrypted as a result of an encryption step MUST be replaced by a corresponding ENCRYPTED_HEADER"),
+ R5606("Any encrypted element or element content within a SECURE_ENVELOPE, encrypted as a result of an encryption step, MUST be replaced by a corresponding ENCRYPTED_DATA, unless the element is a HEADER_ELEMENT"),
+
+ R3029("Any BINARY_SECURITY_TOKEN MUST specify an EncodingType attribute"),
+ R3030("Any BINARY_SECURITY_TOKEN EncodingType attribute MUST have a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\""),
+ R3031("Any BINARY_SECURITY_TOKEN MUST specify an ValueType attribute"),
+ R3032("Any BINARY_SECURITY_TOKEN ValueType attribute MUST have a value specified by the related security token profile"),
+
+ R4222("Any USERNAME_TOKEN MUST NOT have more than one PASSWORD"),
+ R4201("Any PASSWORD MUST specify a Type attribute"),
+ R4212("Any PASSWORD with a Type attribute value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\" MUST have its value computed using the following formula, where \"+\" indicates concatenation: Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) ). That is, concatenate the text forms of the nonce, creation time, and the password (or shared secret or password equivalent), digest the combination using the SHA-1 hash algorithm, then include the Base64 encoding of that result as the password (digest). Any elements that are not present are simply omitted from the concatenation"),
+ R4216("When a SECURITY_TOKEN_REFERENCE, within a SIGNATURE or ENCRYPTED_KEY, refers to a SECURITY_TOKEN named wsse:UsernameToken to derive a key, the key MUST be derived using the algorithm specified in Section 4 of Web Services Security: UsernameToken Profile 1.1"),
+ R4217("When a SECURITY_TOKEN_REFERENCE, within a SIGNATURE or ENCRYPTED_KEY, refers to a SECURITY_TOKEN named wsse:UsernameToken to derive a key, the SECURITY_TOKEN MUST contain a wsse11:Salt child element"),
+ R4218("When a SECURITY_TOKEN_REFERENCE, within a SIGNATURE or ENCRYPTED_KEY, refers to a SECURITY_TOKEN named wsse:UsernameToken to derive a key, the SECURITY_TOKEN MUST contain a wsse11:Iteration child element with a value greater than or equal to 1000"),
+ R4223("Any USERNAME_TOKEN MUST NOT have more than one CREATED"),
+ R4225("Any USERNAME_TOKEN MUST NOT have more than one NONCE"),
+ R4220("Any NONCE MUST specify an EncodingType attribute"),
+ R4221("Any NONCE EncodingType attribute MUST have a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\""),
+ R4214("Any STR_REFERENCE to a USERNAME_TOKEN MUST have a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken\""),
+ R4215("Any SECURITY_TOKEN_REFERENCE to a USERNAME_TOKEN MUST NOT contain an STR_KEY_IDENTIFIER"),
+
+ R3033("Any X509_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\""),
+ R5201("Any BINARY_SECURITY_TOKEN containing an X.509 Certificate Path MUST be either a PKCS7_TOKEN or a PKIPATH_TOKEN"),
+ R5202("Any BINARY_SECURITY_TOKEN containing an X.509 Certificate Path SHOULD be a PKIPATH_TOKEN"),
+ R5211("Any PKCS7_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#PKCS7\""),
+ R5218("Any STR_REFERENCE to a X509_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\""),
+ R5212("Any SECURITY_TOKEN_REFERENCE to a PKCS7_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#PKCS7\""),
+ R5213("Any STR_REFERENCE to a PKCS7_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#PKCS7\""),
+ R5214("Any PKIPATH_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1\""),
+ R5215("Any SECURITY_TOKEN_REFERENCE to a PKIPATH_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1\""),
+ R5216("Any STR_REFERENCE to a PKIPATH_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1\""),
+ R5209("When a SECURITY_TOKEN_REFERENCE references an EXTERNAL_SECURITY_TOKEN that cannot be referred to using an STR_REFERENCE but can be referred to using an STR_KEY_IDENTIFIER or STR_ISSUER_SERIAL, an STR_KEY_IDENTIFIER or STR_ISSUER_SERIAL MUST be used"),
+ R5206("Any STR_KEY_IDENTIFIER that references an X509_TOKEN MUST have a ValueType attribute with the value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier\" or \"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1\""),
+ R5208("Any STR_KEY_IDENTIFIER that references an X509_TOKEN and has a ValueType attribute with the value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier\" MUST contain the value of the token's SubjectKeyIdentifier extension"),
+ R5210("Any STR_KEY_IDENTIFIER that references an X509_TOKEN which does not contain a SubjectKeyIdentifier extension MUST have a ValueType attribute with the value of \"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1\" and MUST contain the value of the SHA1 of the raw octets of the X509_TOKEN that is referenced"),
+ R5409("Any STR_ISSUER_SERIAL MUST contain a value following the encoding rules specified in the XML Signature specification for DNames"),
+
+ R6304("Any STR_REFERENCE to a REL_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-rel-token-profile-1.0.pdf#license\""),
+ R6301("Any STR_REFERENCE to a INTERNAL_SECURITY_TOKEN that is an REL_TOKEN containing a wsu:Id attribute, MUST NOT use a licenseId reference"),
+ R6302("Any SECURITY_HEADER child elements MUST be ordered so that any SIGNATURE necessary to verify the issuance of an REL_TOKEN precedes the first SECURITY_TOKEN_REFERENCE that refers to that REL_TOKEN"),
+
+ R6902("Any KERBEROS_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ\""),
+ R6903("Any KERBEROS_TOKEN MUST be an INTERNAL_SECURITY_TOKEN in the initial SECURE_ENVELOPE of an authenticated message exchange between a SENDER and RECEIVER"),
+ R6904("Any KERBEROS_TOKEN MUST be an EXTERNAL_SECURITY_TOKEN in each SECURE_ENVELOPE after the initial SECURE_ENVELOPE of an authenticated message exchange between a SENDER and RECEIVER"),
+ R6907("Any SECURITY_TOKEN_REFERENCE to a KERBEROS_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ\""),
+ R6906("Any STR_KEY_IDENTIFIER to a KERBEROS_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-kerberos-tokenprofile-1.1#Kerberosv5APREQSHA1\""),
+ R6905("Any SECURITY_TOKEN_REFERENCE to an EXTERNAL_SECURITY_TOKEN which is a KERBEROS_TOKEN MUST contain an STR_KEY_IDENTIFIER"),
+
+ R6601("Any SAML_SC_KEY_INFO MUST NOT contain a reference to a SAML_TOKEN"),
+ R6611("Any SECURITY_TOKEN_REFERENCE to a SAML_V1_1_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1\""),
+ R6617("Any SECURITY_TOKEN_REFERENCE to a SAML_V2_0_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0\""),
+ R6614("Any SECURITY_TOKEN_REFERENCE that references an INTERNAL_SAML_V2_0_TOKEN using a STR_REFERENCE MUST NOT contain a ValueType attribute"),
+ R6602("Any STR_KEY_IDENTIFIER that references a INTERNAL_SAML_TOKEN MUST include a ValueType attribute"),
+ R6609("Any STR_KEY_IDENTIFIER that references a EXTERNAL_SAML_TOKEN MUST include a ValueType attribute"),
+ R6603("Any STR_KEY_IDENTIFIER ValueType attribute that references a SAML_V1_1_TOKEN MUST have a value of \"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID\""),
+ R6616("Any STR_KEY_IDENTIFIER ValueType attribute that references a SAML_V2_0_TOKEN MUST have a value of \"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID\""),
+ R6604("Any STR_KEY_IDENTIFIER that references a SAML_TOKEN MUST NOT include an EncodingType attribute"),
+ R6605("Any STR_KEY_IDENTIFIER that references a SAML_TOKEN MUST have a value encoded as an xs:string"),
+ R6610("Any SECURITY_TOKEN_REFERENCE that references an INTERNAL_SAML_TOKEN that has an ID attribute, the reference MUST contain an STR_REFERENCE or an STR_EMBEDDED"),
+ R6612("Any SIG_REFERENCE to a SECURITY_TOKEN_REFERENCE which contains an STR_EMBEDDED which contains an INTERNAL_SAML_V2_0_TOKEN MUST NOT include a SIG_TRANSFORM with an Algorithm attribute value of \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform\""),
+ R6606("Any SECURITY_TOKEN_REFERENCE that references an EXTERNAL_SAML_TOKEN MUST contain a SAML_AUTHORITY_BINDING"),
+ R6607("Any AuthorityKind attribute of a SAML_AUTHORITY_BINDING MUST have a value of saml:AssertionIDReference"),
+ R6608("Any SECURITY_TOKEN_REFERENCE that references an INTERNAL_SAML_TOKEN MUST NOT contain a SAML_AUTHORITY_BINDING"),
+ R6613("Any SECURITY_TOKEN_REFERENCE to an EXTERNAL_SAML_V2_0_TOKEN MUST contain an STR_REFERENCE"),
+
+ R3069("Any SECURITY_TOKEN_REFERENCE to a ENCRYPTED_KEY_TOKEN MUST contain a wsse11:TokenType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey\""),
+ R3072("Any STR_KEY_IDENTIFIER element in a SECURITY_TOKEN_REFERENCE that refers to an ENCRYPTED_KEY_TOKEN MUST contain a ValueType attribute with a value of \"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKeySHA1\"");
+
+ private final String msg;
+
+ private BSPRule(String msg) {
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+}
\ No newline at end of file
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSConfig.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSConfig.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSConfig.java Wed Aug 22 16:25:23 2012
@@ -25,6 +25,8 @@ import java.security.Security;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
import javax.xml.namespace.QName;
import org.apache.ws.security.dom.action.Action;
@@ -48,6 +50,16 @@ import org.apache.xml.security.stax.impl
*/
public class WSSConfig {
+ public static final DatatypeFactory datatypeFactory;
+
+ static {
+ try {
+ datatypeFactory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private static final org.apache.commons.logging.Log LOG =
org.apache.commons.logging.LogFactory.getLog(WSSConfig.class);
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSecurityEngine.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSecurityEngine.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSecurityEngine.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/WSSecurityEngine.java Wed Aug 22 16:25:23 2012
@@ -19,6 +19,7 @@
package org.apache.ws.security.dom;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.crypto.Crypto;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.derivedKey.ConversationConstants;
@@ -304,6 +305,39 @@ public class WSSecurityEngine {
return processSecurityHeader(securityHeader, data);
}
+ /**
+ * Process the security header given the soap envelope as W3C document.
+ * <p/>
+ * This is the main entry point to verify or decrypt a SOAP envelope.
+ * First check if a <code>wsse:Security</code> is available with the
+ * defined actor.
+ *
+ * @param doc the SOAP envelope as {@link Document}
+ * @param actor the engine works on behalf of this <code>actor</code>. Refer
+ * to the SOAP specification about <code>actor</code> or <code>role
+ * </code>
+ * @param requestData the RequestData associated with the request. It should
+ * be able to provide the callback handler, cryptos, etc...
+ * as needed by the processing
+ * @return a result list
+ * @throws WSSecurityException
+ */
+ public List<WSSecurityEngineResult> processSecurityHeader(
+ Document doc, String actor, RequestData requestData
+ ) throws WSSecurityException {
+ if (actor == null) {
+ actor = "";
+ }
+ List<WSSecurityEngineResult> wsResult = null;
+ Element elem = WSSecurityUtil.getSecurityHeader(doc, actor);
+ if (elem != null) {
+ if (doDebug) {
+ log.debug("Processing WS-Security header for '" + actor + "' actor.");
+ }
+ wsResult = processSecurityHeader(elem, requestData);
+ }
+ return wsResult;
+ }
/**
* Process the security header given the <code>wsse:Security</code> DOM
@@ -343,7 +377,8 @@ public class WSSecurityEngine {
*/
public List<WSSecurityEngineResult> processSecurityHeader(
Element securityHeader,
- RequestData requestData) throws WSSecurityException {
+ RequestData requestData
+ ) throws WSSecurityException {
List<WSSecurityEngineResult> returnResults = new ArrayList<WSSecurityEngineResult>();
if (securityHeader == null) {
return returnResults;
@@ -373,19 +408,10 @@ public class WSSecurityEngine {
QName el = new QName(node.getNamespaceURI(), node.getLocalName());
// Check for multiple timestamps
- if (requestData.getWssConfig().isWsiBSPCompliant()) {
- if (foundTimestamp && el.equals(TIMESTAMP)) {
- if (doDebug) {
- log.debug(
- "Failure on processing multiple Timestamps as per the BSP"
- );
- }
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN, "invalidTimestamp"
- );
- } else if (el.equals(TIMESTAMP)) {
- foundTimestamp = true;
- }
+ if (foundTimestamp && el.equals(TIMESTAMP)) {
+ requestData.getBSPEnforcer().handleBSPRule(BSPRule.R3227);
+ } else if (el.equals(TIMESTAMP)) {
+ foundTimestamp = true;
}
//
// Call the processor for this token. After the processor returns,
Added: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/BSPEnforcer.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/BSPEnforcer.java?rev=1376125&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/BSPEnforcer.java (added)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/bsp/BSPEnforcer.java Wed Aug 22 16:25:23 2012
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ws.security.dom.bsp;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.security.common.bsp.BSPRule;
+import org.apache.ws.security.common.ext.WSSecurityException;
+
+/**
+ * An class that enforces Basic Security Profile Rules
+ */
+public class BSPEnforcer {
+
+ private static final Log LOG = LogFactory.getLog(BSPEnforcer.class);
+
+ private List<BSPRule> ignoredBSPRules = Collections.emptyList();
+
+ private boolean disableBSPRules;
+
+ public BSPEnforcer() {
+ // Complete
+ }
+
+ public BSPEnforcer(List<BSPRule> bspRules) {
+ ignoredBSPRules = new ArrayList<BSPRule>(bspRules);
+ }
+
+ public BSPEnforcer(boolean disableBSPRules) {
+ this.disableBSPRules = disableBSPRules;
+ }
+
+ public void handleBSPRule(BSPRule bspRule) throws WSSecurityException {
+ if (disableBSPRules) {
+ return;
+ }
+
+ if (!ignoredBSPRules.contains(bspRule)) {
+ throw new WSSecurityException(
+ "BSP:" + bspRule.name() + ": " + bspRule.getMsg()
+ );
+ } else {
+ LOG.debug("BSP:" + bspRule.name() + ": " + bspRule.getMsg());
+ }
+ }
+
+ public void setIgnoredBSPRules(List<BSPRule> bspRules) {
+ ignoredBSPRules = new ArrayList<BSPRule>(bspRules);
+ }
+
+ public void setDisableBSPRules(boolean disableBSPRules) {
+ this.disableBSPRules = disableBSPRules;
+ }
+
+}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/handler/RequestData.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/handler/RequestData.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/handler/RequestData.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/handler/RequestData.java Wed Aug 22 16:25:23 2012
@@ -22,6 +22,8 @@ package org.apache.ws.security.dom.handl
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -32,7 +34,9 @@ import org.apache.ws.security.dom.SOAPCo
import org.apache.ws.security.dom.WSConstants;
import org.apache.ws.security.dom.WSEncryptionPart;
import org.apache.ws.security.dom.WSSConfig;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.cache.ReplayCache;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.crypto.Crypto;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.dom.message.WSSecHeader;
@@ -85,6 +89,7 @@ public class RequestData {
private ReplayCache timestampReplayCache;
private ReplayCache nonceReplayCache;
private Collection<Pattern> subjectDNPatterns = new ArrayList<Pattern>();
+ private final List<BSPRule> ignoredBSPRules = new LinkedList<BSPRule>();
public void clear() {
soapConstants = null;
@@ -110,6 +115,7 @@ public class RequestData {
timestampReplayCache = null;
nonceReplayCache = null;
subjectDNPatterns.clear();
+ ignoredBSPRules.clear();
}
public Object getMsgContext() {
@@ -520,5 +526,18 @@ public class RequestData {
public Collection<Pattern> getSubjectCertConstraints() {
return subjectDNPatterns;
}
+
+ public void setIgnoredBSPRules(List<BSPRule> bspRules) {
+ ignoredBSPRules.clear();
+ ignoredBSPRules.addAll(bspRules);
+ }
+
+ public List<BSPRule> getIgnoredBSPRules() {
+ return Collections.unmodifiableList(ignoredBSPRules);
+ }
+
+ public BSPEnforcer getBSPEnforcer() {
+ return new BSPEnforcer(ignoredBSPRules);
+ }
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/BinarySecurity.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/BinarySecurity.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/BinarySecurity.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/BinarySecurity.java Wed Aug 22 16:25:23 2012
@@ -23,8 +23,10 @@ import java.io.IOException;
import java.util.Arrays;
import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.util.DOM2Writer;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.util.WSSecurityUtil;
import org.apache.xml.security.utils.Base64;
import org.w3c.dom.Document;
@@ -52,21 +54,11 @@ public class BinarySecurity {
/**
* Constructor.
- *
- * @param elem The BinarySecurityToken element to process
- * @throws WSSecurityException
- */
- public BinarySecurity(Element elem) throws WSSecurityException {
- this(elem, true);
- }
-
- /**
- * Constructor.
* @param elem The BinarySecurityToken element to process
- * @param bspCompliant whether the processing conforms to the BSP spec
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
* @throws WSSecurityException
*/
- public BinarySecurity(Element elem, boolean bspCompliant) throws WSSecurityException {
+ public BinarySecurity(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
element = elem;
QName el = new QName(element.getNamespaceURI(), element.getLocalName());
if (!(el.equals(TOKEN_BST) || el.equals(TOKEN_KI))) {
@@ -77,22 +69,17 @@ public class BinarySecurity {
);
}
String encoding = getEncodingType();
- if (bspCompliant && !BASE64_ENCODING.equals(encoding)) {
- // The EncodingType attribute must be specified, and must be equal to Base64Binary
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "badEncodingType",
- new Object[] {encoding}
- );
+ if (encoding == null || "".equals(encoding)) {
+ bspEnforcer.handleBSPRule(BSPRule.R3029);
+ }
+
+ if (!BASE64_ENCODING.equals(encoding)) {
+ bspEnforcer.handleBSPRule(BSPRule.R3030);
}
String valueType = getValueType();
- if (bspCompliant && (valueType == null || "".equals(valueType))) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "invalidValueType",
- new Object[]{valueType}
- );
+ if (valueType == null || "".equals(valueType)) {
+ bspEnforcer.handleBSPRule(BSPRule.R3031);
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/KerberosSecurity.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/KerberosSecurity.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/KerberosSecurity.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/KerberosSecurity.java Wed Aug 22 16:25:23 2012
@@ -30,6 +30,8 @@ import javax.security.auth.login.LoginCo
import javax.security.auth.login.LoginException;
import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -48,29 +50,14 @@ public class KerberosSecurity extends Bi
* it from the data contained in the element.
*
* @param elem the element containing the Kerberos token data
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
* @throws WSSecurityException
*/
- public KerberosSecurity(Element elem) throws WSSecurityException {
- this(elem, true);
- }
-
- /**
- * This constructor creates a new Kerberos token object and initializes
- * it from the data contained in the element.
- *
- * @param elem the element containing the Kerberos token data
- * @param bspCompliant Whether the token is processed according to the BSP spec
- * @throws WSSecurityException
- */
- public KerberosSecurity(Element elem, boolean bspCompliant) throws WSSecurityException {
- super(elem, bspCompliant);
+ public KerberosSecurity(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
+ super(elem, bspEnforcer);
String valueType = getValueType();
- if (bspCompliant && !WSConstants.WSS_GSS_KRB_V5_AP_REQ.equals(valueType)) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "invalidValueType",
- new Object[]{valueType}
- );
+ if (!WSConstants.WSS_GSS_KRB_V5_AP_REQ.equals(valueType)) {
+ bspEnforcer.handleBSPRule(BSPRule.R6902);
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/PKIPathSecurity.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/PKIPathSecurity.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/PKIPathSecurity.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/PKIPathSecurity.java Wed Aug 22 16:25:23 2012
@@ -20,6 +20,8 @@
package org.apache.ws.security.dom.message.token;
import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.crypto.Crypto;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.w3c.dom.Document;
@@ -37,29 +39,15 @@ public class PKIPathSecurity extends Bin
/**
* Constructor.
- *
- * @param elem The PKIPath element to process
- * @throws WSSecurityException
- */
- public PKIPathSecurity(Element elem) throws WSSecurityException {
- this(elem, true);
- }
-
- /**
- * Constructor.
*
* @param elem The PKIPath element to process
- * @param bspCompliant Whether the token is processed according to the BSP spec
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
* @throws WSSecurityException
*/
- public PKIPathSecurity(Element elem, boolean bspCompliant) throws WSSecurityException {
- super(elem, bspCompliant);
- if (bspCompliant && !PKI_TYPE.equals(getValueType())) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "invalidValueType",
- new Object[]{PKI_TYPE, getValueType()}
- );
+ public PKIPathSecurity(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
+ super(elem, bspEnforcer);
+ if (!PKI_TYPE.equals(getValueType())) {
+ bspEnforcer.handleBSPRule(BSPRule.R5214);
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SecurityTokenReference.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SecurityTokenReference.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SecurityTokenReference.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SecurityTokenReference.java Wed Aug 22 16:25:23 2012
@@ -27,6 +27,7 @@ import org.apache.ws.security.common.cry
import org.apache.ws.security.common.ext.WSPasswordCallback;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.util.DOM2Writer;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.message.CallbackLookup;
import org.apache.ws.security.dom.message.DOMCallbackLookup;
import org.apache.ws.security.dom.util.WSSecurityUtil;
@@ -484,7 +485,7 @@ public class SecurityTokenReference {
String value = elem.getAttribute("ValueType");
if (X509Security.X509_V3_TYPE.equals(value)) {
- X509Security token = new X509Security(elem);
+ X509Security token = new X509Security(elem, new BSPEnforcer(true));
if (token != null) {
X509Certificate cert = token.getX509Certificate(crypto);
return new X509Certificate[]{cert};
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SignatureConfirmation.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SignatureConfirmation.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SignatureConfirmation.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/SignatureConfirmation.java Wed Aug 22 16:25:23 2012
@@ -22,8 +22,10 @@ package org.apache.ws.security.dom.messa
import java.util.Arrays;
import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.util.DOM2Writer;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.util.WSSecurityUtil;
import org.apache.xml.security.exceptions.Base64DecodingException;
import org.apache.xml.security.utils.Base64;
@@ -50,9 +52,16 @@ public class SignatureConfirmation {
*
* @param elem the <code>wsse11:SignatureCOnfirmation</code> element that
* contains the confirmation data
+ * @param bspEnforcer a BSPEnforcer instance used to enforce BSP rules
*/
- public SignatureConfirmation(Element elem) throws WSSecurityException {
+ public SignatureConfirmation(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
element = elem;
+
+ String id = getID();
+ if (id == null || "".equals(id)) {
+ bspEnforcer.handleBSPRule(BSPRule.R5441);
+ }
+
String sv = element.getAttribute(SC_VALUE_ATTR);
if (sv != null) {
try {
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/Timestamp.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/Timestamp.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/Timestamp.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/Timestamp.java Wed Aug 22 16:25:23 2012
@@ -19,9 +19,22 @@
package org.apache.ws.security.dom.message.token;
-import org.apache.ws.security.dom.WSConstants;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.util.DOM2Writer;
+import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.dom.WSSConfig;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.util.WSSecurityUtil;
import org.apache.ws.security.dom.util.XmlSchemaDateFormat;
import org.w3c.dom.Document;
@@ -29,14 +42,6 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
/**
* Timestamp according to SOAP Message Security 1.0,
* chapter 10 / appendix A.2
@@ -59,20 +64,9 @@ public class Timestamp {
*
* @param timestampElement the <code>wsu:Timestamp</code> element that
* contains the timestamp data
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
*/
- public Timestamp(Element timestampElement) throws WSSecurityException {
- this(timestampElement, true);
- }
-
- /**
- * Constructs a <code>Timestamp</code> object and parses the
- * <code>wsu:Timestamp</code> element to initialize it.
- *
- * @param timestampElement the <code>wsu:Timestamp</code> element that
- * contains the timestamp data
- * @param bspCompliant whether the Timestamp processing complies with the BSP spec
- */
- public Timestamp(Element timestampElement, boolean bspCompliant) throws WSSecurityException {
+ public Timestamp(Element timestampElement, BSPEnforcer bspEnforcer) throws WSSecurityException {
element = timestampElement;
customElements = new ArrayList<Element>();
@@ -90,82 +84,85 @@ public class Timestamp {
WSConstants.WSU_NS.equals(currentChild.getNamespaceURI())) {
if (strCreated == null) {
String valueType = currentChildElement.getAttribute("ValueType");
- if (bspCompliant && valueType != null && !"".equals(valueType)) {
+ if (valueType != null && !"".equals(valueType)) {
// We can't have a ValueType attribute as per the BSP spec
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R3225);
}
strCreated = ((Text)currentChildElement.getFirstChild()).getData();
} else {
// Test for multiple Created elements
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R3203);
}
} else if (WSConstants.EXPIRES_LN.equals(currentChild.getLocalName()) &&
WSConstants.WSU_NS.equals(currentChild.getNamespaceURI())) {
- if (strExpires != null || (bspCompliant && strCreated == null)) {
- //
- // Created must appear before Expires and we can't have multiple Expires
- // elements
- //
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
+ if (strCreated == null) {
+ // Created must appear before Expires
+ bspEnforcer.handleBSPRule(BSPRule.R3221);
+ }
+ if (strExpires != null ) {
+ // We can't have multiple Expires elements
+ bspEnforcer.handleBSPRule(BSPRule.R3224);
} else {
String valueType = currentChildElement.getAttribute("ValueType");
- if (bspCompliant && valueType != null && !"".equals(valueType)) {
+ if (valueType != null && !"".equals(valueType)) {
// We can't have a ValueType attribute as per the BSP spec
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R3226);
}
strExpires = ((Text)currentChildElement.getFirstChild()).getData();
}
} else {
- if (bspCompliant) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
- }
+ bspEnforcer.handleBSPRule(BSPRule.R3222);
customElements.add(currentChildElement);
}
}
}
// We must have a Created element
- if (bspCompliant && strCreated == null) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp"
- );
+ if (strCreated == null) {
+ bspEnforcer.handleBSPRule(BSPRule.R3203);
}
// Parse the dates
- DateFormat zulu = new XmlSchemaDateFormat();
- if (bspCompliant) {
- zulu.setLenient(false);
+ if (strCreated != null) {
+ XMLGregorianCalendar createdCalendar = null;
+ try {
+ createdCalendar =
+ WSSConfig.datatypeFactory.newXMLGregorianCalendar(strCreated);
+ } catch (IllegalArgumentException e) {
+ throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
+ }
+
+ if (createdCalendar.getFractionalSecond().scale() > 3) {
+ bspEnforcer.handleBSPRule(BSPRule.R3220);
+ }
+ if (createdCalendar.getSecond() > 59) {
+ bspEnforcer.handleBSPRule(BSPRule.R3213);
+ }
+ if (createdCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
+ bspEnforcer.handleBSPRule(BSPRule.R3217);
+ }
+ createdDate = createdCalendar.toGregorianCalendar().getTime();
}
- try {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Current time: " + zulu.format(new Date()));
+
+ if (strExpires != null) {
+ XMLGregorianCalendar expiresCalendar = null;
+ try {
+ expiresCalendar =
+ WSSConfig.datatypeFactory.newXMLGregorianCalendar(strExpires);
+ } catch (IllegalArgumentException e) {
+ throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
}
- if (strCreated != null) {
- createdDate = zulu.parse(strCreated);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Timestamp created: " + zulu.format(createdDate));
- }
+
+ if (expiresCalendar.getFractionalSecond().scale() > 3) {
+ bspEnforcer.handleBSPRule(BSPRule.R3229);
}
- if (strExpires != null) {
- expiresDate = zulu.parse(strExpires);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Timestamp expires: " + zulu.format(expiresDate));
- }
+ if (expiresCalendar.getSecond() > 59) {
+ bspEnforcer.handleBSPRule(BSPRule.R3215);
}
- } catch (ParseException e) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "invalidTimestamp", e
- );
+ if (expiresCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
+ bspEnforcer.handleBSPRule(BSPRule.R3223);
+ }
+ expiresDate = expiresCalendar.toGregorianCalendar().getTime();
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/UsernameToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/UsernameToken.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/UsernameToken.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/UsernameToken.java Wed Aug 22 16:25:23 2012
@@ -21,9 +21,11 @@ package org.apache.ws.security.dom.messa
import org.apache.ws.security.dom.WSConstants;
import org.apache.ws.security.dom.WSUsernameTokenPrincipal;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSPasswordCallback;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.common.util.DOM2Writer;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.handler.RequestData;
import org.apache.ws.security.dom.util.WSSecurityUtil;
import org.apache.ws.security.dom.util.XmlSchemaDateFormat;
@@ -82,7 +84,6 @@ public class UsernameToken {
protected boolean hashed = true;
private String rawPassword; // enhancement by Alberto Coletti
private boolean passwordsAreEncoded = false;
- private boolean bspCompliantDerivedKey = true;
/**
* Constructs a <code>UsernameToken</code> object and parses the
@@ -90,27 +91,15 @@ public class UsernameToken {
*
* @param elem the <code>wsse:UsernameToken</code> element that contains
* the UsernameToken data
- * @throws WSSecurityException
- */
- public UsernameToken(Element elem) throws WSSecurityException {
- this (elem, false, true);
- }
-
- /**
- * Constructs a <code>UsernameToken</code> object and parses the
- * <code>wsse:UsernameToken</code> element to initialize it.
- *
- * @param elem the <code>wsse:UsernameToken</code> element that contains
- * the UsernameToken data
* @param allowNamespaceQualifiedPasswordTypes whether to allow (wsse)
* namespace qualified password types or not (for interop with WCF)
- * @param bspCompliant whether the UsernameToken processing complies with the BSP spec
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
* @throws WSSecurityException
*/
public UsernameToken(
Element elem,
boolean allowNamespaceQualifiedPasswordTypes,
- boolean bspCompliant
+ BSPEnforcer bspEnforcer
) throws WSSecurityException {
element = elem;
QName el = new QName(element.getNamespaceURI(), element.getLocalName());
@@ -151,9 +140,7 @@ public class UsernameToken {
);
}
- if (bspCompliant) {
- checkBSPCompliance();
- }
+ checkBSPCompliance(bspEnforcer);
hashed = false;
if (elementSalt != null) {
@@ -199,7 +186,8 @@ public class UsernameToken {
} else {
throw new WSSecurityException(
WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "badUsernameToken"
+ "badUsernameToken",
+ "The Password Type is not allowed to be namespace qualified"
);
}
}
@@ -830,11 +818,26 @@ public class UsernameToken {
* @return Returns the derived key as a byte array
* @throws WSSecurityException
*/
- public byte[] getDerivedKey() throws WSSecurityException {
- if (rawPassword == null || !bspCompliantDerivedKey) {
- LOG.debug("The raw password was null or the Username Token is not BSP compliant");
+ public byte[] getDerivedKey(BSPEnforcer bspEnforcer) throws WSSecurityException {
+ if (rawPassword == null) {
+ LOG.debug("The raw password was null");
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
+
+ if (elementSalt == null) {
+ // We must have a salt element to use this token for a derived key
+ bspEnforcer.handleBSPRule(BSPRule.R4217);
+ }
+ if (elementIteration == null) {
+ // we must have an iteration element to use this token for a derived key
+ bspEnforcer.handleBSPRule(BSPRule.R4218);
+ } else {
+ String iter = nodeString(elementIteration);
+ if (iter == null || Integer.parseInt(iter) < 1000) {
+ bspEnforcer.handleBSPRule(BSPRule.R4218);
+ }
+ }
+
int iteration = getIteration();
byte[] salt = getSalt();
if (passwordsAreEncoded) {
@@ -1038,7 +1041,7 @@ public class UsernameToken {
* A method to check that the UsernameToken is compliant with the BSP spec.
* @throws WSSecurityException
*/
- private void checkBSPCompliance() throws WSSecurityException {
+ private void checkBSPCompliance(BSPEnforcer bspEnforcer) throws WSSecurityException {
List<Element> passwordElements =
WSSecurityUtil.getDirectChildElements(
element, WSConstants.PASSWORD_LN, WSConstants.WSSE_NS
@@ -1048,9 +1051,7 @@ public class UsernameToken {
if (LOG.isDebugEnabled()) {
LOG.debug("The Username Token had more than one password element");
}
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN, "badUsernameToken"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R4222);
}
// We must have a password type
@@ -1061,23 +1062,7 @@ public class UsernameToken {
if (LOG.isDebugEnabled()) {
LOG.debug("The Username Token password does not have a Type attribute");
}
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN, "badUsernameToken"
- );
- }
- }
-
- if (elementSalt == null) {
- // We must have a salt element to use this token for a derived key
- bspCompliantDerivedKey = false;
- }
- if (elementIteration == null) {
- // we must have an iteration element to use this token for a derived key
- bspCompliantDerivedKey = false;
- } else {
- String iter = nodeString(elementIteration);
- if (iter == null || Integer.parseInt(iter) < 1000) {
- bspCompliantDerivedKey = false;
+ bspEnforcer.handleBSPRule(BSPRule.R4201);
}
}
@@ -1090,9 +1075,7 @@ public class UsernameToken {
if (LOG.isDebugEnabled()) {
LOG.debug("The Username Token has more than one created element");
}
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN, "badUsernameToken"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R4223);
}
List<Element> nonceElements =
@@ -1104,24 +1087,20 @@ public class UsernameToken {
if (LOG.isDebugEnabled()) {
LOG.debug("The Username Token has more than one nonce element");
}
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN, "badUsernameToken"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R4225);
}
if (nonceElements.size() == 1) {
Element nonce = nonceElements.get(0);
String encodingType = nonce.getAttribute("EncodingType");
// Encoding Type must be equal to Base64Binary
- if (encodingType == null || "".equals(encodingType)
- || !BinarySecurity.BASE64_ENCODING.equals(encodingType)) {
+ if (encodingType == null || "".equals(encodingType)) {
+ bspEnforcer.handleBSPRule(BSPRule.R4220);
+ } else if (!BinarySecurity.BASE64_ENCODING.equals(encodingType)) {
if (LOG.isDebugEnabled()) {
LOG.debug("The Username Token's nonce element has a bad encoding type");
}
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "badUsernameToken"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R4221);
}
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/X509Security.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/X509Security.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/X509Security.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/message/token/X509Security.java Wed Aug 22 16:25:23 2012
@@ -20,6 +20,8 @@
package org.apache.ws.security.dom.message.token;
import org.apache.ws.security.dom.WSConstants;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.crypto.Crypto;
import org.apache.ws.security.common.ext.WSSecurityException;
import org.w3c.dom.Document;
@@ -50,29 +52,14 @@ public class X509Security extends Binary
* it from the data contained in the element.
*
* @param elem the element containing the X509 certificate data
+ * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules
* @throws WSSecurityException
*/
- public X509Security(Element elem) throws WSSecurityException {
- this(elem, true);
- }
-
- /**
- * This constructor creates a new X509 certificate object and initializes
- * it from the data contained in the element.
- *
- * @param elem the element containing the X509 certificate data
- * @param bspCompliant Whether the token is processed according to the BSP spec
- * @throws WSSecurityException
- */
- public X509Security(Element elem, boolean bspCompliant) throws WSSecurityException {
- super(elem, bspCompliant);
+ public X509Security(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
+ super(elem, bspEnforcer);
String valueType = getValueType();
- if (bspCompliant && !X509_V3_TYPE.equals(valueType)) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN,
- "invalidValueType",
- new Object[]{valueType}
- );
+ if (!X509_V3_TYPE.equals(valueType)) {
+ bspEnforcer.handleBSPRule(BSPRule.R3033);
}
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/BinarySecurityTokenProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/BinarySecurityTokenProcessor.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/BinarySecurityTokenProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/BinarySecurityTokenProcessor.java Wed Aug 22 16:25:23 2012
@@ -19,13 +19,17 @@
package org.apache.ws.security.dom.processor;
+import java.security.cert.X509Certificate;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.security.common.crypto.Crypto;
+import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.dom.SAMLTokenPrincipal;
import org.apache.ws.security.dom.WSConstants;
import org.apache.ws.security.dom.WSDocInfo;
-import org.apache.ws.security.dom.WSSConfig;
import org.apache.ws.security.dom.WSSecurityEngineResult;
-import org.apache.ws.security.common.crypto.Crypto;
-import org.apache.ws.security.common.ext.WSSecurityException;
import org.apache.ws.security.dom.handler.RequestData;
import org.apache.ws.security.dom.message.token.BinarySecurity;
import org.apache.ws.security.dom.message.token.KerberosSecurity;
@@ -35,10 +39,6 @@ import org.apache.ws.security.dom.valida
import org.apache.ws.security.dom.validate.Validator;
import org.w3c.dom.Element;
-import java.security.cert.X509Certificate;
-import java.util.List;
-import javax.xml.namespace.QName;
-
/**
* Processor implementation to handle wsse:BinarySecurityToken elements
*/
@@ -66,7 +66,7 @@ public class BinarySecurityTokenProcesso
}
}
- BinarySecurity token = createSecurityToken(elem, data.getWssConfig());
+ BinarySecurity token = createSecurityToken(elem, data);
X509Certificate[] certs = null;
Validator validator = data.getValidator(new QName(elem.getNamespaceURI(),
elem.getLocalName()));
@@ -135,24 +135,24 @@ public class BinarySecurityTokenProcesso
*
* @param element The XML element that contains either a <code>BinarySecurityToken
* </code> or a <code>PKIPath</code> element.
- * @param config A WSSConfig instance
+ * @param data A RequestData instance
* @return a BinarySecurity token element
* @throws WSSecurityException
*/
private BinarySecurity createSecurityToken(
Element element,
- WSSConfig config
+ RequestData data
) throws WSSecurityException {
String type = element.getAttribute("ValueType");
BinarySecurity token = null;
if (X509Security.X509_V3_TYPE.equals(type)) {
- token = new X509Security(element, config.isWsiBSPCompliant());
+ token = new X509Security(element, data.getBSPEnforcer());
} else if (PKIPathSecurity.getType().equals(type)) {
- token = new PKIPathSecurity(element, config.isWsiBSPCompliant());
+ token = new PKIPathSecurity(element, data.getBSPEnforcer());
} else if (KerberosSecurity.isKerberosToken(type)) {
- token = new KerberosSecurity(element, config.isWsiBSPCompliant());
+ token = new KerberosSecurity(element, data.getBSPEnforcer());
} else {
- token = new BinarySecurity(element, config.isWsiBSPCompliant());
+ token = new BinarySecurity(element, data.getBSPEnforcer());
}
return token;
}
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedDataProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedDataProcessor.java?rev=1376125&r1=1376124&r2=1376125&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedDataProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/ws/security/dom/processor/EncryptedDataProcessor.java Wed Aug 22 16:25:23 2012
@@ -24,7 +24,9 @@ import org.apache.ws.security.dom.WSData
import org.apache.ws.security.dom.WSDocInfo;
import org.apache.ws.security.dom.WSSConfig;
import org.apache.ws.security.dom.WSSecurityEngineResult;
+import org.apache.ws.security.common.bsp.BSPRule;
import org.apache.ws.security.common.ext.WSSecurityException;
+import org.apache.ws.security.dom.bsp.BSPEnforcer;
import org.apache.ws.security.dom.handler.RequestData;
import org.apache.ws.security.dom.str.STRParser;
import org.apache.ws.security.dom.str.SecurityTokenRefSTRParser;
@@ -73,7 +75,7 @@ public class EncryptedDataProcessor impl
String symEncAlgo = X509Util.getEncAlgo(elem);
// Check BSP compliance
if (request.getWssConfig().isWsiBSPCompliant()) {
- checkBSPCompliance(symEncAlgo);
+ checkBSPCompliance(symEncAlgo, request.getBSPEnforcer());
}
// Get the Key either via a SecurityTokenReference or an EncryptedKey
@@ -194,13 +196,11 @@ public class EncryptedDataProcessor impl
* @throws WSSecurityException
*/
private static void checkBSPCompliance(
- String encAlgo
+ String encAlgo, BSPEnforcer bspEnforcer
) throws WSSecurityException {
// EncryptionAlgorithm cannot be null
if (encAlgo == null) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo"
- );
+ bspEnforcer.handleBSPRule(BSPRule.R5601);
}
// EncryptionAlgorithm must be 3DES, or AES128, or AES256
if (!WSConstants.TRIPLE_DES.equals(encAlgo)
@@ -208,9 +208,7 @@ public class EncryptedDataProcessor impl
&& !WSConstants.AES_128_GCM.equals(encAlgo)
&& !WSConstants.AES_256.equals(encAlgo)
&& !WSConstants.AES_256_GCM.equals(encAlgo)) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.INVALID_SECURITY, "badEncAlgo", new Object[]{encAlgo}
- );
+ bspEnforcer.handleBSPRule(BSPRule.R5620);
}
}