cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject git commit: [FEDIZ-86] - Added Metadata support for the CXF plugin
Date Fri, 05 Sep 2014 10:40:13 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master 2d01528cb -> d073bce10


[FEDIZ-86] - Added Metadata support for the CXF plugin


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

Branch: refs/heads/master
Commit: d073bce10bbe4fffed778cfb12bba737c85fcda5
Parents: 2d01528
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Sep 5 11:39:54 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Sep 5 11:39:54 2014 +0100

----------------------------------------------------------------------
 .../cxf/plugin/FedizRedirectBindingFilter.java  | 49 +++++++++++++++++++-
 .../federation/FederationTest.java              |  7 ---
 2 files changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/d073bce1/plugins/cxf/src/main/java/org/apache/cxf/fediz/cxf/plugin/FedizRedirectBindingFilter.java
----------------------------------------------------------------------
diff --git a/plugins/cxf/src/main/java/org/apache/cxf/fediz/cxf/plugin/FedizRedirectBindingFilter.java
b/plugins/cxf/src/main/java/org/apache/cxf/fediz/cxf/plugin/FedizRedirectBindingFilter.java
index 438f615..bd2d198 100644
--- a/plugins/cxf/src/main/java/org/apache/cxf/fediz/cxf/plugin/FedizRedirectBindingFilter.java
+++ b/plugins/cxf/src/main/java/org/apache/cxf/fediz/cxf/plugin/FedizRedirectBindingFilter.java
@@ -36,6 +36,8 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
+import org.w3c.dom.Document;
+
 import org.apache.cxf.fediz.core.FederationConstants;
 import org.apache.cxf.fediz.core.RequestState;
 import org.apache.cxf.fediz.core.SAMLSSOConstants;
@@ -70,13 +72,17 @@ public class FedizRedirectBindingFilter extends AbstractServiceProviderFilter
{
     
     public void filter(ContainerRequestContext context) {
         Message m = JAXRSUtils.getCurrentMessage();
+        FedizContext fedConfig = getFedizContext(m);
         
+        // See if it is a Metadata request
+        if (isMetadataRequest(context, fedConfig)) {
+            return;
+        }
+
         if (checkSecurityContext(m)) {
             return;
         } else {
             try {
-                FedizContext fedConfig = getFedizContext(m);
-                
                 String httpMethod = context.getMethod();
                 MultivaluedMap<String, String> params = null;
                 if (HttpMethod.GET.equals(httpMethod)) {
@@ -207,6 +213,45 @@ public class FedizRedirectBindingFilter extends AbstractServiceProviderFilter
{
         }
     }
     
+    private boolean isMetadataRequest(ContainerRequestContext context, FedizContext fedConfig)
{
+        String requestPath = context.getUriInfo().getPath();
+        // See if it is a Metadata request
+        if (requestPath.indexOf(FederationConstants.METADATA_PATH_URI) != -1
+            || requestPath.indexOf(getMetadataURI(fedConfig)) != -1) {
+            if (LOG.isInfoEnabled()) {
+                LOG.info("Metadata document requested");
+            }
+            
+            FedizProcessor wfProc = 
+                FedizProcessorFactory.newFedizProcessor(fedConfig.getProtocol());
+            try {
+                Document metadata = wfProc.getMetaData(fedConfig);
+                String metadataStr = DOM2Writer.nodeToString(metadata);
+                
+                ResponseBuilder response = Response.ok(metadataStr, "text/xml");
+                context.abortWith(response.build());
+                return true;
+            } catch (Exception ex) {
+                LOG.error("Failed to get metadata document: " + ex.getMessage());
+                throw ExceptionUtils.toInternalServerErrorException(ex, null);
+            }            
+        }
+        
+        return false;
+    }
+    
+    private String getMetadataURI(FedizContext fedConfig) {
+        if (fedConfig.getProtocol().getMetadataURI() != null) {
+            return fedConfig.getProtocol().getMetadataURI();
+        } else if (fedConfig.getProtocol() instanceof FederationProtocol) {
+            return FederationConstants.METADATA_PATH_URI;
+        } else if (fedConfig.getProtocol() instanceof SAMLProtocol) {
+            return SAMLSSOConstants.FEDIZ_SAML_METADATA_PATH_URI;
+        }
+        
+        return FederationConstants.METADATA_PATH_URI;
+    }
+    
     private boolean isSignInRequired(FedizContext fedConfig, MultivaluedMap<String, String>
params) {
         if (params != null && fedConfig.getProtocol() instanceof FederationProtocol
             && params.getFirst(FederationConstants.PARAM_ACTION) == null) {

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/d073bce1/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java
----------------------------------------------------------------------
diff --git a/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java
b/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java
index fd2d5e4..f763340 100644
--- a/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java
+++ b/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java
@@ -195,13 +195,6 @@ public class FederationTest extends AbstractTests {
 
     }
 
-    @org.junit.Test
-    @org.junit.Ignore
-    @Override
-    public void testMetadata() throws Exception {
-    }
-
-
     public String getServletContextName() {
         return "fedizhelloworld";
     }


Mime
View raw message