geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From de...@apache.org
Subject svn commit: r948344 - /geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java
Date Wed, 26 May 2010 06:38:24 GMT
Author: delos
Date: Wed May 26 06:38:24 2010
New Revision: 948344

URL: http://svn.apache.org/viewvc?rev=948344&view=rev
Log:
GERONIMO-5010 Redirect to secure port when hasUserDataPermissions() is false

Modified:
    geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java

Modified: geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java?rev=948344&r1=948343&r2=948344&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java
(original)
+++ geronimo/server/branches/2.2/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/security/SecurityValve.java
Wed May 26 06:38:24 2010
@@ -25,6 +25,7 @@ import java.security.Principal;
 
 import javax.servlet.ServletException;
 
+import org.apache.catalina.Globals;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.valves.ValveBase;
@@ -49,9 +50,35 @@ public class SecurityValve extends Valve
         Object constraints = authorizer.getConstraints(request);
 
         if (!authorizer.hasUserDataPermissions(request, constraints)) {
-            //TODO redirect to secure port?
-            if (!response.isError()) {
-                response.sendError(Response.SC_MOVED_TEMPORARILY);
+            //redirect to secure port?
+            if (!response.isError() && !request.getRequest().isSecure()) {
+            	 // Redirect to the corresponding SSL port
+                StringBuffer file = new StringBuffer();
+                String protocol = "https";
+                String host = request.getServerName();
+                // Protocol
+                file.append(protocol).append("://").append(host);
+                int redirectPort = request.getConnector().getRedirectPort();
+				// Host with port
+                if(redirectPort != 443) {
+                    file.append(":").append(redirectPort);
+                }
+                // URI
+                file.append(request.getRequestURI());
+                String requestedSessionId = request.getRequestedSessionId();
+                if ((requestedSessionId != null) &&
+                    request.isRequestedSessionIdFromURL()) {
+                    file.append(";");
+                    file.append(Globals.SESSION_PARAMETER_NAME);
+                    file.append("=");
+                    file.append(requestedSessionId);
+                }
+                String queryString = request.getQueryString();
+                if (queryString != null) {
+                    file.append('?');
+                    file.append(queryString);
+                }
+                response.sendRedirect(file.toString());
             }
             return;
         }



Mime
View raw message