cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/4] cxf git commit: Strip WebServiceContext from the RequestParser + RealmParser
Date Tue, 02 Feb 2016 16:54:15 GMT
Repository: cxf
Updated Branches:
  refs/heads/master cf9ab27a8 -> 53a462058


Strip WebServiceContext from the RequestParser + RealmParser


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

Branch: refs/heads/master
Commit: 3b2f2ed2db01f05fa9b648693ce33978ccc8ede8
Parents: cf9ab27
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue Feb 2 15:33:22 2016 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue Feb 2 15:33:22 2016 +0000

----------------------------------------------------------------------
 .../java/org/apache/cxf/sts/RealmParser.java    |  6 ++--
 .../cxf/sts/operation/AbstractOperation.java    |  5 +--
 .../cxf/sts/operation/TokenRenewOperation.java  |  2 +-
 .../sts/operation/TokenValidateOperation.java   |  2 +-
 .../apache/cxf/sts/request/RequestParser.java   | 32 +++++++++-----------
 .../cxf/sts/operation/CustomRealmParser.java    |  6 ++--
 .../cxf/sts/request/RequestParserUnitTest.java  | 10 ++----
 .../cxf/systest/sts/realms/URLRealmParser.java  |  6 ++--
 .../cxf/systest/sts/common/UriRealmParser.java  |  7 ++---
 9 files changed, 34 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/main/java/org/apache/cxf/sts/RealmParser.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/RealmParser.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/RealmParser.java
index 75a3a4a..a597ea4 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/RealmParser.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/RealmParser.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cxf.sts;
 
-import javax.xml.ws.WebServiceContext;
+import java.util.Map;
 
 import org.apache.cxf.ws.security.sts.provider.STSException;
 
