cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/2] cxf-fediz git commit: Use the MetadataHandler in the plugins
Date Fri, 25 Sep 2015 14:50:10 GMT
Use the MetadataHandler in the plugins


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

Branch: refs/heads/master
Commit: 7aced716430c0cc5d21243925aa290ab92f64895
Parents: f6feaf3
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Sep 25 15:49:56 2015 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Sep 25 15:49:56 2015 +0100

----------------------------------------------------------------------
 .../fediz/jetty8/FederationAuthenticator.java   | 44 +++----------------
 .../fediz/jetty9/FederationAuthenticator.java   | 44 +++----------------
 .../web/FederationAuthenticationEntryPoint.java | 46 +++-----------------
 .../web/FederationAuthenticationEntryPoint.java | 46 +++-----------------
 4 files changed, 24 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/7aced716/plugins/jetty8/src/main/java/org/apache/cxf/fediz/jetty8/FederationAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/jetty8/src/main/java/org/apache/cxf/fediz/jetty8/FederationAuthenticator.java
b/plugins/jetty8/src/main/java/org/apache/cxf/fediz/jetty8/FederationAuthenticator.java
index a1c650f..c9f69cb 100644
--- a/plugins/jetty8/src/main/java/org/apache/cxf/fediz/jetty8/FederationAuthenticator.java
+++ b/plugins/jetty8/src/main/java/org/apache/cxf/fediz/jetty8/FederationAuthenticator.java
@@ -22,7 +22,6 @@ package org.apache.cxf.fediz.jetty8;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.security.cert.X509Certificate;
 import java.util.Date;
@@ -36,8 +35,6 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.JAXBException;
 
-import org.w3c.dom.Document;
-
 import org.apache.cxf.fediz.core.FederationConstants;
 import org.apache.cxf.fediz.core.SAMLSSOConstants;
 import org.apache.cxf.fediz.core.config.FederationProtocol;
@@ -45,12 +42,12 @@ import org.apache.cxf.fediz.core.config.FedizConfigurator;
 import org.apache.cxf.fediz.core.config.FedizContext;
 import org.apache.cxf.fediz.core.config.SAMLProtocol;
 import org.apache.cxf.fediz.core.exception.ProcessingException;
+import org.apache.cxf.fediz.core.metadata.MetadataDocumentHandler;
 import org.apache.cxf.fediz.core.processor.FedizProcessor;
 import org.apache.cxf.fediz.core.processor.FedizProcessorFactory;
 import org.apache.cxf.fediz.core.processor.FedizRequest;
 import org.apache.cxf.fediz.core.processor.FedizResponse;
 import org.apache.cxf.fediz.core.processor.RedirectionResponse;
-import org.apache.wss4j.common.util.DOM2Writer;
 import org.eclipse.jetty.http.HttpMethods;
 import org.eclipse.jetty.http.MimeTypes;
 import org.eclipse.jetty.security.ServerAuthException;
