You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by ad...@apache.org on 2010/10/31 19:16:25 UTC

svn commit: r1029443 - in /shiro/sandbox/struts2: ./ samples/ samples/struts2/ samples/struts2/src/ samples/struts2/src/main/ samples/struts2/src/main/java/ samples/struts2/src/main/java/org/ samples/struts2/src/main/java/org/apache/ samples/struts2/sr...

Author: adc
Date: Sun Oct 31 18:16:24 2010
New Revision: 1029443

URL: http://svn.apache.org/viewvc?rev=1029443&view=rev
Log:
SHIRO-210 Struts 2 example

Added:
    shiro/sandbox/struts2/samples/struts2/
    shiro/sandbox/struts2/samples/struts2/pom.xml
    shiro/sandbox/struts2/samples/struts2/src/
    shiro/sandbox/struts2/samples/struts2/src/main/
    shiro/sandbox/struts2/samples/struts2/src/main/java/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/BootstrapDataPopulator.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/DefaultSampleManager.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Index.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Login.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Logout.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/ValidateableAction.java
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/
    shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/Struts2AuthenticationFilter.java
    shiro/sandbox/struts2/samples/struts2/src/main/resources/
    shiro/sandbox/struts2/samples/struts2/src/main/resources/ehcache.xml
    shiro/sandbox/struts2/samples/struts2/src/main/resources/log4j.properties
    shiro/sandbox/struts2/samples/struts2/src/main/resources/struts.properties
    shiro/sandbox/struts2/samples/struts2/src/main/resources/struts2.xml
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/applicationContext.xml
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/include.jsp
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/login.jsp
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/sampleIndex.jsp
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/web.xml
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/index.jsp
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/logo.png   (with props)
    shiro/sandbox/struts2/samples/struts2/src/main/webapp/shiro.css
Modified:
    shiro/sandbox/struts2/pom.xml
    shiro/sandbox/struts2/samples/pom.xml

Modified: shiro/sandbox/struts2/pom.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/pom.xml?rev=1029443&r1=1029442&r2=1029443&view=diff
==============================================================================
--- shiro/sandbox/struts2/pom.xml (original)
+++ shiro/sandbox/struts2/pom.xml Sun Oct 31 18:16:24 2010
@@ -263,6 +263,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.shiro</groupId>
+                <artifactId>shiro-struts2</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.shiro</groupId>
                 <artifactId>shiro-aspectj</artifactId>
                 <version>${project.version}</version>
             </dependency>