@@ -28,8 +28,8 @@ import org.apache.cxf.ws.security.sts.provider.STSException;
 public interface RealmParser {
     
     /**
-     * Return the realm of the current request given a WebServiceContext object
+     * Return the realm of the current request given a message context map
      */
-    String parseRealm(WebServiceContext context) throws STSException;
+    String parseRealm(Map<String, Object> messageContext) throws STSException;
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
index b6a827b..c88471e 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
@@ -181,7 +181,8 @@ public abstract class AbstractOperation {
         stsProperties.configureProperties();
         
         RequestParser requestParser = new RequestParser();
-        return requestParser.parseRequest(request, context, stsProperties, claimsManager.getClaimParsers());
+        return requestParser.parseRequest(request, context.getMessageContext(), stsProperties,

+                                          claimsManager.getClaimParsers());
     }
     
     /**
@@ -407,7 +408,7 @@ public abstract class AbstractOperation {
         // Get the realm of the request
         if (stsProperties.getRealmParser() != null) {
             RealmParser realmParser = stsProperties.getRealmParser();
-            String realm = realmParser.parseRealm(context);
+            String realm = realmParser.parseRealm(context.getMessageContext());
             providerParameters.setRealm(realm);
         }
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenRenewOperation.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenRenewOperation.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenRenewOperation.java
index 312631d..c0da0a8 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenRenewOperation.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenRenewOperation.java
@@ -105,7 +105,7 @@ public class TokenRenewOperation extends AbstractOperation implements
RenewOpera
             String realm = null;
             if (stsProperties.getRealmParser() != null) {
                 RealmParser realmParser = stsProperties.getRealmParser();
-                realm = realmParser.parseRealm(context);
+                realm = realmParser.parseRealm(context.getMessageContext());
             }
             renewerParameters.setRealm(realm);
             

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
index e84fe2e..49cfb74 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
@@ -101,7 +101,7 @@ public class TokenValidateOperation extends AbstractOperation implements
Validat
             String realm = null;
             if (stsProperties.getRealmParser() != null) {
                 RealmParser realmParser = stsProperties.getRealmParser();
-                realm = realmParser.parseRealm(context);
+                realm = realmParser.parseRealm(context.getMessageContext());
             }
             validatorParameters.setRealm(realm);
             

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/main/java/org/apache/cxf/sts/request/RequestParser.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/request/RequestParser.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/request/RequestParser.java
index ae1441e..d3e58d5 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/request/RequestParser.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/request/RequestParser.java
@@ -30,6 +30,7 @@ import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -40,8 +41,6 @@ import javax.xml.crypto.dsig.keyinfo.KeyInfo;
 import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
 import javax.xml.crypto.dsig.keyinfo.KeyValue;
 import javax.xml.crypto.dsig.keyinfo.X509Data;
-import javax.xml.ws.WebServiceContext;
-import javax.xml.ws.handler.MessageContext;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -97,7 +96,7 @@ public class RequestParser {
     private static final Logger LOG = LogUtils.getL7dLogger(RequestParser.class);
     
     public RequestRequirements parseRequest(
-        RequestSecurityTokenType request, WebServiceContext wsContext, STSPropertiesMBean
stsProperties, 
+        RequestSecurityTokenType request, Map<String, Object> messageContext, STSPropertiesMBean
stsProperties, 
         List<ClaimsParser> claimsParsers
     ) throws STSException {
         LOG.fine("Parsing RequestSecurityToken");
@@ -114,9 +113,9 @@ public class RequestParser {
                 }
                 try {
                     boolean found = 
-                        parseTokenRequirements(jaxbElement, tokenRequirements, wsContext,
claimsParsers);
+                        parseTokenRequirements(jaxbElement, tokenRequirements, messageContext,
claimsParsers);
                     if (!found) {
-                        found = parseKeyRequirements(jaxbElement, keyRequirements, wsContext,
stsProperties);
+                        found = parseKeyRequirements(jaxbElement, keyRequirements, messageContext,
stsProperties);
                     }
                     if (!found) {
                         LOG.log(
@@ -180,7 +179,7 @@ public class RequestParser {
      */
     private static boolean parseKeyRequirements(
         JAXBElement<?> jaxbElement, KeyRequirements keyRequirements, 
-        WebServiceContext wsContext, STSPropertiesMBean stsProperties
+        Map<String, Object> messageContext, STSPropertiesMBean stsProperties
     ) {
         if (QNameConstants.AUTHENTICATION_TYPE.equals(jaxbElement.getName())) {
             String authenticationType = (String)jaxbElement.getValue();
@@ -208,7 +207,7 @@ public class RequestParser {
             keyRequirements.setKeywrapAlgorithm(keywrapAlgorithm);
         } else if (QNameConstants.USE_KEY.equals(jaxbElement.getName())) {
             UseKeyType useKey = (UseKeyType)jaxbElement.getValue();
-            ReceivedKey receivedKey = parseUseKey(useKey, wsContext);
+            ReceivedKey receivedKey = parseUseKey(useKey, messageContext);
             keyRequirements.setReceivedKey(receivedKey);
         } else if (QNameConstants.ENTROPY.equals(jaxbElement.getName())) {
             EntropyType entropyType = (EntropyType)jaxbElement.getValue();
@@ -234,7 +233,7 @@ public class RequestParser {
     private static boolean parseTokenRequirements(
         JAXBElement<?> jaxbElement, 
         TokenRequirements tokenRequirements,
-        WebServiceContext wsContext,
+        Map<String, Object> messageContext,
         List<ClaimsParser> claimsParsers
     ) {
         if (QNameConstants.TOKEN_TYPE.equals(jaxbElement.getName())) {
@@ -262,7 +261,7 @@ public class RequestParser {
             ValidateTargetType validateTargetType = (ValidateTargetType)jaxbElement.getValue();
             ReceivedToken validateTarget = new ReceivedToken(validateTargetType.getAny());
             if (isTokenReferenced(validateTarget.getToken())) {
-                Element target = fetchTokenElementFromReference(validateTarget.getToken(),
wsContext);
+                Element target = fetchTokenElementFromReference(validateTarget.getToken(),
messageContext);
                 validateTarget = new ReceivedToken(target);
             }  
             tokenRequirements.setValidateTarget(validateTarget);
@@ -270,7 +269,7 @@ public class RequestParser {
             CancelTargetType cancelTargetType = (CancelTargetType)jaxbElement.getValue();
             ReceivedToken cancelTarget = new ReceivedToken(cancelTargetType.getAny());
             if (isTokenReferenced(cancelTarget.getToken())) {
-                Element target = fetchTokenElementFromReference(cancelTarget.getToken(),
wsContext);
+                Element target = fetchTokenElementFromReference(cancelTarget.getToken(),
messageContext);
                 cancelTarget = new ReceivedToken(target);
             }          
             tokenRequirements.setCancelTarget(cancelTarget);
@@ -278,7 +277,7 @@ public class RequestParser {
             RenewTargetType renewTargetType = (RenewTargetType)jaxbElement.getValue();
             ReceivedToken renewTarget = new ReceivedToken(renewTargetType.getAny());
             if (isTokenReferenced(renewTarget.getToken())) {
-                Element target = fetchTokenElementFromReference(renewTarget.getToken(), wsContext);
+                Element target = fetchTokenElementFromReference(renewTarget.getToken(), messageContext);
                 renewTarget = new ReceivedToken(target);
             }          
             tokenRequirements.setRenewTarget(renewTarget);
@@ -310,13 +309,13 @@ public class RequestParser {
     /**
      * Parse the UseKey structure to get a ReceivedKey containing a cert/public-key/secret-key.
      * @param useKey The UseKey object
-     * @param wsContext The WebServiceContext object
+     * @param messageContext The message context object
      * @return the ReceivedKey that has been parsed
      * @throws STSException
      */
     private static ReceivedKey parseUseKey(
         UseKeyType useKey, 
-        WebServiceContext wsContext
+        Map<String, Object> messageContext
     ) throws STSException {
         byte[] x509 = null;
         if (useKey.getAny() instanceof JAXBElement<?>) {
@@ -343,7 +342,7 @@ public class RequestParser {
                 || obj instanceof SecurityTokenReferenceType) {
                 SecurityTokenReferenceType strType = 
                     SecurityTokenReferenceType.class.cast(useKeyJaxb.getValue());
-                Element token = fetchTokenElementFromReference(strType, wsContext);
+                Element token = fetchTokenElementFromReference(strType, messageContext);
                 try {
                     x509 = Base64Utility.decode(token.getTextContent().trim());
                     LOG.fine("Found X509Certificate UseKey type via reference");
@@ -354,7 +353,7 @@ public class RequestParser {
             }
         } else if (useKey.getAny() instanceof Element) {
             if (isTokenReferenced(useKey.getAny())) {
-                Element token = fetchTokenElementFromReference(useKey.getAny(), wsContext);
+                Element token = fetchTokenElementFromReference(useKey.getAny(), messageContext);
                 try {
                     x509 = Base64Utility.decode(token.getTextContent().trim());
                     LOG.fine("Found X509Certificate UseKey type via reference");
@@ -685,7 +684,7 @@ public class RequestParser {
      * Method to fetch token from the SecurityTokenReference
      */
     private static Element fetchTokenElementFromReference(
-        Object targetToken, WebServiceContext wsContext
+        Object targetToken, Map<String, Object> messageContext
     ) {
         // Get the reference URI
         String referenceURI = null;
@@ -723,7 +722,6 @@ public class RequestParser {
         // Find processed token corresponding to the URI
         referenceURI = XMLUtils.getIDFromReference(referenceURI);
 
-        MessageContext messageContext = wsContext.getMessageContext();
         final List<WSHandlerResult> handlerResults = 
             CastUtils.cast((List<?>) messageContext.get(WSHandlerConstants.RECV_RESULTS));
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CustomRealmParser.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CustomRealmParser.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CustomRealmParser.java
index ff5b725..b1b121e 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CustomRealmParser.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CustomRealmParser.java
@@ -18,8 +18,7 @@
  */
 package org.apache.cxf.sts.operation;
 
-import javax.xml.ws.WebServiceContext;
-import javax.xml.ws.handler.MessageContext;
+import java.util.Map;
 
 import org.apache.cxf.sts.RealmParser;
 import org.apache.cxf.ws.security.sts.provider.STSException;
@@ -29,8 +28,7 @@ import org.apache.cxf.ws.security.sts.provider.STSException;
  */
 public class CustomRealmParser implements RealmParser {
 
-    public String parseRealm(WebServiceContext context) throws STSException {
-        MessageContext messageContext = context.getMessageContext();
+    public String parseRealm(Map<String, Object> messageContext) throws STSException
{
         String endpoint = (String)messageContext.get("url");
         if (endpoint.contains("ldap")) {
             return "A";

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/sts-core/src/test/java/org/apache/cxf/sts/request/RequestParserUnitTest.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/request/RequestParserUnitTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/request/RequestParserUnitTest.java
index 63035a5..cbb7273 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/request/RequestParserUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/request/RequestParserUnitTest.java
@@ -33,7 +33,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
-import org.apache.cxf.jaxws.context.WebServiceContextImpl;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
@@ -133,7 +132,6 @@ public class RequestParserUnitTest extends org.junit.Assert {
         // Mock up message context
         MessageImpl msg = new MessageImpl();
         WrappedMessageContext msgContext = new WrappedMessageContext(msg);
-        WebServiceContextImpl wsContext = new WebServiceContextImpl(msgContext);
         
         // Process the security header and store the results in the message context
         WSSecurityEngine securityEngine = new WSSecurityEngine();
@@ -146,7 +144,7 @@ public class RequestParserUnitTest extends org.junit.Assert {
         resultsList.add(results);
         msgContext.put(WSHandlerConstants.RECV_RESULTS, resultsList);
         
-        RequestRequirements requestRequirements = parser.parseRequest(request, wsContext,
null, null);
+        RequestRequirements requestRequirements = parser.parseRequest(request, msgContext,
null, null);
         
         SCTCanceller sctCanceller = new SCTCanceller();
         assertTrue(sctCanceller.canHandleToken(requestRequirements.getTokenRequirements().getCancelTarget()));
@@ -164,7 +162,6 @@ public class RequestParserUnitTest extends org.junit.Assert {
         // Mock up message context
         MessageImpl msg = new MessageImpl();
         WrappedMessageContext msgContext = new WrappedMessageContext(msg);
-        WebServiceContextImpl wsContext = new WebServiceContextImpl(msgContext);
         
         // Process the security header and store the results in the message context
         WSSecurityEngine securityEngine = new WSSecurityEngine();
@@ -177,7 +174,7 @@ public class RequestParserUnitTest extends org.junit.Assert {
         resultsList.add(results);
         msgContext.put(WSHandlerConstants.RECV_RESULTS, resultsList);
         
-        RequestRequirements requestRequirements = parser.parseRequest(request, wsContext,
null, null);
+        RequestRequirements requestRequirements = parser.parseRequest(request, msgContext,
null, null);
         
         SCTValidator sctValidator = new SCTValidator();
         assertTrue(sctValidator.canHandleToken(requestRequirements.getTokenRequirements().getValidateTarget()));
@@ -195,7 +192,6 @@ public class RequestParserUnitTest extends org.junit.Assert {
         // Mock up message context
         MessageImpl msg = new MessageImpl();
         WrappedMessageContext msgContext = new WrappedMessageContext(msg);
-        WebServiceContextImpl wsContext = new WebServiceContextImpl(msgContext);
         
         // Process the security header and store the results in the message context
         WSSecurityEngine securityEngine = new WSSecurityEngine();
@@ -209,7 +205,7 @@ public class RequestParserUnitTest extends org.junit.Assert {
         resultsList.add(results);
         msgContext.put(WSHandlerConstants.RECV_RESULTS, resultsList);
         
-        RequestRequirements requestRequirements = parser.parseRequest(request, wsContext,
null, null);
+        RequestRequirements requestRequirements = parser.parseRequest(request, msgContext,
null, null);
         
         assertNotNull(requestRequirements.getKeyRequirements().getReceivedKey().getX509Cert());
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms/URLRealmParser.java
----------------------------------------------------------------------
diff --git a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms/URLRealmParser.java
b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms/URLRealmParser.java
index 3f40030..425ee4f 100644
--- a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms/URLRealmParser.java
+++ b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms/URLRealmParser.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cxf.systest.sts.realms;
 
-import javax.xml.ws.WebServiceContext;
+import java.util.Map;
 
 import org.apache.cxf.sts.RealmParser;
 import org.apache.cxf.ws.security.sts.provider.STSException;
@@ -29,8 +29,8 @@ import org.apache.cxf.ws.security.sts.provider.STSException;
  */
 public class URLRealmParser implements RealmParser {
 
-    public String parseRealm(WebServiceContext context) throws STSException {
-        String url = (String)context.getMessageContext().get("org.apache.cxf.request.url");
+    public String parseRealm(Map<String, Object> messageContext) throws STSException
{
+        String url = (String)messageContext.get("org.apache.cxf.request.url");
         if (url.contains("realmA")) {
             return "A";
         } else if (url.contains("realmB")) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/3b2f2ed2/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/common/UriRealmParser.java
----------------------------------------------------------------------
diff --git a/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/common/UriRealmParser.java
b/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/common/UriRealmParser.java
index 7ce72d4..87f5d7d 100644
--- a/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/common/UriRealmParser.java
+++ b/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/common/UriRealmParser.java
@@ -18,22 +18,21 @@
  */
 package org.apache.cxf.systest.sts.common;
 
+import java.util.Map;
 import java.util.StringTokenizer;
 
-import javax.xml.ws.WebServiceContext;
-
 import org.apache.cxf.sts.RealmParser;
 import org.apache.cxf.ws.security.sts.provider.STSException;
 
 public class UriRealmParser implements RealmParser {
 
     @Override
-    public String parseRealm(WebServiceContext context) throws STSException {
+    public String parseRealm(Map<String, Object> messageContext) throws STSException
{
         
 
         String realm = null;
         try {
-            String url = (String)context.getMessageContext().get("org.apache.cxf.request.url");
+            String url = (String)messageContext.get("org.apache.cxf.request.url");
             
             StringTokenizer st = new StringTokenizer(url, "/");
             


Mime
View raw message