Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AF5C1200C4C for ; Tue, 4 Apr 2017 11:15:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id ADD65160B90; Tue, 4 Apr 2017 09:15:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5940A160B81 for ; Tue, 4 Apr 2017 11:15:39 +0200 (CEST) Received: (qmail 5871 invoked by uid 500); 4 Apr 2017 09:15:38 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 5839 invoked by uid 99); 4 Apr 2017 09:15:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Apr 2017 09:15:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3072EDFE59; Tue, 4 Apr 2017 09:15:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Tue, 04 Apr 2017 09:15:38 -0000 Message-Id: <05c2f3d3e62340ce982a44076abdc937@git.apache.org> In-Reply-To: <9544f7f2ac3241e6843dd9c5c8bc1ed6@git.apache.org> References: <9544f7f2ac3241e6843dd9c5c8bc1ed6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] cxf git commit: Disable taking a UsernameToken with no password as the security context principal archived-at: Tue, 04 Apr 2017 09:15:40 -0000 Disable taking a UsernameToken with no password as the security context principal # Conflicts: # rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java # rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java # rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java # rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/786604cf Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/786604cf Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/786604cf Branch: refs/heads/3.1.x-fixes Commit: 786604cf247878b8625b51d62e749caaf1559006 Parents: 03f4a10 Author: Colm O hEigeartaigh Authored: Tue Apr 4 08:36:35 2017 +0100 Committer: Colm O hEigeartaigh Committed: Tue Apr 4 08:37:18 2017 +0100 ---------------------------------------------------------------------- .../cxf/rt/security/SecurityConstants.java | 12 ++++++ .../cxf/rt/security/utils/SecurityUtils.java | 5 +++ .../DefaultWSS4JSecurityContextCreator.java | 18 +++++++- .../wss4j/StaxSecurityContextInInterceptor.java | 44 +++++++++++++++++--- .../cxf/systest/wssec/examples/ut/server.xml | 1 + .../systest/wssec/examples/ut/stax-server.xml | 1 + .../apache/cxf/systest/ws/ut/server-derived.xml | 7 ++++ .../org/apache/cxf/systest/ws/ut/server.xml | 1 + .../apache/cxf/systest/ws/ut/stax-server.xml | 1 + 9 files changed, 84 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java ---------------------------------------------------------------------- diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java b/rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java index 5ee526b..80cf1bd 100644 --- a/rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java +++ b/rt/security/src/main/java/org/apache/cxf/rt/security/SecurityConstants.java @@ -158,6 +158,13 @@ public class SecurityConstants { "security.enable.unsigned-saml-assertion.principal"; /** + * Whether to allow UsernameTokens with no password to be used as SecurityContext Principals. + * The default is false. + */ + public static final String ENABLE_UT_NOPASSWORD_PRINCIPAL = + "security.enable.ut-no-password.principal"; + + /** * Whether to validate the SubjectConfirmation requirements of a received SAML Token * (sender-vouches or holder-of-key). The default is true. */ @@ -345,7 +352,12 @@ public class SecurityConstants { CALLBACK_HANDLER, SAML_CALLBACK_HANDLER, SIGNATURE_PROPERTIES, SIGNATURE_CRYPTO, ENCRYPT_PROPERTIES, ENCRYPT_CRYPTO, ENCRYPT_CERT, ENABLE_REVOCATION, SUBJECT_CERT_CONSTRAINTS, ENABLE_UNSIGNED_SAML_ASSERTION_PRINCIPAL, +<<<<<<< HEAD AUDIENCE_RESTRICTION_VALIDATION, SAML_ROLE_ATTRIBUTENAME, +======= + ENABLE_UT_NOPASSWORD_PRINCIPAL, + AUDIENCE_RESTRICTION_VALIDATION, SAML_ROLE_ATTRIBUTENAME, +>>>>>>> b77e43f... Disable taking a UsernameToken with no password as the security context principal ENABLE_UNSIGNED_SAML_ASSERTION_PRINCIPAL, SC_FROM_JAAS_SUBJECT, STS_TOKEN_USE_CERT_FOR_KEYINFO, STS_TOKEN_DO_CANCEL, CACHE_ISSUED_TOKEN_IN_ENDPOINT, DISABLE_STS_CLIENT_WSMEX_CALL_USING_EPR_ADDRESS, STS_TOKEN_CRYPTO, http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java ---------------------------------------------------------------------- diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java b/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java index b679edb..a0419de 100644 --- a/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java +++ b/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java @@ -183,11 +183,16 @@ public final class SecurityUtils { * values. If none is configured, then the defaultValue parameter is returned. */ public static boolean getSecurityPropertyBoolean(String property, Message message, boolean defaultValue) { +<<<<<<< HEAD Object value = message.getContextualProperty(property); if (value == null) { value = message.getContextualProperty("ws-" + property); } +======= + Object value = getSecurityPropertyValue(property, message); + +>>>>>>> b77e43f... Disable taking a UsernameToken with no password as the security context principal if (value != null) { return PropertyUtils.isTrue(value); } http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java index 5a832ef..cd15d46 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/DefaultWSS4JSecurityContextCreator.java @@ -66,6 +66,7 @@ public class DefaultWSS4JSecurityContextCreator implements WSS4JSecurityContextC * Create a SecurityContext and store it on the SoapMessage parameter */ public void createSecurityContext(SoapMessage msg, WSHandlerResult handlerResult) { +<<<<<<< HEAD String allowUnsigned = (String)SecurityUtils.getSecurityPropertyValue( @@ -74,6 +75,20 @@ public class DefaultWSS4JSecurityContextCreator implements WSS4JSecurityContextC boolean allowUnsignedSamlPrincipals = Boolean.parseBoolean(allowUnsigned); boolean useJAASSubject = true; String useJAASSubjectStr = +======= + + boolean allowUnsignedSamlPrincipals = + SecurityUtils.getSecurityPropertyBoolean( + SecurityConstants.ENABLE_UNSIGNED_SAML_ASSERTION_PRINCIPAL, msg, false + ); + boolean allowUTNoPassword = + SecurityUtils.getSecurityPropertyBoolean( + SecurityConstants.ENABLE_UT_NOPASSWORD_PRINCIPAL, msg, false + ); + + boolean useJAASSubject = true; + String useJAASSubjectStr = +>>>>>>> b77e43f... Disable taking a UsernameToken with no password as the security context principal (String)SecurityUtils.getSecurityPropertyValue(SecurityConstants.SC_FROM_JAAS_SUBJECT, msg); if (useJAASSubjectStr != null) { useJAASSubject = Boolean.parseBoolean(useJAASSubjectStr); @@ -82,7 +97,8 @@ public class DefaultWSS4JSecurityContextCreator implements WSS4JSecurityContextC // Now go through the results in a certain order to set up a security context. Highest priority is first. Map> actionResults = handlerResult.getActionResults(); for (Integer resultPriority : securityPriorities) { - if (resultPriority == WSConstants.ST_UNSIGNED && !allowUnsignedSamlPrincipals) { + if ((resultPriority == WSConstants.ST_UNSIGNED && !allowUnsignedSamlPrincipals) + || (resultPriority == WSConstants.UT_NOPASSWORD && !allowUTNoPassword)) { continue; } http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java index c20105a..82cc6a1 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSecurityContextInInterceptor.java @@ -31,6 +31,7 @@ import org.apache.cxf.binding.soap.SoapVersion; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.interceptor.security.DefaultSecurityContext; import org.apache.cxf.interceptor.security.RolePrefixSecurityContextImpl; +import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.apache.cxf.rt.security.claims.ClaimCollection; @@ -101,7 +102,7 @@ public class StaxSecurityContextInInterceptor extends AbstractPhaseInterceptor incomingSecurityEventList, - Event desiredEvent) throws XMLSecurityException { + Event desiredEvent, + Message msg) throws XMLSecurityException { for (SecurityEvent event : incomingSecurityEventList) { if (desiredEvent == event.getSecurityEventType()) { - if (event.getSecurityEventType() == WSSecurityEventConstants.USERNAME_TOKEN) { + if (event.getSecurityEventType() == WSSecurityEventConstants.USERNAME_TOKEN + && isUsernameTokenEventAllowed((UsernameTokenSecurityEvent)event, msg)) { return ((UsernameTokenSecurityEvent)event).getSecurityToken(); } else if (event.getSecurityEventType() == WSSecurityEventConstants.SAML_TOKEN - && isSamlEventSigned((SamlTokenSecurityEvent)event)) { + && isSamlEventAllowed((SamlTokenSecurityEvent)event, msg)) { return ((SamlTokenSecurityEvent)event).getSecurityToken(); } else if (event.getSecurityEventType() == WSSecurityEventConstants.X509Token && isUsedForPublicKeySignature(((X509TokenSecurityEvent)event).getSecurityToken())) { @@ -209,6 +212,7 @@ public class StaxSecurityContextInInterceptor extends AbstractPhaseInterceptor 0); } +<<<<<<< HEAD private boolean isSamlEventSigned(SamlTokenSecurityEvent event) { if (event == null) { @@ -216,8 +220,38 @@ public class StaxSecurityContextInInterceptor extends AbstractPhaseInterceptor>>>>>> b77e43f... Disable taking a UsernameToken with no password as the security context principal && event.getSecurityToken().getSamlAssertionWrapper() != null - && event.getSecurityToken().getSamlAssertionWrapper().isSigned(); + && (allowUnsignedSamlPrincipals || event.getSecurityToken().getSamlAssertionWrapper().isSigned()); + } + + private boolean isUsernameTokenEventAllowed(UsernameTokenSecurityEvent event, Message msg) { + if (event == null) { + return false; + } + + boolean allowUTNoPassword = + SecurityUtils.getSecurityPropertyBoolean( + SecurityConstants.ENABLE_UT_NOPASSWORD_PRINCIPAL, msg, false + ); + + // The "no password" case is not allowed by default + return event.getSecurityToken() != null + && (allowUTNoPassword || event.getSecurityToken().getPassword() != null); } private SecurityContext createSecurityContext(final Principal p) { http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/server.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/server.xml b/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/server.xml index 0c6a11e..3491d4d 100644 --- a/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/server.xml +++ b/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/server.xml @@ -32,6 +32,7 @@ + http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/stax-server.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/stax-server.xml b/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/stax-server.xml index aa64f48..2d258d2 100644 --- a/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/stax-server.xml +++ b/systests/ws-security-examples/src/test/resources/org/apache/cxf/systest/wssec/examples/ut/stax-server.xml @@ -33,6 +33,7 @@ + http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server-derived.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server-derived.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server-derived.xml index c114b8e..12e6d69 100644 --- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server-derived.xml +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server-derived.xml @@ -28,26 +28,31 @@ + + + + + @@ -55,6 +60,7 @@ + @@ -62,6 +68,7 @@ + http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml index 8084a66..0da6275 100644 --- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml @@ -70,6 +70,7 @@ + http://git-wip-us.apache.org/repos/asf/cxf/blob/786604cf/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/stax-server.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/stax-server.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/stax-server.xml index 3a32e5e..bb829a2 100644 --- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/stax-server.xml +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/stax-server.xml @@ -75,6 +75,7 @@ +