cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: Fixing NPE in REST STS implementation + got it to work on Tomcat
Date Fri, 12 Feb 2016 11:44:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f2f8b95ad -> 97f3ac75f


Fixing NPE in REST STS implementation + got it to work on Tomcat


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/97f3ac75
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/97f3ac75
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/97f3ac75

Branch: refs/heads/master
Commit: 97f3ac75fd9fc105c346acfc48a646d5088a2127
Parents: f2f8b95
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Feb 12 11:44:12 2016 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Feb 12 11:44:12 2016 +0000

----------------------------------------------------------------------
 .../sts/rest/RESTSecurityTokenServiceImpl.java  | 23 ++++++++++++++++----
 .../cxf/systest/sts/rest/cxf-rest-sts.xml       |  8 -------
 2 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/97f3ac75/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
index 6d283a5..dd01d0a 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
@@ -81,6 +81,9 @@ public class RESTSecurityTokenServiceImpl extends SecurityTokenServiceImpl
imple
 
     @Context
     private MessageContext messageContext;
+    
+    @Context
+    private javax.ws.rs.core.SecurityContext securityContext;
 
     private Map<String, String> claimTypeMap = DEFAULT_CLAIM_TYPE_MAP;
 
@@ -297,12 +300,24 @@ public class RESTSecurityTokenServiceImpl extends SecurityTokenServiceImpl
imple
     
     @Override
     protected Principal getPrincipal() {
+        // Try JAX-RS SecurityContext first
+        if (securityContext != null && securityContext.getUserPrincipal() != null)
{
+            return securityContext.getUserPrincipal();
+        }
+        
+        // Then try the CXF SecurityContext
         SecurityContext sc = (SecurityContext)messageContext.get(SecurityContext.class);
-        if (sc == null || sc.getUserPrincipal() == null) {
-            // Get the TLS client principal if no security context is set up
-            return getTLSClientCertificate().getSubjectX500Principal();
+        if (sc != null && sc.getUserPrincipal() != null) {
+            return sc.getUserPrincipal();
         }
-        return messageContext.getSecurityContext().getUserPrincipal();
+        
+        // Get the TLS client principal if no security context is set up
+        X509Certificate clientCert = getTLSClientCertificate();
+        if (clientCert != null) {
+            return clientCert.getSubjectX500Principal();
+        }
+        
+        return null;
     }
     
     private X509Certificate getTLSClientCertificate() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/97f3ac75/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/rest/cxf-rest-sts.xml
----------------------------------------------------------------------
diff --git a/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/rest/cxf-rest-sts.xml
b/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/rest/cxf-rest-sts.xml
index 6736f10..a7c1156 100644
--- a/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/rest/cxf-rest-sts.xml
+++ b/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/rest/cxf-rest-sts.xml
@@ -113,14 +113,6 @@
         <property name="renewOperation" ref="transportRenewDelegate"/>
     </bean>
     
-    <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
-        <property name="depthProperties">
-            <bean class="org.apache.cxf.staxutils.DocumentDepthProperties">
-                <property name="innerElementCountThreshold" value="500" />
-            </bean>
-        </property>
-    </bean>
-
     <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
/>
     
     <jaxrs:server id="stsRESTService"


Mime
View raw message