diff --git a/castest2/WebContent/WEB-INF/web.xml b/castest2/WebContent/WEB-INF/web.xml index 83ddee3407ad80568ec9f2c325a40b6723e19ffe..076287394a445626978d0818446595b730a63a3f 100644 --- a/castest2/WebContent/WEB-INF/web.xml +++ b/castest2/WebContent/WEB-INF/web.xml @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> - <display-name>castest2</display-name> + <display-name>Sample CASified Application</display-name> + <description> + A sample application that demonstrates the CAS client. + </description> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> @@ -9,10 +12,15 @@ <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> + + <context-param> + <param-name>serverName</param-name> + <param-value>http://localhost:8080</param-value> + </context-param> <!-- Start CAS configuration --> <!-- https://secure.identity.ucsb.edu/inside/doku.php/sso_java --> -<!-- CAS Single Sign Out Filter +<!-- CAS Single Sign Out Filter--> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class> @@ -20,7 +28,7 @@ <param-name>casServerUrlPrefix</param-name> <param-value>https://shib.idm.umd.edu/shibboleth-idp/profile/cas</param-value> </init-param> -</filter>--> +</filter> <!-- CAS Authentication Filter --> <filter> <filter-name>CAS Authentication Filter</filter-name> @@ -29,22 +37,14 @@ <param-name>casServerLoginUrl</param-name> <param-value>https://login.umd.edu/cas/login</param-value> </init-param> - <init-param> - <param-name>serverName</param-name> - <param-value>http://localhost:8080/</param-value> - </init-param> </filter> - <!-- CAS Validation Filter + <!-- CAS Validation Filter --> <filter> <filter-name>CAS Validation Filter</filter-name> - <filter-class>org.jasig.cas.client.validation.Cas20ServiceTicketValidator</filter-class> + <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> - <param-value>https://shib.idm.umd.edu/shibboleth-idp/profile/cas</param-value> - </init-param> - <init-param> - <param-name>serverName</param-name> - <param-value>http://localhost:8080/castest2</param-value> + <param-value>https://login.umd.edu/cas</param-value> </init-param> <init-param> <param-name>redirectAfterValidation</param-name> @@ -54,33 +54,33 @@ <param-name>useSession</param-name> <param-value>true</param-value> </init-param> -</filter> --> +</filter> <!-- CAS HttpServletRequest Wrapper Filter --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class> </filter> -<!-- order of CAS filter mappings is important +<!-- order of CAS filter mappings is important --> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> -</filter-mapping>--> +</filter-mapping> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> -<!--<filter-mapping> +<filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> -</filter-mapping>--> +</filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> -<!-- <listener> + <listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> -</listener>--> +</listener> <!-- End CAS configuration --> </web-app> \ No newline at end of file diff --git a/castest2/src/castest2/servlet/FileCounter.java b/castest2/src/castest2/servlet/FileCounter.java index e6995f73b60826c7106b4b7888c790ec04e4a9a0..8a8cb71a34f17ddf4919bacb91ac38acbbeb15f1 100644 --- a/castest2/src/castest2/servlet/FileCounter.java +++ b/castest2/src/castest2/servlet/FileCounter.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.jasig.cas.client.authentication.AttributePrincipal; import castest2.FileDao; @@ -29,16 +30,25 @@ public class FileCounter extends HttpServlet { HttpSession session = request.getSession(true); // Set the session valid for 5 secs session.setMaxInactiveInterval(5); + response.setContentType("text/html"); PrintWriter out = response.getWriter(); if (session.isNew()) { count++; } - out.println("This site has been accessed " + count + " times."); - out.println("<a href='https://login.umd.edu/cas/logout'> logout </a>"); + //CAS returns principal in the request. + AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal(); + if (principal != null) { + String uni = principal.getName(); + out.println(uni); + } else { + out.println("Could not get username"); + } + out.println("This site has been accessed " + count + " times.\n"); + out.println("<a href='https://login.umd.edu/cas/logout'> logout\n </a>"); + } - - + @Override public void init() throws ServletException { dao = new FileDao();