From af5b4bac3da618d593fe22e4896cd068e0555d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E5=B1=B1=E9=A3=9E=E9=B9=84?= Date: Sat, 12 Jul 2014 22:42:51 +0800 Subject: [PATCH] cas-shiro-demo --- cas-shiro-demo/.gitignore | 6 + cas-shiro-demo/README.md | 22 ++ cas-shiro-demo/cas-shiro-demo-app/.gitignore | 6 + cas-shiro-demo/cas-shiro-demo-app/pom.xml | 74 ++++++ .../src/main/resources/log4j.properties | 7 + .../src/main/resources/shiro.ini | 26 +++ .../src/main/webapp/WEB-INF/web.xml | 15 ++ .../src/main/webapp/auth/index.jsp | 12 + .../src/main/webapp/error.jsp | 1 + .../src/main/webapp/index.jsp | 2 + .../src/main/webapp/user/index.jsp | 12 + .../cas-shiro-demo-server/.gitignore | 6 + cas-shiro-demo/cas-shiro-demo-server/pom.xml | 37 +++ .../webapp/WEB-INF/deployerConfigContext.xml | 72 ++++++ .../src/main/webapp/WEB-INF/login-webflow.xml | 217 ++++++++++++++++++ .../ticketExpirationPolicies.xml | 35 +++ .../ticketGrantingTicketCookieGenerator.xml | 34 +++ .../view/jsp/default/ui/casLoginView.jsp | 143 ++++++++++++ cas-shiro-demo/pom.xml | 37 +++ 19 files changed, 764 insertions(+) create mode 100644 cas-shiro-demo/.gitignore create mode 100644 cas-shiro-demo/README.md create mode 100644 cas-shiro-demo/cas-shiro-demo-app/.gitignore create mode 100644 cas-shiro-demo/cas-shiro-demo-app/pom.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/resources/log4j.properties create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/resources/shiro.ini create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/WEB-INF/web.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/auth/index.jsp create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/error.jsp create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/index.jsp create mode 100644 cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/user/index.jsp create mode 100644 cas-shiro-demo/cas-shiro-demo-server/.gitignore create mode 100644 cas-shiro-demo/cas-shiro-demo-server/pom.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/deployerConfigContext.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/login-webflow.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml create mode 100644 cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp create mode 100644 cas-shiro-demo/pom.xml diff --git a/cas-shiro-demo/.gitignore b/cas-shiro-demo/.gitignore new file mode 100644 index 0000000..e4a63e1 --- /dev/null +++ b/cas-shiro-demo/.gitignore @@ -0,0 +1,6 @@ +.classpath +.project +.settings/ +target/ +test-output/ +bin/ diff --git a/cas-shiro-demo/README.md b/cas-shiro-demo/README.md new file mode 100644 index 0000000..09c8aa0 --- /dev/null +++ b/cas-shiro-demo/README.md @@ -0,0 +1,22 @@ +h2. What is this project ? + +This project *cas-shiro-demo* has been created to test the CAS support for Shiro library, i.e. the *shiro-cas* library. It’s composed of two modules : +- the *cas-shiro-demo-app* module is a demo web application which uses the CAS Shiro support library with protected area requiring CAS authentication : "http://shiro.apache.org/cas.html":http://shiro.apache.org/cas.html +- the *cas-shiro-demo-server* module is a CAS server configured with remember-me feature. + +h2. Quick start & test + +To start quickly, build the project :
cas-shiro-demo
+mvn clean install
and start the two web applications with jetty :
cd cas-shiro-demo-app
+mvn jetty:run
+ +To test, +- call the "http://localhost:8080/app/user/index.jsp":http://localhost:8080/app/user/index.jsp url by clicking on the _user/index_ link +- be sent to CAS server and log in (the password is equal to the login) +- be redirected back to the application, authenticated. + +h2. Manual deployment + +You can also deploy manually these two web applications in your favorite web applications server : +- cas-shiro-demo-app on http://localhost:8080/app +- cas-shiro-demo-server on http://localhost:8080/cas diff --git a/cas-shiro-demo/cas-shiro-demo-app/.gitignore b/cas-shiro-demo/cas-shiro-demo-app/.gitignore new file mode 100644 index 0000000..e4a63e1 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/.gitignore @@ -0,0 +1,6 @@ +.classpath +.project +.settings/ +target/ +test-output/ +bin/ diff --git a/cas-shiro-demo/cas-shiro-demo-app/pom.xml b/cas-shiro-demo/cas-shiro-demo-app/pom.xml new file mode 100644 index 0000000..af037e8 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/pom.xml @@ -0,0 +1,74 @@ + + 4.0.0 + + org.leleuj + cas-shiro-demo + 1.0.0-SNAPSHOT + + cas-shiro-demo-app + war + CAS Shiro demo : application + CAS Shiro demo : application + + + org.apache.shiro + shiro-cas + 1.2.3 + + + org.slf4j + slf4j-log4j12 + 1.6.4 + + + org.slf4j + jcl-over-slf4j + 1.6.4 + + + commons-codec + commons-codec + 1.4 + + + org.opensaml + opensaml + 1.1 + + + org.apache.santuario + xmlsec + 1.4.3 + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-eclipse-plugin + + + org.mortbay.jetty + jetty-maven-plugin + 8.1.7.v20120910 + + + /app + + + + ${basedir}/../cas-shiro-demo-server/target/cas-shiro-demo-server.war + /cas + + + + + + + diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/log4j.properties b/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/log4j.properties new file mode 100644 index 0000000..2aeb3da --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=WARN, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=CAS SHIRO DEMO APP %d{yyyy/MM/dd HH:mm:ss,SSS} %5p [%t] %c - %m%n + +log4j.logger.org.apache.shiro=DEBUG diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/shiro.ini b/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/shiro.ini new file mode 100644 index 0000000..1f8a549 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/resources/shiro.ini @@ -0,0 +1,26 @@ +[main] +casFilter = org.apache.shiro.cas.CasFilter +casFilter.failureUrl = /error.jsp + +casRealm = org.apache.shiro.cas.CasRealm +casRealm.defaultRoles = ROLE_USER +casRealm.casServerUrlPrefix = http://localhost:8080/cas/ +casRealm.casService = http://localhost:8080/app/shiro-cas +casRealm.validationProtocol = SAML + +casSubjectFactory = org.apache.shiro.cas.CasSubjectFactory +securityManager.subjectFactory = $casSubjectFactory + +# only with SHIRO-373 featured added : +#casAuthUser = org.apache.shiro.cas.CasAuthenticatedUserFilter +#casAuthUser.loginUrl = http://localhost:8080/cas/login?service=http://localhost:8080/app/shiro-cas + +user.loginUrl = http://localhost:8080/cas/login?service=http://localhost:8080/app/shiro-cas + +[urls] +/shiro-cas = casFilter +# only with SHIRO-373 featured added : +#/auth/** = casAuthUser +/user/** = user +/logout = logout +/** = anon diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/WEB-INF/web.xml b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..63b8be4 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,15 @@ + + + + CAS Shiro demo : application + + + ShiroFilter + org.apache.shiro.web.servlet.IniShiroFilter + + + ShiroFilter + /* + + + diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/auth/index.jsp b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/auth/index.jsp new file mode 100644 index 0000000..cd15d3c --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/auth/index.jsp @@ -0,0 +1,12 @@ +

