You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by jb...@apache.org on 2012/06/04 15:26:35 UTC
svn commit: r1345958 - in /shiro/trunk/samples: ./ guice/ guice/src/
guice/src/main/ guice/src/main/java/ guice/src/main/java/org/
guice/src/main/java/org/apache/ guice/src/main/java/org/apache/shiro/
guice/src/main/java/org/apache/shiro/samples/ guice...
Author: jbunting
Date: Mon Jun 4 13:26:34 2012
New Revision: 1345958
URL: http://svn.apache.org/viewvc?rev=1345958&view=rev
Log:
SHIRO-320: creating samples-guice as a port of samples-web, modified for guice integtaion
Added:
shiro/trunk/samples/guice/
shiro/trunk/samples/guice/pom.xml
shiro/trunk/samples/guice/src/
shiro/trunk/samples/guice/src/main/
shiro/trunk/samples/guice/src/main/java/
shiro/trunk/samples/guice/src/main/java/org/
shiro/trunk/samples/guice/src/main/java/org/apache/
shiro/trunk/samples/guice/src/main/java/org/apache/shiro/
shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/
shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/
shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java
shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java
shiro/trunk/samples/guice/src/main/resources/
shiro/trunk/samples/guice/src/main/resources/log4j.properties
shiro/trunk/samples/guice/src/main/webapp/
shiro/trunk/samples/guice/src/main/webapp/WEB-INF/
shiro/trunk/samples/guice/src/main/webapp/WEB-INF/shiro.ini
shiro/trunk/samples/guice/src/main/webapp/WEB-INF/web.xml
shiro/trunk/samples/guice/src/main/webapp/account/
shiro/trunk/samples/guice/src/main/webapp/account/index.jsp
shiro/trunk/samples/guice/src/main/webapp/home.jsp
shiro/trunk/samples/guice/src/main/webapp/include.jsp
shiro/trunk/samples/guice/src/main/webapp/index.jsp
shiro/trunk/samples/guice/src/main/webapp/login.jsp
shiro/trunk/samples/guice/src/main/webapp/style.css
shiro/trunk/samples/guice/src/test/
shiro/trunk/samples/guice/src/test/java/
shiro/trunk/samples/guice/src/test/java/org/
shiro/trunk/samples/guice/src/test/java/org/apache/
shiro/trunk/samples/guice/src/test/java/org/apache/shiro/
shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/
shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/
shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerTest.java
shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationTest.java
Modified:
shiro/trunk/samples/pom.xml
Added: shiro/trunk/samples/guice/pom.xml
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/pom.xml?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/pom.xml (added)
+++ shiro/trunk/samples/guice/pom.xml Mon Jun 4 13:26:34 2012
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>shiro-samples</artifactId>
+ <groupId>org.apache.shiro.samples</groupId>
+ <version>1.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>samples-guice</artifactId>
+ <name>Apache Shiro :: Samples :: Guice Web</name>
+ <packaging>war</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>never</forkMode>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>${jetty.version}</version>
+ <configuration>
+ <contextPath>/</contextPath>
+ <connectors>
+ <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+ <port>9080</port>
+ <maxIdleTime>60000</maxIdleTime>
+ </connector>
+ </connectors>
+ <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
+ <filename>./target/yyyy_mm_dd.request.log</filename>
+ <retainDays>90</retainDays>
+ <append>true</append>
+ <extended>false</extended>
+ <logTimeZone>GMT</logTimeZone>
+ </requestLog>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-guice</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jetty.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jsp-2.1-jetty</artifactId>
+ <version>${jetty.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>taglibs</groupId>
+ <artifactId>standard</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java (added)
+++ shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java Mon Jun 4 13:26:34 2012
@@ -0,0 +1,25 @@
+package org.apache.shiro.samples.guice;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.servlet.GuiceServletContextListener;
+import org.apache.shiro.guice.web.ShiroWebModule;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+public class SampleShiroGuiceBootstrap extends GuiceServletContextListener {
+
+ private ServletContext servletContext;
+
+ @Override
+ public void contextInitialized(final ServletContextEvent servletContextEvent) {
+ this.servletContext = servletContextEvent.getServletContext();
+ super.contextInitialized(servletContextEvent);
+ }
+
+ @Override
+ protected Injector getInjector() {
+ return Guice.createInjector(new SampleShiroServletModule(servletContext), ShiroWebModule.guiceFilterModule());
+ }
+}
Added: shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java (added)
+++ shiro/trunk/samples/guice/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java Mon Jun 4 13:26:34 2012
@@ -0,0 +1,44 @@
+package org.apache.shiro.samples.guice;
+
+import com.google.inject.Provides;
+import com.google.inject.name.Names;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.guice.web.ShiroWebModule;
+import org.apache.shiro.realm.text.IniRealm;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class SampleShiroServletModule extends ShiroWebModule {
+ private final ServletContext servletContext;
+
+ public SampleShiroServletModule(ServletContext servletContext) {
+ super(servletContext);
+
+ this.servletContext = servletContext;
+ }
+
+ @Override
+ protected void configureShiroWeb() {
+ bindConstant().annotatedWith(Names.named("shiro.loginUrl")).to("/login.jsp");
+ try {
+ this.bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
+ } catch (NoSuchMethodException e) {
+ addError("Could not locate proper constructor for IniRealm.", e);
+ }
+
+ this.addFilterChain("/login.jsp", AUTHC);
+ this.addFilterChain("/logout", LOGOUT);
+ this.addFilterChain("/account/**", AUTHC);
+ this.addFilterChain("/remoting/**", AUTHC, config(ROLES, "b2bClient"), config(PERMS, "remote:invoke:lan,wan"));
+ }
+
+ @Provides
+ @Singleton
+ Ini loadShiroIni() throws MalformedURLException {
+ URL iniUrl = servletContext.getResource("/WEB-INF/shiro.ini");
+ return Ini.fromResourcePath("url:" + iniUrl.toExternalForm());
+ }
+}
Added: shiro/trunk/samples/guice/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/resources/log4j.properties?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/resources/log4j.properties (added)
+++ shiro/trunk/samples/guice/src/main/resources/log4j.properties Mon Jun 4 13:26:34 2012
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF 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
+#
+# 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.
+#
+# This file is used to format all logging output
+log4j.rootLogger=TRACE, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c]: %m%n
+
+# =============================================================================
+# 3rd Party Libraries
+# OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL
+# =============================================================================
+# ehcache caching manager:
+log4j.logger.net.sf.ehcache=WARN
+
+# Most all Apache libs:
+log4j.logger.org.apache=WARN
+
+# Quartz Enterprise Scheular (java 'cron' utility)
+log4j.logger.org.quartz=WARN
+
+# =============================================================================
+# Apache Shiro
+# =============================================================================
+# Shiro security framework
+log4j.logger.org.apache.shiro=TRACE
+#log4j.logger.org.apache.shiro.realm.text.PropertiesRealm=INFO
+#log4j.logger.org.apache.shiro.cache.ehcache.EhCache=INFO
+#log4j.logger.org.apache.shiro.io=INFO
+#log4j.logger.org.apache.shiro.web.servlet=INFO
+log4j.logger.org.apache.shiro.util.ThreadContext=INFO
Added: shiro/trunk/samples/guice/src/main/webapp/WEB-INF/shiro.ini
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/WEB-INF/shiro.ini?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/WEB-INF/shiro.ini (added)
+++ shiro/trunk/samples/guice/src/main/webapp/WEB-INF/shiro.ini Mon Jun 4 13:26:34 2012
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF 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
+#
+# 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.
+
+# INI configuration is very powerful and flexible, while still remaining succinct.
+# Please http://shiro.apache.org/configuration.html and
+# http://shiro.apache.org/web.html for more.
+
+[main]
+shiro.loginUrl = /login.jsp
+
+[users]
+# format: username = password, role1, role2, ..., roleN
+root = secret,admin
+guest = guest,guest
+presidentskroob = 12345,president
+darkhelmet = ludicrousspeed,darklord,schwartz
+lonestarr = vespa,goodguy,schwartz
+
+[roles]
+# format: roleName = permission1, permission2, ..., permissionN
+admin = *
+schwartz = lightsaber:*
+goodguy = winnebago:drive:eagle5
+
+[urls]
+# The /login.jsp is not restricted to authenticated users (otherwise no one could log in!), but
+# the 'authc' filter must still be specified for it so it can process that url's
+# login submissions. It is 'smart' enough to allow those requests through as specified by the
+# shiro.loginUrl above.
+/login.jsp = authc
+/logout = logout
+/account/** = authc
+/remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"]
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/WEB-INF/web.xml?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/WEB-INF/web.xml (added)
+++ shiro/trunk/samples/guice/src/main/webapp/WEB-INF/web.xml Mon Jun 4 13:26:34 2012
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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.
+ -->
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <listener>
+ <listener-class>org.apache.shiro.samples.guice.SampleShiroGuiceBootstrap</listener-class>
+ </listener>
+
+ <filter>
+ <filter-name>GuiceFilter</filter-name>
+ <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>GuiceFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+</web-app>
Added: shiro/trunk/samples/guice/src/main/webapp/account/index.jsp
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/account/index.jsp?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/account/index.jsp (added)
+++ shiro/trunk/samples/guice/src/main/webapp/account/index.jsp Mon Jun 4 13:26:34 2012
@@ -0,0 +1,36 @@
+<%--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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.
+ --%>
+<%@ include file="../include.jsp" %>
+
+<html>
+<head>
+ <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/>
+</head>
+<body>
+
+<h2>Users only</h2>
+
+<p>You are currently logged in.</p>
+
+<p><a href="<c:url value="/home.jsp"/>">Return to the home page.</a></p>
+
+<p><a href="<c:url value="/logout"/>">Log out.</a></p>
+
+</body>
+</html>
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/home.jsp?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/home.jsp (added)
+++ shiro/trunk/samples/guice/src/main/webapp/home.jsp Mon Jun 4 13:26:34 2012
@@ -0,0 +1,69 @@
+<%--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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.
+ --%>
+<%@ include file="include.jsp" %>
+
+<html>
+<head>
+ <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/>
+ <title>Apache Shiro Quickstart</title>
+</head>
+<body>
+
+<h1>Apache Shiro Quickstart</h1>
+
+<p>Hi <shiro:guest>Guest</shiro:guest><shiro:user><shiro:principal/></shiro:user>!
+ ( <shiro:user><a href="<c:url value="/logout"/>">Log out</a></shiro:user>
+ <shiro:guest><a href="<c:url value="/login.jsp"/>">Log in</a> (sample accounts provided)</shiro:guest> )
+</p>
+
+<p>Welcome to the Apache Shiro Quickstart sample application.
+ This page represents the home page of any web application.</p>
+
+<shiro:user><p>Visit your <a href="<c:url value="/account"/>">account page</a>.</p></shiro:user>
+<shiro:guest><p>If you want to access the user-only <a href="<c:url value="/account"/>">account page</a>,
+ you will need to log-in first.</p></shiro:guest>
+
+<h2>Roles</h2>
+
+<p>To show some taglibs, here are the roles you have and don't have. Log out and log back in under different user
+ accounts to see different roles.</p>
+
+<h3>Roles you have</h3>
+
+<p>
+ <shiro:hasRole name="admin">admin<br/></shiro:hasRole>
+ <shiro:hasRole name="president">president<br/></shiro:hasRole>
+ <shiro:hasRole name="darklord">darklord<br/></shiro:hasRole>
+ <shiro:hasRole name="goodguy">goodguy<br/></shiro:hasRole>
+ <shiro:hasRole name="schwartz">schwartz<br/></shiro:hasRole>
+</p>
+
+<h3>Roles you DON'T have</h3>
+
+<p>
+ <shiro:lacksRole name="admin">admin<br/></shiro:lacksRole>
+ <shiro:lacksRole name="president">president<br/></shiro:lacksRole>
+ <shiro:lacksRole name="darklord">darklord<br/></shiro:lacksRole>
+ <shiro:lacksRole name="goodguy">goodguy<br/></shiro:lacksRole>
+ <shiro:lacksRole name="schwartz">schwartz<br/></shiro:lacksRole>
+</p>
+
+
+</body>
+</html>
Added: shiro/trunk/samples/guice/src/main/webapp/include.jsp
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/include.jsp?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/include.jsp (added)
+++ shiro/trunk/samples/guice/src/main/webapp/include.jsp Mon Jun 4 13:26:34 2012
@@ -0,0 +1,22 @@
+<%--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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 import="org.apache.shiro.SecurityUtils" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/index.jsp?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/index.jsp (added)
+++ shiro/trunk/samples/guice/src/main/webapp/index.jsp Mon Jun 4 13:26:34 2012
@@ -0,0 +1,21 @@
+<%--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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.
+ --%>
+
+<%-- Forward the user to the home page --%>
+<jsp:forward page="home.jsp"/>
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/main/webapp/login.jsp
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/login.jsp?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/login.jsp (added)
+++ shiro/trunk/samples/guice/src/main/webapp/login.jsp Mon Jun 4 13:26:34 2012
@@ -0,0 +1,110 @@
+<%--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF 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
+ ~
+ ~ 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.
+ --%>
+<%@ include file="include.jsp" %>
+
+<html>
+<head>
+ <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/>
+</head>
+<body>
+
+<h2>Please Log in</h2>
+
+<shiro:guest>
+ <p>Here are a few sample accounts to play with in the default text-based Realm (used for this
+ demo and test installs only). Do you remember the movie these names came from? ;)</p>
+
+
+ <style type="text/css">
+ table.sample {
+ border-width: 1px;
+ border-style: outset;
+ border-color: blue;
+ border-collapse: separate;
+ background-color: rgb(255, 255, 240);
+ }
+
+ table.sample th {
+ border-width: 1px;
+ padding: 1px;
+ border-style: none;
+ border-color: blue;
+ background-color: rgb(255, 255, 240);
+ }
+
+ table.sample td {
+ border-width: 1px;
+ padding: 1px;
+ border-style: none;
+ border-color: blue;
+ background-color: rgb(255, 255, 240);
+ }
+ </style>
+
+
+ <table class="sample">
+ <thead>
+ <tr>
+ <th>Username</th>
+ <th>Password</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>root</td>
+ <td>secret</td>
+ </tr>
+ <tr>
+ <td>presidentskroob</td>
+ <td>12345</td>
+ </tr>
+ <tr>
+ <td>darkhelmet</td>
+ <td>ludicrousspeed</td>
+ </tr>
+ <tr>
+ <td>lonestarr</td>
+ <td>vespa</td>
+ </tr>
+ </tbody>
+ </table>
+ <br/><br/>
+</shiro:guest>
+
+<form name="loginform" action="" method="post">
+ <table align="left" border="0" cellspacing="0" cellpadding="3">
+ <tr>
+ <td>Username:</td>
+ <td><input type="text" name="username" maxlength="30"></td>
+ </tr>
+ <tr>
+ <td>Password:</td>
+ <td><input type="password" name="password" maxlength="30"></td>
+ </tr>
+ <tr>
+ <td colspan="2" align="left"><input type="checkbox" name="rememberMe"><font size="2">Remember Me</font></td>
+ </tr>
+ <tr>
+ <td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td>
+ </tr>
+ </table>
+</form>
+
+</body>
+</html>
Added: shiro/trunk/samples/guice/src/main/webapp/style.css
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/main/webapp/style.css?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/main/webapp/style.css (added)
+++ shiro/trunk/samples/guice/src/main/webapp/style.css Mon Jun 4 13:26:34 2012
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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
+ *
+ * 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.
+ */
+body {
+ margin: 15px 0 0 15px;
+ padding: 1px; /*background: #2370cf;*/
+ font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif;
+ color: #000;
+}
+
+table, td {
+ font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif;
+ color: #000;
+}
+
+h1 {
+ font: 24px;
+}
+
+img {
+ border: thin black solid;
+}
+
+#contentBox {
+ text-align: center;
+ width: 50%;
+ margin: auto;
+ margin-top: 50px;
+ color: black;
+ background: #eee;
+ border: thick black solid;
+}
\ No newline at end of file
Added: shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerTest.java
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerTest.java?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerTest.java (added)
+++ shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerTest.java Mon Jun 4 13:26:34 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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
+ *
+ * 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.
+ */
+package org.apache.shiro.samples.guice;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+import java.net.BindException;
+
+import static org.junit.Assert.assertTrue;
+
+public abstract class AbstractContainerTest {
+ public static final int MAX_PORT = 9200;
+
+ protected static PauseableServer server;
+
+ private static int port = 9180;
+
+ protected final WebClient webClient = new WebClient();
+
+ @BeforeClass
+ public static void startContainer() throws Exception {
+ while (server == null && port < MAX_PORT) {
+ try {
+ server = createAndStartServer(port);
+ } catch (BindException e) {
+ System.err.printf("Unable to listen on port %d. Trying next port.", port);
+ port++;
+ }
+ }
+ assertTrue(server.isStarted());
+ }
+
+ private static PauseableServer createAndStartServer(final int port) throws Exception {
+ PauseableServer server = new PauseableServer();
+ Connector connector = new SelectChannelConnector();
+ connector.setPort(port);
+ server.setConnectors(new Connector[]{connector});
+ server.setHandler(new WebAppContext("src/main/webapp", "/"));
+ server.start();
+ return server;
+ }
+
+ protected static String getBaseUri() {
+ return "http://localhost:" + port + "/";
+ }
+
+ @Before
+ public void beforeTest() {
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ }
+
+ public void pauseServer(boolean paused) {
+ if (server != null) server.pause(paused);
+ }
+
+ public static class PauseableServer extends Server {
+ public synchronized void pause(boolean paused) {
+ try {
+ if (paused) for (Connector connector : getConnectors())
+ connector.stop();
+ else for (Connector connector : getConnectors())
+ connector.start();
+ } catch (Exception e) {
+ }
+ }
+ }
+}
Added: shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationTest.java
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationTest.java?rev=1345958&view=auto
==============================================================================
--- shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationTest.java (added)
+++ shiro/trunk/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationTest.java Mon Jun 4 13:26:34 2012
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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
+ *
+ * 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.
+ */
+package org.apache.shiro.samples.guice;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+import com.gargoylesoftware.htmlunit.WebAssert;
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+public class ContainerIntegrationTest extends AbstractContainerTest {
+
+ @Before
+ public void logOut() throws IOException {
+ // Make sure we are logged out
+ final HtmlPage homePage = webClient.getPage(getBaseUri());
+ try {
+ homePage.getAnchorByHref("/logout").click();
+ }
+ catch (ElementNotFoundException e) {
+ //Ignore
+ }
+ }
+
+ @Test
+ public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
+
+ HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
+ HtmlForm form = page.getFormByName("loginform");
+ form.<HtmlInput>getInputByName("username").setValueAttribute("root");
+ form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
+ page = form.<HtmlInput>getInputByName("submit").click();
+ // This'll throw an expection if not logged in
+ page.getAnchorByHref("/logout");
+ }
+
+ @Test
+ public void logInAndRememberMe() throws Exception {
+ HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
+ HtmlForm form = page.getFormByName("loginform");
+ form.<HtmlInput>getInputByName("username").setValueAttribute("root");
+ form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
+ HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe");
+ checkbox.setChecked(true);
+ page = form.<HtmlInput>getInputByName("submit").click();
+ server.stop();
+ server.start();
+ page = webClient.getPage(getBaseUri());
+ // page.getAnchorByHref("/logout");
+ WebAssert.assertLinkPresentWithText(page, "Log out");
+ page = page.getAnchorByHref("/account").click();
+ // login page should be shown again - user remembered but not authenticated
+ WebAssert.assertFormPresent(page, "loginform");
+ }
+
+}
Modified: shiro/trunk/samples/pom.xml
URL: http://svn.apache.org/viewvc/shiro/trunk/samples/pom.xml?rev=1345958&r1=1345957&r2=1345958&view=diff
==============================================================================
--- shiro/trunk/samples/pom.xml (original)
+++ shiro/trunk/samples/pom.xml Mon Jun 4 13:26:34 2012
@@ -39,6 +39,7 @@
<module>spring-client</module>
<module>spring</module>
<module>spring-hibernate</module>
+ <module>guice</module>
</modules>
<reporting>