@@ -459,6 +464,11 @@
                 <version>${struts2.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.struts</groupId>
+                <artifactId>struts2-spring-plugin</artifactId>
+                <version>${struts2.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.hibernate</groupId>
                 <artifactId>hibernate-annotations</artifactId>
                 <version>3.2.1.ga</version>

Modified: shiro/sandbox/struts2/samples/pom.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/pom.xml?rev=1029443&r1=1029442&r2=1029443&view=diff
==============================================================================
--- shiro/sandbox/struts2/samples/pom.xml (original)
+++ shiro/sandbox/struts2/samples/pom.xml Sun Oct 31 18:16:24 2010
@@ -38,6 +38,7 @@
         <module>spring-client</module>
         <module>spring</module>
         <module>spring-hibernate</module>
+        <module>struts2</module>
     </modules>
 
     <reporting>

Added: shiro/sandbox/struts2/samples/struts2/pom.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/pom.xml?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/pom.xml (added)
+++ shiro/sandbox/struts2/samples/struts2/pom.xml Sun Oct 31 18:16:24 2010
@@ -0,0 +1,139 @@
+<?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.
+  -->
+<!--suppress osmorcNonOsgiMavenDependency	-->
+<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/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.apache.shiro.samples</groupId>
+        <artifactId>shiro-samples</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>samples-struts2</artifactId>
+    <name>Apache Shiro :: Samples :: Struts 2</name>
+    <packaging>war</packaging>
+    <description>
+    	Struts 2 based web application sample demonstrating Shiro's
+        capabilities. To launch the webstart application successfully, you
+        need to run "mvn jetty:run".
+    </description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.mortbay.jetty</groupId>
+                <artifactId>maven-jetty-plugin</artifactId>
+                <version>${jetty.version}</version>
+                <configuration>
+                    <contextPath>/shiro</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>
+                <dependencies>
+                    <dependency>
+                        <groupId>hsqldb</groupId>
+                        <artifactId>hsqldb</artifactId>
+                        <version>${hsqldb.version}</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shiro.samples</groupId>
+            <artifactId>samples-spring-client</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-ehcache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-spring</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-struts2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.struts</groupId>
+            <artifactId>struts2-spring-plugin</artifactId>
+            <scope>runtime</scope>
+        </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>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>hsqldb</groupId>
+            <artifactId>hsqldb</artifactId>
+            <version>${hsqldb.version}</version>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>jstl</artifactId>
+            <version>1.2</version>
+            <scope>runtime</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/BootstrapDataPopulator.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/BootstrapDataPopulator.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/BootstrapDataPopulator.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/BootstrapDataPopulator.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,120 @@
+/*
+ * 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.spring;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.shiro.crypto.hash.Sha256Hash;
+
+/**
+ * A data populator that creates a set of security tables and test data that can be used by the
+ * Shiro Spring sample application to demonstrate the use of the {@link org.apache.shiro.realm.jdbc.JdbcRealm}
+ * The tables created by this class follow the default table and column names that {@link org.apache.shiro.realm.jdbc.JdbcRealm} uses.
+ *
+ */
+public class BootstrapDataPopulator implements InitializingBean {
+
+    private static final String CREATE_TABLES = "create table users (\n" +
+            "    username varchar(255) primary key,\n" +
+            "    password varchar(255) not null\n" +
+            ");\n" +
+            "\n" +
+            "create table roles (\n" +
+            "    role_name varchar(255) primary key\n" +
+            ");\n" +
+            "\n" +
+            "create table user_roles (\n" +
+            "    username varchar(255) not null,\n" +
+            "    role_name varchar(255) not null,\n" +
+            "    constraint user_roles_uq unique ( username, role_name )\n" +
+            ");\n" +
+            "\n" +
+            "create table roles_permissions (\n" +
+            "    role_name varchar(255) not null,\n" +
+            "    permission varchar(255) not null,\n" +
+            "    primary key (role_name, permission)\n" +
+            ");";
+
+    private static final Logger log = LoggerFactory.getLogger(BootstrapDataPopulator.class);
+
+    protected DataSource dataSource = null;
+
+    public void setDataSource(DataSource dataSource) {
+        this.dataSource = dataSource;
+    }
+
+    public void afterPropertiesSet() throws Exception {
+        //because we're using an in-memory hsqldb for the sample app, a new one will be created each time the
+        //app starts, so create the tables and insert the 2 sample users on bootstrap:
+
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
+        jdbcTemplate.execute(CREATE_TABLES);
+
+        //password is 'user1' SHA hashed and base64 encoded:
+        //The first argument to the hash constructor is the actual value to be hased.  The 2nd is the
+        //salt.  In this simple demo scenario, the username and the password are the same, but to clarify the
+        //distinction, you would see this in practice:
+        //new Sha256Hash( <password>, <username> )
+        String query = "insert into users values ('user1', '" + new Sha256Hash("user1", "user1").toBase64() + "' )";
+        jdbcTemplate.execute(query);
+        log.debug("Created user1.");
+
+        //password is 'user2' SHA hashed and base64 encoded:
+        query = "insert into users values ( 'user2', '" + new Sha256Hash("user2", "user2").toBase64() + "' )";
+        jdbcTemplate.execute(query);
+        log.debug("Created user2.");
+
+        query = "insert into roles values ( 'role1' )";
+        jdbcTemplate.execute(query);
+        log.debug("Created role1");
+
+        query = "insert into roles values ( 'role2' )";
+        jdbcTemplate.execute(query);
+        log.debug("Created role2");
+
+        query = "insert into roles_permissions values ( 'role1', 'permission1')";
+        jdbcTemplate.execute(query);
+        log.debug("Created permission 1 for role 1");
+
+        query = "insert into roles_permissions values ( 'role1', 'permission2')";
+        jdbcTemplate.execute(query);
+        log.debug("Created permission 2 for role 1");
+
+        query = "insert into roles_permissions values ( 'role2', 'permission1')";
+        jdbcTemplate.execute(query);
+        log.debug("Created permission 1 for role 2");
+
+        query = "insert into user_roles values ( 'user1', 'role1' )";
+        jdbcTemplate.execute(query);
+        query = "insert into user_roles values ( 'user1', 'role2' )";
+        jdbcTemplate.execute(query);
+        log.debug("Assigned user1 roles role1 and role2");
+
+        query = "insert into user_roles values ( 'user2', 'role2' )";
+        jdbcTemplate.execute(query);
+        log.debug("Assigned user2 role role2");
+    }
+
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/DefaultSampleManager.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/DefaultSampleManager.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/DefaultSampleManager.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/spring/DefaultSampleManager.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,105 @@
+/*
+ * 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.spring;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.subject.Subject;
+
+
+/**
+ * Default implementation of the {@link SampleManager} interface that stores
+ * and retrieves a value from the user's session.
+ *
+ * @since 0.1
+ */
+public class DefaultSampleManager implements SampleManager {
+
+    /*--------------------------------------------
+    |             C O N S T A N T S             |
+    ============================================*/
+    /**
+     * Key used to store the value in the user's session.
+     */
+    private static final String VALUE_KEY = "sample_value";
+
+    /*--------------------------------------------
+    |    I N S T A N C E   V A R I A B L E S    |
+    ============================================*/
+    private static final Logger log = LoggerFactory.getLogger(DefaultSampleManager.class);
+
+    /*--------------------------------------------
+    |         C O N S T R U C T O R S           |
+    ============================================*/
+
+    /*--------------------------------------------
+    |  A C C E S S O R S / M O D I F I E R S    |
+    ============================================*/
+
+    /*--------------------------------------------
+    |               M E T H O D S               |
+    ============================================*/
+
+    public String getValue() {
+        String value = null;
+
+        Subject subject = SecurityUtils.getSubject();
+        Session session = subject.getSession(false);
+        if (session != null) {
+            value = (String) session.getAttribute(VALUE_KEY);
+            if (log.isDebugEnabled()) {
+                log.debug("retrieving session key [" + VALUE_KEY + "] with value [" + value + "] on session with id [" + session.getId() + "]");
+            }
+        }
+
+        return value;
+    }
+
+    public void setValue(String newValue) {
+        Subject subject = SecurityUtils.getSubject();
+        Session session = subject.getSession();
+
+        if (log.isDebugEnabled()) {
+            log.debug("saving session key [" + VALUE_KEY + "] with value [" + newValue + "] on session with id [" + session.getId() + "]");
+        }
+
+        session.setAttribute(VALUE_KEY, newValue);
+    }
+
+    public void secureMethod1() {
+        if (log.isInfoEnabled()) {
+            log.info("Secure method 1 called...");
+        }
+    }
+
+    public void secureMethod2() {
+        if (log.isInfoEnabled()) {
+            log.info("Secure method 2 called...");
+        }
+    }
+
+    public void secureMethod3() {
+        if (log.isInfoEnabled()) {
+            log.info("Secure method 3 called...");
+        }
+    }
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Index.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Index.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Index.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Index.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,40 @@
+/**
+ * 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.struts2.actions;
+
+import com.opensymphony.xwork2.Action;
+
+import org.apache.shiro.samples.spring.SampleManager;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Index implements Action {
+
+    private SampleManager sampleManager;
+
+    public void setSampleManager(SampleManager sampleManager) {
+        this.sampleManager = sampleManager;
+    }
+
+    public String execute() throws Exception {
+        return SUCCESS;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Login.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Login.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Login.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Login.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,82 @@
+/**
+ * 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.struts2.actions;
+
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.StringUtils;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Login extends ValidateableAction {
+
+    private Subject shiroUser;
+    private boolean first;
+    private String username;
+    private String password;
+
+    public void setShiroUser(Subject shiroUser) {
+        this.shiroUser = shiroUser;
+    }
+
+    public void setFirst(boolean first) {
+        this.first = first;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public void validate() {
+        if (!first && !shiroUser.isAuthenticated()) {
+            if (!StringUtils.hasText(username)) addFieldError("username", "Username cannot be empty");
+            if (!StringUtils.hasText(password)) addFieldError("password", "Password cannot be empty");
+        }
+    }
+
+    public String execute() throws Exception {
+        if (!first && !shiroUser.isAuthenticated()) {
+            try {
+                shiroUser.login(new UsernamePasswordToken(username, password));
+
+                return SUCCESS;
+            }
+            catch (AuthenticationException ae) {
+                addActionError("No user was found with those credentials. Double check your info and try again.");
+            }
+        }
+
+        return INPUT;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Logout.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Logout.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Logout.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/Logout.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,60 @@
+/**
+ * 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.struts2.actions;
+
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import com.opensymphony.xwork2.Action;
+
+import org.apache.struts2.interceptor.ServletRequestAware;
+import org.apache.struts2.interceptor.SessionAware;
+
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.subject.Subject;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Logout implements Action, ServletRequestAware {
+
+    private HttpServletRequest request;
+
+    public void setServletRequest(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    public String execute() throws Exception {
+
+        Subject subject = SecurityUtils.getSubject();
+        if (subject != null) {
+            subject.logout();
+        }
+
+        HttpSession session = request.getSession(false);
+        if( session != null ) {
+            session.invalidate();
+        }
+
+        return SUCCESS;
+    }
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/ValidateableAction.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/ValidateableAction.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/ValidateableAction.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/actions/ValidateableAction.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,92 @@
+/**
+ * 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.struts2.actions;
+
+import java.util.Collection;
+import java.util.Map;
+
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.Validateable;
+import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.ValidationAwareSupport;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public abstract class ValidateableAction implements Action, Validateable, ValidationAware {
+
+    private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
+
+    public void setActionErrors(Collection errorMessages) {
+        validationAware.setActionErrors(errorMessages);
+    }
+
+    public Collection getActionErrors() {
+        return validationAware.getActionErrors();
+    }
+
+    public void setActionMessages(Collection messages) {
+        validationAware.setActionMessages(messages);
+    }
+
+    public Collection getActionMessages() {
+        return validationAware.getActionMessages();
+    }
+
+    public void setFieldErrors(Map errorMap) {
+        validationAware.setFieldErrors(errorMap);
+    }
+
+    public Map getFieldErrors() {
+        return validationAware.getFieldErrors();
+    }
+
+    public void addActionError(String anErrorMessage) {
+        validationAware.addActionError(anErrorMessage);
+    }
+
+    public void addActionMessage(String aMessage) {
+        validationAware.addActionMessage(aMessage);
+    }
+
+    public void addFieldError(String fieldName, String errorMessage) {
+        validationAware.addFieldError(fieldName, errorMessage);
+    }
+
+    public boolean hasActionErrors() {
+        return validationAware.hasActionErrors();
+    }
+
+    public boolean hasActionMessages() {
+        return validationAware.hasActionMessages();
+    }
+
+    public boolean hasErrors() {
+        return validationAware.hasErrors();
+    }
+
+    public boolean hasFieldErrors() {
+        return validationAware.hasFieldErrors();
+    }
+
+    public void clearErrorsAndMessages() {
+        validationAware.clearErrorsAndMessages();
+    }
+}

Added: shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/Struts2AuthenticationFilter.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/Struts2AuthenticationFilter.java?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/Struts2AuthenticationFilter.java (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/java/org/apache/shiro/samples/struts2/filter/Struts2AuthenticationFilter.java Sun Oct 31 18:16:24 2010
@@ -0,0 +1,43 @@
+/**
+ * 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.struts2.filter;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter;
+
+
+/**
+ * This filter extends {@link PassThruAuthenticationFilter}.  It overrides
+ * {@link PassThruAuthenticationFilter#isLoginRequest(ServletRequest, ServletResponse)}
+ * so that the login URL's query parameters do not participate in the matching
+ * of the servlet request.
+ *
+ * @version $Revision: $ $Date: $
+ */
+public class Struts2AuthenticationFilter extends PassThruAuthenticationFilter {
+
+    @Override
+    protected boolean isLoginRequest(ServletRequest request, ServletResponse response) {
+        String loginUrl = getLoginUrl();
+        if (loginUrl.contains("?")) loginUrl = loginUrl.substring(0, loginUrl.indexOf('?'));
+        return pathsMatch(loginUrl, request);
+    }
+}
\ No newline at end of file

Added: shiro/sandbox/struts2/samples/struts2/src/main/resources/ehcache.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/resources/ehcache.xml?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/resources/ehcache.xml (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/resources/ehcache.xml Sun Oct 31 18:16:24 2010
@@ -0,0 +1,98 @@
+<!--
+  ~ 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.
+  -->
+
+<!-- EhCache XML configuration file used for Shiro spring sample application -->
+<ehcache>
+
+    <!-- Sets the path to the directory where cache .data files are created.
+
+If the path is a Java System Property it is replaced by
+its value in the running VM.
+
+The following properties are translated:
+user.home - User's home directory
+user.dir - User's current working directory
+java.io.tmpdir - Default temp file path -->
+    <diskStore path="java.io.tmpdir/shiro-spring-sample"/>
+
+
+    <!--Default Cache configuration. These will applied to caches programmatically created through
+    the CacheManager.
+
+    The following attributes are required:
+
+    maxElementsInMemory            - Sets the maximum number of objects that will be created in memory
+    eternal                        - Sets whether elements are eternal. If eternal,  timeouts are ignored and the
+                                     element is never expired.
+    overflowToDisk                 - Sets whether elements can overflow to disk when the in-memory cache
+                                     has reached the maxInMemory limit.
+
+    The following attributes are optional:
+    timeToIdleSeconds              - Sets the time to idle for an element before it expires.
+                                     i.e. The maximum amount of time between accesses before an element expires
+                                     Is only used if the element is not eternal.
+                                     Optional attribute. A value of 0 means that an Element can idle for infinity.
+                                     The default value is 0.
+    timeToLiveSeconds              - Sets the time to live for an element before it expires.
+                                     i.e. The maximum time between creation time and when an element expires.
+                                     Is only used if the element is not eternal.
+                                     Optional attribute. A value of 0 means that and Element can live for infinity.
+                                     The default value is 0.
+    diskPersistent                 - Whether the disk store persists between restarts of the Virtual Machine.
+                                     The default value is false.
+    diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
+                                     is 120 seconds.
+    memoryStoreEvictionPolicy      - Policy would be enforced upon reaching the maxElementsInMemory limit. Default
+                                     policy is Least Recently Used (specified as LRU). Other policies available -
+                                     First In First Out (specified as FIFO) and Less Frequently Used
+                                     (specified as LFU)
+    -->
+
+    <defaultCache
+            maxElementsInMemory="10000"
+            eternal="false"
+            timeToIdleSeconds="120"
+            timeToLiveSeconds="120"
+            overflowToDisk="false"
+            diskPersistent="false"
+            diskExpiryThreadIntervalSeconds="120"
+            />
+
+    <!-- We want eternal="true" (with no timeToIdle or timeToLive settings) because Shiro manages session
+expirations explicitly.  If we set it to false and then set corresponding timeToIdle and timeToLive properties,
+ehcache would evict sessions without Shiro's knowledge, which would cause many problems
+(e.g. "My Shiro session timeout is 30 minutes - why isn't a session available after 2 minutes?"
+Answer - ehcache expired it due to the timeToIdle property set to 120 seconds.)
+
+diskPersistent=true since we want an enterprise session management feature - ability to use sessions after
+even after a JVM restart.  -->
+    <cache name="shiro-activeSessionCache"
+           maxElementsInMemory="10000"
+           eternal="true"
+           overflowToDisk="true"
+           diskPersistent="true"
+           diskExpiryThreadIntervalSeconds="600"/>
+
+    <cache name="org.apache.shiro.realm.SimpleAccountRealm.authorization"
+           maxElementsInMemory="100"
+           eternal="false"
+           timeToLiveSeconds="600"
+           overflowToDisk="false"/>
+
+</ehcache>

Added: shiro/sandbox/struts2/samples/struts2/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/resources/log4j.properties?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/resources/log4j.properties (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/resources/log4j.properties Sun Oct 31 18:16:24 2010
@@ -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.
+#
+log4j.rootLogger=INFO, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n
+
+# General Apache libraries
+log4j.logger.org.apache=WARN
+
+# Spring
+log4j.logger.org.springframework=WARN
+
+# Default Shiro logging
+log4j.logger.org.apache.shiro=TRACE
+
+# Disable verbose logging
+log4j.logger.org.apache.shiro.util.ThreadContext=WARN
+log4j.logger.org.apache.shiro.cache.ehcache.EhCache=WARN

Added: shiro/sandbox/struts2/samples/struts2/src/main/resources/struts.properties
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/resources/struts.properties?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/resources/struts.properties (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/resources/struts.properties Sun Oct 31 18:16:24 2010
@@ -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.
+#
+struts.objectFactory=org.apache.struts2.spring.StrutsSpringObjectFactory
+struts.action.extension=jspa
+struts.ui.theme=xhtml

Added: shiro/sandbox/struts2/samples/struts2/src/main/resources/struts2.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/resources/struts2.xml?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/resources/struts2.xml (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/resources/struts2.xml Sun Oct 31 18:16:24 2010
@@ -0,0 +1,68 @@
+<?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.
+  -->
+<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
+<struts>
+    <include file="struts-default.xml"/>
+
+    <package name="common" extends="struts-default">
+
+        <interceptors>
+
+            <interceptor name="shiroUser" class="org.apache.shiro.struts2.CurrentShiroUserInterceptor"/>
+
+            <interceptor-stack name="shiro-default">
+                <interceptor-ref name="shiroUser"/>
+                <interceptor-ref name="defaultStack"/>
+            </interceptor-stack>
+
+        </interceptors>
+
+        <default-interceptor-ref name="shiro-default"/>
+
+    </package>
+
+    <package name="signin" extends="common" namespace="/signin">
+
+        <action name="login" class="org.apache.shiro.samples.struts2.actions.Login">
+            <result name="success" type="redirectAction">
+                <param name="actionName">view</param>
+                <param name="namespace">/home</param>
+            </result>
+            <result name="input">/WEB-INF/resources/login.jsp</result>
+        </action>
+
+        <action name="logout" class="org.apache.shiro.samples.struts2.actions.Logout">
+            <result name="success" type="redirectAction">
+                <param name="actionName">login</param>
+                <param name="namespace">/signin</param>
+                <param name="first">true</param>
+            </result>
+        </action>
+
+    </package>
+
+    <package name="home" extends="common" namespace="/home">
+
+        <action name="view" class="org.apache.shiro.samples.struts2.actions.Index">
+            <result name="success">/WEB-INF/resources/sampleIndex.jsp</result>
+        </action>
+
+    </package>
+</struts>

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/applicationContext.xml?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/applicationContext.xml (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/applicationContext.xml Sun Oct 31 18:16:24 2010
@@ -0,0 +1,138 @@
+<?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.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
+
+    <!-- Sample RDBMS data source that would exist in any application - not Shiro related. -->
+    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+        <property name="url" value="jdbc:hsqldb:mem:shiro-spring"/>
+        <property name="username" value="sa"/>
+    </bean>
+    <!-- Populates the sample database with sample users and roles. -->
+    <bean id="bootstrapDataPopulator" class="org.apache.shiro.samples.spring.BootstrapDataPopulator">
+        <property name="dataSource" ref="dataSource"/>
+    </bean>
+
+    <!-- Simulated business-tier "Manager", not Shiro related, just an example -->
+    <bean id="sampleManager" class="org.apache.shiro.samples.spring.DefaultSampleManager"/>
+
+    <!-- =========================================================
+         Shiro Core Components - Not Spring Specific
+         ========================================================= -->
+    <!-- Shiro's main business-tier object for web-enabled applications
+         (use DefaultSecurityManager instead when there is no web environment)-->
+    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
+        <property name="cacheManager" ref="cacheManager"/>
+        <!-- Single realm app.  If you have multiple realms, use the 'realms' property instead. -->
+        <property name="realm" ref="jdbcRealm"/>
+
+        <!-- TODO: SHIRO-212 investigate why setting the session mode to native breaks session management --> 
+        <!--<property name="sessionMode" value="native"/>-->
+    </bean>
+
+    <!-- Let's use some enterprise caching support for better performance.  You can replace this with any enterprise
+         caching framework implementation that you like (Terracotta+Ehcache, Coherence, GigaSpaces, etc -->
+    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
+        <!-- Set a net.sf.ehcache.CacheManager instance here if you already have one.  If not, a new one
+             will be creaed with a default config:
+             <property name="cacheManager" ref="ehCacheManager"/> -->
+        <!-- If you don't have a pre-built net.sf.ehcache.CacheManager instance to inject, but you want
+             a specific Ehcache configuration to be used, specify that here.  If you don't, a default
+             will be used.:
+        <property name="cacheManagerConfigFile" value="classpath:some/path/to/ehcache.xml"/> -->
+    </bean>
+
+    <!-- Used by the SecurityManager to access security data (users, roles, etc).
+         Many other realm implementations can be used too (PropertiesRealm,
+         LdapRealm, etc. -->
+    <bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
+        <property name="name" value="jdbcRealm"/>
+        <property name="dataSource" ref="dataSource"/>
+        <property name="credentialsMatcher">
+            <!-- The 'bootstrapDataPopulator' Sha256 hashes the password
+                 (using the username as the salt) then base64 encodes it: -->
+            <bean class="org.apache.shiro.authc.credential.Sha256CredentialsMatcher">
+                <!-- true means hex encoded, false means base64 encoded -->
+                <property name="storedCredentialsHexEncoded" value="false"/>
+                <!-- We salt the password using the username, the most common practice: -->
+                <property name="hashSalted" value="true"/>
+            </bean>
+        </property>
+    </bean>
+
+    <!-- =========================================================
+         Shiro Spring-specific integration
+         ========================================================= -->
+    <!-- Post processor that automatically invokes init() and destroy() methods
+         for Spring-configured Shiro objects so you don't have to
+         1) specify an init-method and destroy-method attributes for every bean
+            definition and
+         2) even know which Shiro objects require these methods to be
+            called. -->
+    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
+
+    <!-- Enable Shiro Annotations for Spring-configured beans.  Only run after
+         the lifecycleBeanProcessor has run: -->
+    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
+          depends-on="lifecycleBeanPostProcessor"/>
+    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
+        <property name="securityManager" ref="securityManager"/>
+    </bean>
+
+    <!-- Secure Spring remoting:  Ensure any Spring Remoting method invocations can be associated
+         with a Subject for security checks. -->
+    <bean id="secureRemoteInvocationExecutor" class="org.apache.shiro.spring.remoting.SecureRemoteInvocationExecutor">
+        <property name="securityManager" ref="securityManager"/>
+    </bean>
+
+    <!-- Define the Shiro Filter here (as a FactoryBean) instead of directly in web.xml -
+         web.xml uses the DelegatingFilterProxy to access this bean.  This allows us
+         to wire things with more control as well utilize nice Spring things such as
+         PropertiesPlaceholderConfigurer and abstract beans or anything else we might need: -->
+    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
+        <property name="securityManager" ref="securityManager"/>
+        <property name="loginUrl" value="/signin/login.jspa?first=true"/>
+        <!--<property name="successUrl" value="/home/view"/>-->
+        <!--<property name="unauthorizedUrl" value="/s/unauthorized"/>-->
+        <!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean
+             defined will be automatically acquired and available via its beanName in chain
+             definitions, but you can perform overrides or parent/child consolidated configuration
+             here if you like: -->
+        <!-- <property name="filters">
+            <util:map>
+                <entry key="aName" value-ref="someFilterPojo"/>
+            </util:map>
+        </property> -->
+        <property name="filterChainDefinitions">
+            <value>
+                /signin/** = s2Filter
+                /home/** = s2Filter
+            </value>
+        </property>
+    </bean>
+
+    <bean id="s2Filter" class="org.apache.shiro.samples.struts2.filter.Struts2AuthenticationFilter"/>
+
+</beans>

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/include.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/include.jsp?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/include.jsp (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/include.jsp Sun Oct 31 18:16:24 2010
@@ -0,0 +1,24 @@
+<%--
+  ~ 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 session="false" %>
+
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
\ No newline at end of file

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/login.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/login.jsp?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/login.jsp (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/login.jsp Sun Oct 31 18:16:24 2010
@@ -0,0 +1,46 @@
+<%--
+  ~ 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" %>
+
+<%@ page contentType="text/html; charset=iso-8859-1" isELIgnored="false" %>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+
+<head>
+    <link type="text/css" rel="stylesheet" href="<c:url value="/shiro.css"/>"/>
+</head>
+
+<body onload="document.forms[0].elements[0].focus();">
+
+<div id="contentBox">
+
+    <h1>Shiro Login</h1>
+
+    <s:actionerror/>
+    <s:form namespace="/signin" action="login">
+        <s:textfield cssClass="label" name="username" label="Username"/>
+        <s:password cssClass="label" name="password" label="Password"/>
+        <s:submit cssClass="button" type="button"/>
+    </s:form>
+
+    <p>Try logging in with username/passwords: user1/user1 and user2/user2.</p>
+
+</div>
+</body>
+</html>

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/sampleIndex.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/sampleIndex.jsp?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/sampleIndex.jsp (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/resources/sampleIndex.jsp Sun Oct 31 18:16:24 2010
@@ -0,0 +1,77 @@
+<%--
+  ~ 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="/shiro.css"/>"/>
+</head>
+
+<body>
+
+<div id="contentBox">
+    <img src="<c:url value="/logo.png"/>" style="margin-top:20px; border:0"/><br/>
+
+    <h2>You have successfully logged in as <shiro:principal/>.</h2>
+
+    Session ID: ${subjectSession.id}
+
+    <h3>Session Attribute Keys</h3>
+    <table border="1">
+        <tr>
+            <th>Key</th>
+            <th>Value</th>
+        </tr>
+        <c:forEach items="${sessionAttributes}" var="entry">
+            <tr>
+                <td>${entry.key}</td>
+                <td>${entry.value}</td>
+            </tr>
+        </c:forEach>
+    </table>
+
+    <p style="font-weight: bold;">
+        <shiro:hasRole name="role1">You have role 1.<br/></shiro:hasRole>
+        <shiro:lacksRole name="role1">You do not have role 1.<br/></shiro:lacksRole>
+        <shiro:hasRole name="role2">You have role 2.<br/></shiro:hasRole>
+        <shiro:lacksRole name="role2">You do not have role 2.<br/></shiro:lacksRole>
+    </p>
+
+    <p style="font-weight: bold;">
+        <shiro:hasPermission name="permission1">You have permission 1.<br/></shiro:hasPermission>
+        <shiro:lacksPermission name="permission1">You do not have permission 1.<br/></shiro:lacksPermission>
+        <shiro:hasPermission name="permission2">You have permission 2.<br/></shiro:hasPermission>
+        <shiro:lacksPermission name="permission2">You do not have permission 2.<br/></shiro:lacksPermission>
+    </p>
+
+
+    <form action="<c:url value="/s/index"/>" method="POST">
+        Enter value here to store in session: <input type="text" name="value" value="${command.value}" size="30"/>
+        <input type="submit" value="Save"/>
+        <button type="button" onclick="document.location.href='<c:url value="/s/index"/>';">Refresh</button>
+    </form>
+
+
+    <p>
+        Click <a href="<s:url action='logout' namespace='/signin'/>">here</a> to logout.
+    </p>
+</div>
+</body>
+</html>
\ No newline at end of file

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/web.xml?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/web.xml (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/WEB-INF/web.xml Sun Oct 31 18:16:24 2010
@@ -0,0 +1,89 @@
+<?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">
+
+    <!-- ==================================================================
+         Context parameters
+         ================================================================== -->
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>
+            /WEB-INF/applicationContext.xml
+        </param-value>
+    </context-param>
+
+    <!--
+    - Key of the system property that should specify the root directory of this
+    - web app. Applied by WebAppRootListener or Log4jConfigListener.
+    -->
+    <context-param>
+        <param-name>webAppRootKey</param-name>
+        <param-value>struts2-sample.webapp.root</param-value>
+    </context-param>
+
+    <!-- ==================================================================
+         Servlet listeners
+         ================================================================== -->
+    <listener>
+        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
+    </listener>
+    <listener>
+        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+    </listener>
+
+    <!-- ==================================================================
+         Filters
+         ================================================================== -->
+    <!-- Shiro Filter is defined in the spring application context: -->
+    <filter>
+        <filter-name>shiroFilter</filter-name>
+        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+    </filter>
+
+    <filter>
+        <filter-name>struts2Filter</filter-name>
+        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
+        <init-param>
+            <param-name>config</param-name>
+            <param-value>struts2.xml</param-value>
+        </init-param>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>shiroFilter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+    <filter-mapping>
+        <filter-name>struts2Filter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <!-- ==================================================================
+         Welcome file list
+         ================================================================== -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+
+</web-app>

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/index.jsp?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/index.jsp (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/index.jsp Sun Oct 31 18:16:24 2010
@@ -0,0 +1,29 @@
+<%--
+  ~ 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="/WEB-INF/resources/include.jsp" %>
+
+<html>
+<head>
+    <meta http-equiv="Refresh" content="0; url=<c:url value="/s/login"/>">
+</head>
+<body>
+Please wait...
+</body>
+
+</html>
\ No newline at end of file

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/logo.png
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/logo.png?rev=1029443&view=auto
==============================================================================
Binary file - no diff available.

Propchange: shiro/sandbox/struts2/samples/struts2/src/main/webapp/logo.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: shiro/sandbox/struts2/samples/struts2/src/main/webapp/shiro.css
URL: http://svn.apache.org/viewvc/shiro/sandbox/struts2/samples/struts2/src/main/webapp/shiro.css?rev=1029443&view=auto
==============================================================================
--- shiro/sandbox/struts2/samples/struts2/src/main/webapp/shiro.css (added)
+++ shiro/sandbox/struts2/samples/struts2/src/main/webapp/shiro.css Sun Oct 31 18:16:24 2010
@@ -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.
+ */
+body {
+    margin: 1px;
+    padding: 1px;
+    background: #fff;
+    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 #ccc solid;
+}
\ No newline at end of file