auth/index

+logout
+
+<%@page import="org.apache.shiro.subject.Subject"%> +<%@page import="org.apache.shiro.SecurityUtils"%> +<% + Subject subject = SecurityUtils.getSubject(); +%> +principal : <%=subject.getPrincipal()%>
+principals : <%=subject.getPrincipals()%>
+isAuthenticated : <%=subject.isAuthenticated()%>
+isRemembered : <%=subject.isRemembered()%>
diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/error.jsp b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/error.jsp new file mode 100644 index 0000000..ecfd539 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/error.jsp @@ -0,0 +1 @@ +

error

\ No newline at end of file diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/index.jsp b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/index.jsp new file mode 100644 index 0000000..fbd582e --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/index.jsp @@ -0,0 +1,2 @@ +auth/index
+user/index
diff --git a/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/user/index.jsp b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/user/index.jsp new file mode 100644 index 0000000..582b7bf --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-app/src/main/webapp/user/index.jsp @@ -0,0 +1,12 @@ +

user/index

+logout
+
+<%@page import="org.apache.shiro.subject.Subject"%> +<%@page import="org.apache.shiro.SecurityUtils"%> +<% + Subject subject = SecurityUtils.getSubject(); +%> +principal : <%=subject.getPrincipal()%>
+principals : <%=subject.getPrincipals()%>
+isAuthenticated : <%=subject.isAuthenticated()%>
+isRemembered : <%=subject.isRemembered()%>
diff --git a/cas-shiro-demo/cas-shiro-demo-server/.gitignore b/cas-shiro-demo/cas-shiro-demo-server/.gitignore new file mode 100644 index 0000000..e4a63e1 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/.gitignore @@ -0,0 +1,6 @@ +.classpath +.project +.settings/ +target/ +test-output/ +bin/ diff --git a/cas-shiro-demo/cas-shiro-demo-server/pom.xml b/cas-shiro-demo/cas-shiro-demo-server/pom.xml new file mode 100644 index 0000000..5a0af46 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + + org.leleuj + cas-shiro-demo + 1.0.0-SNAPSHOT + + cas-shiro-demo-server + war + CAS Shiro demo : CAS server + CAS Shiro demo : CAS server + + + org.jasig.cas + cas-server-webapp + ${cas.version} + war + runtime + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-eclipse-plugin + + + + + 3.5.0 + + diff --git a/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/deployerConfigContext.xml b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/deployerConfigContext.xml new file mode 100644 index 0000000..61d5a97 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/deployerConfigContext.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/login-webflow.xml b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/login-webflow.xml new file mode 100644 index 0000000..c766186 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/login-webflow.xml @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml new file mode 100644 index 0000000..4b93d22 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml @@ -0,0 +1,35 @@ + + + + + + Assignment of expiration policies for the different tickets generated by CAS including ticket granting ticket + (TGT), service ticket (ST), proxy granting ticket (PGT), and proxy ticket (PT). + These expiration policies determine how long the ticket they are assigned + to can be used and even how often they + can be used before becoming expired / invalid. + + + + + + + + + + + + + + + + + + + diff --git a/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml new file mode 100644 index 0000000..61ab9ca --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml @@ -0,0 +1,34 @@ + + + + + + Defines the cookie that stores the TicketGrantingTicket. You most likely should never modify these (especially the "secure" property). + You can change the name if you want to make it harder for people to guess. + + + \ No newline at end of file diff --git a/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp new file mode 100644 index 0000000..4d916f7 --- /dev/null +++ b/cas-shiro-demo/cas-shiro-demo-server/src/main/webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp @@ -0,0 +1,143 @@ +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + +<%-- + ~ Licensed to Jasig under one or more contributor license + ~ agreements. See the NOTICE file distributed with this work + ~ for additional information regarding copyright ownership. + ~ Jasig licenses this file to you under the Apache License, + ~ Version 2.0 (the "License"); you may not use this file + ~ except in compliance with the License. You may obtain a + ~ copy of the License at the following location: + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --%> + +<%@ page contentType="text/html; charset=UTF-8" %> + + + +
+

Non-secure Connection

+

You are currently accessing CAS over a non-secure connection. Single Sign On WILL NOT WORK. In order to have single sign on work, you MUST log in over HTTPS.

+
+
+ +
+ + + +

+
+ + + ${sessionScope.openIdLocalId} + + + + + + + +
+
+ + <%-- + NOTE: Certain browsers will offer the option of caching passwords for a user. There is a non-standard attribute, + "autocomplete" that when set to "off" will tell certain browsers not to prompt to cache credentials. For more + information, see the following web page: + http://www.geocities.com/technofundo/tech/web/ie_autocomplete.html + --%> + + +
+
+ " type="checkbox" /> + +
+
+ + +
+
+ + + + + " tabindex="4" type="submit" /> + " tabindex="5" type="reset" /> +
+
+
+ + \ No newline at end of file diff --git a/cas-shiro-demo/pom.xml b/cas-shiro-demo/pom.xml new file mode 100644 index 0000000..8b32e83 --- /dev/null +++ b/cas-shiro-demo/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + org.leleuj + cas-shiro-demo + 1.0.0-SNAPSHOT + pom + CAS Shiro demo + CAS Shiro demo + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.7 + + 2.0 + + + + + + + cas-shiro-demo-app + cas-shiro-demo-server + +