From e0f98d7d3bde6c3643f91b0203f285da31f6c1d3 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Thu, 18 Oct 2012 13:59:05 +0200
Subject: [PATCH] local testing without https

---
 hsarweb/build.xml                               |    6 ++++++
 hsarweb/conf/WEB-INF/web.xml                    |   20 ++++++++++----------
 hsarweb/src/de/hsadmin/web/MainApplication.java |   29 ++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/hsarweb/build.xml b/hsarweb/build.xml
index 530142d..eaad198 100644
--- a/hsarweb/build.xml
+++ b/hsarweb/build.xml
@@ -21,6 +21,7 @@
 				<filter token="CONFIG_PORT" value="${hsar.https.port}"/>
 				<filter token="ADMIN_HOST" value="${hsarweb.domain.name}"/>
 				<filter token="ADMIN_PORT" value="${hsarweb.https.port}"/>
+				<filter token="HTTPS" value="${hsar.https}"/>
 			</filterset>
 		</copy>
         <war destfile="build/hsarweb.war" basedir="WebContent">
@@ -38,4 +39,9 @@
 		/>    
     </target>
 
+    <target name="clean">
+    	<delete dir="build"/>
+    	<delete file="WebContent/WEB-INF/web.xml"/>
+    </target>
+
 </project>
diff --git a/hsarweb/conf/WEB-INF/web.xml b/hsarweb/conf/WEB-INF/web.xml
index efabea9..e9a46ec 100644
--- a/hsarweb/conf/WEB-INF/web.xml
+++ b/hsarweb/conf/WEB-INF/web.xml
@@ -7,15 +7,15 @@
 
 	<context-param>
 		<param-name>serverName</param-name>
-		<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@</param-value>
+		<param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@</param-value>
 	</context-param>
 	<context-param>
 		<param-name>backendURL</param-name>
-		<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value>
+		<param-value>@HTTPS@://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value>
 	</context-param>
 	<context-param>
 		<param-name>xmlrpcURL</param-name>
-		<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/xmlrpc/hsadmin</param-value>
+		<param-value>@HTTPS@://@CONFIG_HOST@:@CONFIG_PORT@/hsar/xmlrpc/hsadmin</param-value>
 	</context-param>
 	<context-param>
 		<description>Vaadin production mode</description>
@@ -28,11 +28,11 @@
 		<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
 		<init-param>
 			<param-name>casServerLoginUrl</param-name>
-			<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/login</param-value>
+			<param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas/login</param-value>
 		</init-param>
 		<init-param>
 			<param-name>service</param-name>
-			<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
+			<param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
 		</init-param>
 	</filter>
 
@@ -41,7 +41,7 @@
 		<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
 		<init-param>
 			<param-name>casServerUrlPrefix</param-name>
-			<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas</param-value>
+			<param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas</param-value>
 		</init-param>
 		<init-param>
         	<param-name>proxyReceptorUrl</param-name>
@@ -49,11 +49,11 @@
         </init-param>
         <init-param>
         	<param-name>proxyCallbackUrl</param-name>
-            <param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb/proxyCallback</param-value>
+            <param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb/proxyCallback</param-value>
         </init-param>
 		<init-param>
 			<param-name>service</param-name>
-			<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
+			<param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
 		</init-param>
 	</filter>
 	
@@ -66,13 +66,13 @@
         <filter-name>CAS Authentication Filter</filter-name>
 		<url-pattern>/*</url-pattern>
     </filter-mapping>
-
+		 
 	<servlet>
 		<servlet-name>Logout Servlet</servlet-name>
 		<servlet-class>de.hsadmin.logout.LogoutServlet</servlet-class>
 		<init-param>
 			<param-name>redirect</param-name>
-			<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/logout</param-value>
+			<param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas/logout</param-value>
 		</init-param>
 	</servlet>
 	
diff --git a/hsarweb/src/de/hsadmin/web/MainApplication.java b/hsarweb/src/de/hsadmin/web/MainApplication.java
index 5f256a2..9d87716 100644
--- a/hsarweb/src/de/hsadmin/web/MainApplication.java
+++ b/hsarweb/src/de/hsadmin/web/MainApplication.java
@@ -32,6 +32,14 @@
 public class MainApplication extends Application implements HttpServletRequestListener, TabSheet.SelectedTabChangeListener {
 
 	private static final long serialVersionUID = 1L;
+	private static final String LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets";
+	private static boolean isTestEnvironment = false;
+
+	static {
+		Config config = Config.getInstance();
+		Object loginURL = config.getProperty("loginURL", LOGIN_URL);
+		isTestEnvironment = "TestUmgebung".equals(loginURL);
+	}
 	
 	private HttpSession httpSession;
 	private ServletContext servletContext;
@@ -138,7 +146,26 @@
 		requestLocale = request.getLocale();
 		httpSession = request.getSession();
 		servletContext = httpSession.getServletContext();
-		userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal();
+		if (isTestEnvironment) {
+			userPrincipal = new AttributePrincipal() {
+				private static final long serialVersionUID = 1L;
+				@Override
+				public String getName() {
+					return "ad";
+				}
+				@Override
+				public String getProxyTicketFor(String arg0) {
+					return "user:ad";
+				}
+				@SuppressWarnings("rawtypes")
+				@Override
+				public Map getAttributes() {
+					return new HashMap();
+				}
+			};
+		} else {
+			userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal();
+		}
 	}
 
 	@Override

--
Gitblit v1.9.1