@@ -165,29 +162,12 @@ public class FederationAuthenticator extends LoginAuthenticator {
         FedizContext fedConfig = getContextConfiguration(contextName);
         
         // Check to see if it is a metadata request
-        try {
-            if (request.getRequestURL().indexOf(FederationConstants.METADATA_PATH_URI) !=
-1
-                || request.getRequestURL().indexOf(getMetadataURI(fedConfig)) != -1) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Metadata document requested");
-                }
-                response.setContentType("text/xml");
-                PrintWriter out = response.getWriter();
-                
-                FedizProcessor wfProc = 
-                    FedizProcessorFactory.newFedizProcessor(fedConfig.getProtocol());
-                try {
-                    Document metadata = wfProc.getMetaData(request, fedConfig);
-                    out.write(DOM2Writer.nodeToString(metadata));
-                    return Authentication.SEND_CONTINUE;
-                } catch (Exception ex) {
-                    LOG.warn("Failed to get metadata document: " + ex.getMessage());
-                    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                    return Authentication.SEND_FAILURE;
-                }            
+        MetadataDocumentHandler mdHandler = new MetadataDocumentHandler(fedConfig);
+        if (mdHandler.canHandleRequest(request)) {
+            if (mdHandler.handleRequest(request, response)) {
+                return Authentication.SEND_CONTINUE;
             }
-        } catch (IOException e) {
-            throw new ServerAuthException(e);
+            return Authentication.SEND_FAILURE;
         }
 
         if (!mandatory) {
@@ -448,18 +428,6 @@ public class FederationAuthenticator extends LoginAuthenticator {
         return null;
     }
     
-    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;
-    }
-
     /* ------------------------------------------------------------ */
     public boolean secureResponse(ServletRequest req, ServletResponse res, boolean mandatory,
                                   User validatedUser) throws ServerAuthException {

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/7aced716/plugins/jetty9/src/main/java/org/apache/cxf/fediz/jetty9/FederationAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/jetty9/src/main/java/org/apache/cxf/fediz/jetty9/FederationAuthenticator.java
b/plugins/jetty9/src/main/java/org/apache/cxf/fediz/jetty9/FederationAuthenticator.java
index 1b8e8ca..df8f000 100644
--- a/plugins/jetty9/src/main/java/org/apache/cxf/fediz/jetty9/FederationAuthenticator.java
+++ b/plugins/jetty9/src/main/java/org/apache/cxf/fediz/jetty9/FederationAuthenticator.java
@@ -22,7 +22,6 @@ package org.apache.cxf.fediz.jetty9;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.security.cert.X509Certificate;
 import java.util.Date;
@@ -36,8 +35,6 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.JAXBException;
 
-import org.w3c.dom.Document;
-
 import org.apache.cxf.fediz.core.FederationConstants;
 import org.apache.cxf.fediz.core.SAMLSSOConstants;
 import org.apache.cxf.fediz.core.config.FederationProtocol;
@@ -45,12 +42,12 @@ import org.apache.cxf.fediz.core.config.FedizConfigurator;
 import org.apache.cxf.fediz.core.config.FedizContext;
 import org.apache.cxf.fediz.core.config.SAMLProtocol;
 import org.apache.cxf.fediz.core.exception.ProcessingException;
+import org.apache.cxf.fediz.core.metadata.MetadataDocumentHandler;
 import org.apache.cxf.fediz.core.processor.FedizProcessor;
 import org.apache.cxf.fediz.core.processor.FedizProcessorFactory;
 import org.apache.cxf.fediz.core.processor.FedizRequest;
 import org.apache.cxf.fediz.core.processor.FedizResponse;
 import org.apache.cxf.fediz.core.processor.RedirectionResponse;
-import org.apache.wss4j.common.util.DOM2Writer;
 import org.eclipse.jetty.http.HttpMethod;
 import org.eclipse.jetty.http.MimeTypes;
 import org.eclipse.jetty.security.ServerAuthException;
@@ -164,29 +161,12 @@ public class FederationAuthenticator extends LoginAuthenticator {
         FedizContext fedConfig = getContextConfiguration(contextName);
         
         // Check to see if it is a metadata request
-        try {
-            if (request.getRequestURL().indexOf(FederationConstants.METADATA_PATH_URI) !=
-1
-                || request.getRequestURL().indexOf(getMetadataURI(fedConfig)) != -1) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Metadata document requested");
-                }
-                response.setContentType("text/xml");
-                PrintWriter out = response.getWriter();
-                
-                FedizProcessor wfProc = 
-                    FedizProcessorFactory.newFedizProcessor(fedConfig.getProtocol());
-                try {
-                    Document metadata = wfProc.getMetaData(request, fedConfig);
-                    out.write(DOM2Writer.nodeToString(metadata));
-                    return Authentication.SEND_CONTINUE;
-                } catch (Exception ex) {
-                    LOG.warn("Failed to get metadata document: " + ex.getMessage());
-                    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                    return Authentication.SEND_FAILURE;
-                }            
+        MetadataDocumentHandler mdHandler = new MetadataDocumentHandler(fedConfig);
+        if (mdHandler.canHandleRequest(request)) {
+            if (mdHandler.handleRequest(request, response)) {
+                return Authentication.SEND_CONTINUE;
             }
-        } catch (IOException e) {
-            throw new ServerAuthException(e);
+            return Authentication.SEND_FAILURE;
         }
 
         if (!mandatory) {
@@ -449,18 +429,6 @@ public class FederationAuthenticator extends LoginAuthenticator {
         return null;
     }
     
-    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;
-    }
-
     /* ------------------------------------------------------------ */
     public boolean secureResponse(ServletRequest req, ServletResponse res, boolean mandatory,
                                   User validatedUser) throws ServerAuthException {

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/7aced716/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
----------------------------------------------------------------------
diff --git a/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
b/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
index 9749927..c62e56e 100644
--- a/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
+++ b/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
@@ -20,27 +20,19 @@
 package org.apache.cxf.fediz.spring.web;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.w3c.dom.Document;
-
-import org.apache.cxf.fediz.core.FederationConstants;
-import org.apache.cxf.fediz.core.SAMLSSOConstants;
-import org.apache.cxf.fediz.core.config.FederationProtocol;
 import org.apache.cxf.fediz.core.config.FedizContext;
-import org.apache.cxf.fediz.core.config.SAMLProtocol;
 import org.apache.cxf.fediz.core.exception.ProcessingException;
+import org.apache.cxf.fediz.core.metadata.MetadataDocumentHandler;
 import org.apache.cxf.fediz.core.processor.FedizProcessor;
 import org.apache.cxf.fediz.core.processor.FedizProcessorFactory;
 import org.apache.cxf.fediz.core.processor.RedirectionResponse;
 import org.apache.cxf.fediz.spring.FederationConfig;
-import org.apache.wss4j.common.util.DOM2Writer;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -86,25 +78,11 @@ public class FederationAuthenticationEntryPoint implements AuthenticationEntryPo
         FedizContext fedContext = federationConfig.getFedizContext();
         LOG.debug("Federation context: {}", fedContext);
         
-        if (servletRequest.getRequestURL().indexOf(FederationConstants.METADATA_PATH_URI)
!= -1
-            || servletRequest.getRequestURL().indexOf(getMetadataURI(fedContext)) != -1)
{
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Metadata document requested");
-            }
-            response.setContentType("text/xml");
-            PrintWriter out = response.getWriter();
-            
-            FedizProcessor wfProc = 
-                FedizProcessorFactory.newFedizProcessor(fedContext.getProtocol());
-            try {
-                Document metadata = wfProc.getMetaData(servletRequest, fedContext);
-                out.write(DOM2Writer.nodeToString(metadata));
-                return;
-            } catch (Exception ex) {
-                LOG.warn("Failed to get metadata document: " + ex.getMessage());
-                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                return;
-            }            
+        // Check to see if it is a metadata request
+        MetadataDocumentHandler mdHandler = new MetadataDocumentHandler(fedContext);
+        if (mdHandler.canHandleRequest(servletRequest)) {
+            mdHandler.handleRequest(servletRequest, response);
+            return;
         }
         
         String redirectUrl = null;
@@ -139,18 +117,6 @@ public class FederationAuthenticationEntryPoint implements AuthenticationEntryPo
         response.sendRedirect(redirectUrl);
     }
 
-    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;
-    }
-
     /**
      * Template method for you to do your own pre-processing before the redirect occurs.
      *

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/7aced716/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
----------------------------------------------------------------------
diff --git a/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
b/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
index 851f253..0a732d2 100644
--- a/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
+++ b/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
@@ -20,7 +20,6 @@
 package org.apache.cxf.fediz.spring.web;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.Map;
 
 import javax.servlet.ServletException;
@@ -29,20 +28,13 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.w3c.dom.Document;
-
-import org.apache.cxf.fediz.core.FederationConstants;
-import org.apache.cxf.fediz.core.SAMLSSOConstants;
-import org.apache.cxf.fediz.core.config.FederationProtocol;
 import org.apache.cxf.fediz.core.config.FedizContext;
-import org.apache.cxf.fediz.core.config.SAMLProtocol;
 import org.apache.cxf.fediz.core.exception.ProcessingException;
+import org.apache.cxf.fediz.core.metadata.MetadataDocumentHandler;
 import org.apache.cxf.fediz.core.processor.FedizProcessor;
 import org.apache.cxf.fediz.core.processor.FedizProcessorFactory;
 import org.apache.cxf.fediz.core.processor.RedirectionResponse;
 import org.apache.cxf.fediz.spring.FederationConfig;
-import org.apache.wss4j.common.util.DOM2Writer;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -83,18 +75,6 @@ public class FederationAuthenticationEntryPoint implements AuthenticationEntryPo
         Assert.notNull(this.federationConfig, "FederationConfig cannot be null.");
     }
 
-    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;
-    }
-
     /**
      * Template method for you to do your own pre-processing before the redirect occurs.
      *
@@ -119,25 +99,11 @@ public class FederationAuthenticationEntryPoint implements AuthenticationEntryPo
         FedizContext fedContext = federationConfig.getFedizContext();
         LOG.debug("Federation context: {}", fedContext);
         
-        if (hrequest.getRequestURL().indexOf(FederationConstants.METADATA_PATH_URI) != -1
-            || hrequest.getRequestURL().indexOf(getMetadataURI(fedContext)) != -1) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Metadata document requested");
-            }
-            response.setContentType("text/xml");
-            PrintWriter out = response.getWriter();
-            
-            FedizProcessor wfProc = 
-                FedizProcessorFactory.newFedizProcessor(fedContext.getProtocol());
-            try {
-                Document metadata = wfProc.getMetaData(hrequest, fedContext);
-                out.write(DOM2Writer.nodeToString(metadata));
-                return;
-            } catch (Exception ex) {
-                LOG.warn("Failed to get metadata document: " + ex.getMessage());
-                hresponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                return;
-            }            
+        // Check to see if it is a metadata request
+        MetadataDocumentHandler mdHandler = new MetadataDocumentHandler(fedContext);
+        if (mdHandler.canHandleRequest(hrequest)) {
+            mdHandler.handleRequest(hrequest, hresponse);
+            return;
         }
         
         String redirectUrl = null;


Mime
View raw message