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/24 04:32:22 UTC
svn commit: r1026733 - in /shiro/sandbox/salty/samples: ./ salty/ salty/src/
salty/src/main/ salty/src/main/java/ salty/src/main/java/org/
salty/src/main/java/org/salty/ salty/src/main/java/org/salty/shiro/
salty/src/main/java/org/salty/shiro/util/ sal...
Author: adc
Date: Sun Oct 24 02:32:21 2010
New Revision: 1026733
URL: http://svn.apache.org/viewvc?rev=1026733&view=rev
Log:
Rough, non-working, sketch in a simple implementation for salty realms
Added:
shiro/sandbox/salty/samples/salty/
shiro/sandbox/salty/samples/salty/pom.xml
shiro/sandbox/salty/samples/salty/src/
shiro/sandbox/salty/samples/salty/src/main/
shiro/sandbox/salty/samples/salty/src/main/java/
shiro/sandbox/salty/samples/salty/src/main/java/org/
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Base64Encoder.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Encoder.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Hasher.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/HexEncoder.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MessageDigestHasher.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MockPersonDao.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PasswordHasher.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Person.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PersonDao.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyAuthenticationInfo.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyCredentialsMatcher.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyRealm.java
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/
shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/HexSupport.java
shiro/sandbox/salty/samples/salty/src/main/resources/
shiro/sandbox/salty/samples/salty/src/main/resources/log4j.properties
shiro/sandbox/salty/samples/salty/src/main/webapp/
shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/
shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/applicationContext.xml
shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/web.xml
shiro/sandbox/salty/samples/salty/src/main/webapp/account/
shiro/sandbox/salty/samples/salty/src/main/webapp/account/index.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/home.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/include.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/index.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/login.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/logout.jsp
shiro/sandbox/salty/samples/salty/src/main/webapp/style.css
shiro/sandbox/salty/samples/salty/src/test/
shiro/sandbox/salty/samples/salty/src/test/java/
shiro/sandbox/salty/samples/salty/src/test/java/org/
shiro/sandbox/salty/samples/salty/src/test/java/org/apache/
shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/
shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/
shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/AbstractContainerTest.java
shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
shiro/sandbox/salty/samples/salty/src/test/resources/
shiro/sandbox/salty/samples/salty/src/test/resources/salty.properties
Modified:
shiro/sandbox/salty/samples/pom.xml
Modified: shiro/sandbox/salty/samples/pom.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/pom.xml?rev=1026733&r1=1026732&r2=1026733&view=diff
==============================================================================
--- shiro/sandbox/salty/samples/pom.xml (original)
+++ shiro/sandbox/salty/samples/pom.xml Sun Oct 24 02:32:21 2010
@@ -35,6 +35,7 @@
<module>aspectj</module>
<module>quickstart</module>
<module>web</module>
+ <module>salty</module>
<module>spring-client</module>
<module>spring</module>
<module>spring-hibernate</module>
Added: shiro/sandbox/salty/samples/salty/pom.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/pom.xml?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/pom.xml (added)
+++ shiro/sandbox/salty/samples/salty/pom.xml Sun Oct 24 02:32:21 2010
@@ -0,0 +1,131 @@
+<?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-salty</artifactId>
+ <name>Apache Shiro :: Samples :: Salty 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-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-web</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>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </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>
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Base64Encoder.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Base64Encoder.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Base64Encoder.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Base64Encoder.java Sun Oct 24 02:32:21 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.salty.shiro;
+
+import java.io.IOException;
+
+import org.apache.shiro.codec.Base64;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Base64Encoder implements Encoder
+{
+ public String convert(byte[] buffer)
+ {
+ return Base64.decodeToString(buffer);
+ }
+
+ public byte[] convert(String buffer) throws IOException
+ {
+ return Base64.encode(buffer.getBytes());
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Encoder.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Encoder.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Encoder.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Encoder.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.salty.shiro;
+
+import java.io.IOException;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public interface Encoder
+{
+ /**
+ * Encode a byte array into a string.
+ *
+ * @param buffer the byte array to be encoded
+ * @return an encoded byte array in a string
+ */
+ public String convert(byte[] buffer);
+
+ /**
+ * Decode a String into a byte array.
+ *
+ * @param buffer the string to be decoded
+ * @return the decoded byte array
+ * @throws IOException if a problem is encountered with the decoding
+ */
+ public byte[] convert(String buffer) throws IOException;
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Hasher.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Hasher.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Hasher.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Hasher.java Sun Oct 24 02:32:21 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.
+ */
+package org.salty.shiro;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public interface Hasher
+{
+ String hash(String value);
+
+ String hash(String[] values);
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/HexEncoder.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/HexEncoder.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/HexEncoder.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/HexEncoder.java Sun Oct 24 02:32:21 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.salty.shiro;
+
+import java.io.IOException;
+
+import org.salty.shiro.util.HexSupport;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class HexEncoder implements Encoder
+{
+ public String convert(byte[] buffer)
+ {
+ return HexSupport.toHexFromBytes(buffer);
+ }
+
+ public byte[] convert(String buffer) throws IOException
+ {
+ return HexSupport.toBytesFromHex(buffer);
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MessageDigestHasher.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MessageDigestHasher.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MessageDigestHasher.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MessageDigestHasher.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,111 @@
+/**
+ * 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.salty.shiro;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class MessageDigestHasher implements Hasher
+{
+ private final String algorithm;
+ private final Encoder encoder;
+ private String password;
+
+ public MessageDigestHasher(String algorithm, Encoder encoder) throws NoSuchAlgorithmException
+ {
+ this(algorithm, encoder, null);
+ }
+
+ public MessageDigestHasher(String algorithm, Encoder encoder, String password) throws NoSuchAlgorithmException
+ {
+ if (encoder == null) throw new IllegalArgumentException("Encoder cannot be null");
+
+ this.algorithm = algorithm;
+ this.encoder = encoder;
+ this.password = password;
+
+ MessageDigest.getInstance(algorithm);
+ }
+
+ public String getAlgorithm()
+ {
+ return algorithm;
+ }
+
+ public Encoder getEncoder()
+ {
+ return encoder;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public String hash(String value)
+ {
+ return hash(new String[]{value});
+ }
+
+ public String hash(String[] values)
+ {
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance(algorithm);
+ md.reset();
+
+ if (password != null)
+ {
+ try
+ {
+ md.update(password.getBytes("UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ // Should be impossible to get here
+ throw new Error("Could not get bytes from password", uee);
+ }
+ }
+
+ for (String value : values)
+ {
+ try
+ {
+ md.update(value.getBytes("UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ // Should be impossible to get here
+ throw new Error("Could not get bytes from request parameters", uee);
+ }
+ }
+
+ return encoder.convert(md.digest());
+ }
+ catch (NoSuchAlgorithmException impossible)
+ {
+ return null;
+ }
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MockPersonDao.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MockPersonDao.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MockPersonDao.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/MockPersonDao.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,30 @@
+/**
+ * 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.salty.shiro;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class MockPersonDao implements PersonDao
+{
+ public Person findPersonByUsername(String username)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PasswordHasher.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PasswordHasher.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PasswordHasher.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PasswordHasher.java Sun Oct 24 02:32:21 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.salty.shiro;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class PasswordHasher
+{
+ private Hasher hasher;
+
+ public PasswordHasher(Hasher hasher)
+ {
+ if (hasher == null) throw new IllegalArgumentException("Hasher cannot be null");
+ this.hasher = hasher;
+ }
+
+ public String hash(int salt, String password)
+ {
+ String[] hash = new String[2];
+
+ hash[0] = Integer.toHexString(salt);
+ hash[1] = password;
+
+ return hasher.hash(hash);
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Person.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Person.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Person.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/Person.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,58 @@
+/**
+ * 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.salty.shiro;
+
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Person
+{
+ private final Set<String> roles = new HashSet<String>();
+ private int salt;
+ private String password;
+
+ public Set<String> getRoles()
+ {
+ return roles;
+ }
+
+ public int getSalt()
+ {
+ return salt;
+ }
+
+ public void setSalt(int salt)
+ {
+ this.salt = salt;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+}
\ No newline at end of file
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PersonDao.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PersonDao.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PersonDao.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/PersonDao.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.salty.shiro;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public interface PersonDao
+{
+ Person findPersonByUsername(String username);
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyAuthenticationInfo.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyAuthenticationInfo.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyAuthenticationInfo.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyAuthenticationInfo.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,58 @@
+/**
+ * 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.salty.shiro;
+
+import org.apache.shiro.authc.SimpleAuthenticationInfo;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class SaltyAuthenticationInfo extends SimpleAuthenticationInfo
+{
+ private int salt;
+
+ public SaltyAuthenticationInfo()
+ {
+ }
+
+ public SaltyAuthenticationInfo(Object principal, String credentials, String realmName, int salt)
+ {
+ this(new SimplePrincipalCollection(principal, realmName), credentials, salt);
+ }
+
+ public SaltyAuthenticationInfo(PrincipalCollection principals, String credentials, int salt)
+ {
+ super(principals, credentials);
+
+ this.salt = salt;
+ }
+
+ public int getSalt()
+ {
+ return salt;
+ }
+
+ public void setSalt(int salt)
+ {
+ this.salt = salt;
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyCredentialsMatcher.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyCredentialsMatcher.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyCredentialsMatcher.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyCredentialsMatcher.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,50 @@
+/**
+ * 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.salty.shiro;
+
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class SaltyCredentialsMatcher extends SimpleCredentialsMatcher
+{
+ private PasswordHasher passwordHasher;
+
+ public void setPasswordHasher(PasswordHasher passwordHasher)
+ {
+ this.passwordHasher = passwordHasher;
+ }
+
+ @Override
+ public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info)
+ {
+ char[] tokenCredentials = (char[])getCredentials(token);
+
+ SaltyAuthenticationInfo myInfo = (SaltyAuthenticationInfo)info;
+ String hash = passwordHasher.hash(myInfo.getSalt(), new String(tokenCredentials));
+
+ Object accountCredentials = getCredentials(info);
+
+ return equals(hash.toCharArray(), accountCredentials);
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyRealm.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyRealm.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyRealm.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/SaltyRealm.java Sun Oct 24 02:32:21 2010
@@ -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.salty.shiro;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.UnknownAccountException;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.authz.AuthorizationException;
+import org.apache.shiro.authz.AuthorizationInfo;
+import org.apache.shiro.authz.SimpleAuthorizationInfo;
+import org.apache.shiro.realm.AuthorizingRealm;
+import org.apache.shiro.subject.PrincipalCollection;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class SaltyRealm extends AuthorizingRealm
+{
+ private PersonDao personDao;
+ private String realmName;
+
+ public void setPersonDao(PersonDao personDao)
+ {
+ this.personDao = personDao;
+ }
+
+ public void setRealmName(String realmName)
+ {
+ this.realmName = realmName;
+ }
+
+ @Override
+ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
+ {
+ if (principals == null) throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
+
+ String username = (String)getAvailablePrincipal(principals);
+
+ Person person = personDao.findPersonByUsername(username);
+
+ Set<String> roles = new HashSet<String>();
+ for (String role : person.getRoles())
+ {
+ roles.add(role);
+ }
+
+ return new SimpleAuthorizationInfo(roles);
+ }
+
+ @Override
+ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException
+ {
+ UsernamePasswordToken upToken = (UsernamePasswordToken)token;
+ String username = upToken.getUsername();
+ Person person = personDao.findPersonByUsername(username);
+
+ if (person == null)
+ {
+ throw new UnknownAccountException("No user was found with those credentials. Double check your info and try again.");
+ }
+
+ int salt = person.getSalt();
+ String password = person.getPassword();
+
+ return new SaltyAuthenticationInfo(person, password, realmName, salt);
+ }
+}
Added: shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/HexSupport.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/HexSupport.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/HexSupport.java (added)
+++ shiro/sandbox/salty/samples/salty/src/main/java/org/salty/shiro/util/HexSupport.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,84 @@
+/**
+ * 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.salty.shiro.util;
+
+/**
+ * Blatently stolen from Apache ActiveMQ
+ *
+ * @version $Revision: $ $Date: $
+ */
+public final class HexSupport
+{
+ private static final String[] HEX_TABLE = new String[]{
+ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f",
+ "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f",
+ "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f",
+ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f",
+ "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f",
+ "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f",
+ "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f",
+ "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f",
+ "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f",
+ "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f",
+ "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af",
+ "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf",
+ "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf",
+ "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df",
+ "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef",
+ "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff",
+ };
+
+ private HexSupport()
+ {
+ }
+
+ /**
+ * @param hex Hex string
+ * @return Byte array
+ */
+ static public byte[] toBytesFromHex(String hex)
+ {
+ if (hex.length() % 2 == 1) hex = "0" + hex;
+
+ byte rc[] = new byte[hex.length() / 2];
+ for (int i = 0; i < rc.length; i++)
+ {
+ String h = hex.substring(i * 2, i * 2 + 2);
+ int x = Integer.parseInt(h, 16);
+ rc[i] = (byte)x;
+ }
+ return rc;
+ }
+
+ /**
+ * @param bytes
+ * @return Hex String
+ */
+ static public String toHexFromBytes(byte[] bytes)
+ {
+ StringBuffer rc = new StringBuffer(bytes.length * 2);
+ for (int i = 0; i < bytes.length; i++)
+ {
+ rc.append(HEX_TABLE[0xFF & bytes[i]]);
+ }
+ return rc.toString();
+ }
+
+}
+
Added: shiro/sandbox/salty/samples/salty/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/resources/log4j.properties?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/resources/log4j.properties (added)
+++ shiro/sandbox/salty/samples/salty/src/main/resources/log4j.properties Sun Oct 24 02:32:21 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.
+#
+# 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/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/applicationContext.xml?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/applicationContext.xml (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/applicationContext.xml Sun Oct 24 02:32:21 2010
@@ -0,0 +1,89 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="location" value="classpath:salty.properties"/>
+ </bean>
+
+ <bean id="passwordHasher" class="org.salty.shiro.MessageDigestHasher">
+ <constructor-arg value="MD5"/>
+ <constructor-arg ref="hexEncoder"/>
+ <constructor-arg value="${logon-hash-password}"/>
+ </bean>
+
+ <bean id="hexEncoder" class="org.salty.shiro.HexEncoder"/>
+
+ <bean id="passwordGenerator" class="org.salty.shiro.PasswordHasher">
+ <constructor-arg ref="passwordHasher"/>
+ </bean>
+
+ <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
+ <property name="securityManager" ref="securityManager"/>
+ <property name="loginUrl" value="/signin/signIn.jspa?first=true"/>
+ <property name="successUrl" value="/home.jsp"/>
+ <property name="unauthorizedUrl" value="/unauthorized.jsp"/>
+ <property name="filterChainDefinitions">
+ <value>
+ # The IniShiroFilter configuration is very powerful and flexible, while still remaining succinct.
+ # Please read the org.apache.shiro.web.servlet.IniShiroFilter JavaDoc for information.
+
+ # Quick Tip: Instead of having this configuration here in web.xml, you can instead
+ # move all of this to a 'shiro.ini' file at the root of the classpath and remove
+ # the 'config' init-param. Or you can specify the 'configPath' init-param and specify the
+ # path to a resource at any location (url, file or classpath). This may be desired if the
+ # config gets long and you want to keep web.xml clean.
+
+ [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
+
+ [filters]
+ shiro.loginUrl = /login.jsp
+
+ [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
+
+ /account/** = authc
+ /remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"]
+ </value>
+ </property>
+ </bean>
+
+ <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
+ <property name="realm" ref="saltyRealm"/>
+ </bean>
+
+ <bean id="saltyRealm" class="org.salty.shiro.SaltyRealm">
+ <property name="personDao" ref="personDao"/>
+ <property name="realmName" value="myRealm"/>
+ <property name="credentialsMatcher" ref="saltyCredentialsMatcher"/>
+ </bean>
+
+ <bean id="saltyCredentialsMatcher" class="org.salty.shiro.SaltyCredentialsMatcher">
+ <property name="passwordHasher" ref="passwordGenerator"/>
+ </bean>
+
+ <bean id="personDao" class="org.salty.shiro.MockPersonDao"/>
+
+</beans>
Added: shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/web.xml?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/web.xml (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/WEB-INF/web.xml Sun Oct 24 02:32:21 2010
@@ -0,0 +1,81 @@
+<?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">
+
+ <filter>
+ <filter-name>ShiroFilter</filter-name>
+ <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
+ <init-param>
+ <param-name>config</param-name>
+ <param-value>
+
+ # The IniShiroFilter configuration is very powerful and flexible, while still remaining succinct.
+ # Please read the org.apache.shiro.web.servlet.IniShiroFilter JavaDoc for information.
+
+ # Quick Tip: Instead of having this configuration here in web.xml, you can instead
+ # move all of this to a 'shiro.ini' file at the root of the classpath and remove
+ # the 'config' init-param. Or you can specify the 'configPath' init-param and specify the
+ # path to a resource at any location (url, file or classpath). This may be desired if the
+ # config gets long and you want to keep web.xml clean.
+
+ [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
+
+ [filters]
+ shiro.loginUrl = /login.jsp
+
+ [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
+
+ /account/** = authc
+ /remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"]
+
+ </param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>ShiroFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+</web-app>
Added: shiro/sandbox/salty/samples/salty/src/main/webapp/account/index.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/account/index.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/account/index.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/account/index.jsp Sun Oct 24 02:32:21 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.
+ --%>
+<%@ 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.jsp"/>">Log out.</a></p>
+
+</body>
+</html>
\ No newline at end of file
Added: shiro/sandbox/salty/samples/salty/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/home.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/home.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/home.jsp Sun Oct 24 02:32:21 2010
@@ -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.jsp"/>">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/sandbox/salty/samples/salty/src/main/webapp/include.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/include.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/include.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/include.jsp Sun Oct 24 02:32:21 2010
@@ -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/sandbox/salty/samples/salty/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/index.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/index.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/index.jsp Sun Oct 24 02:32:21 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.
+ --%>
+
+<%-- Forward the user to the home page --%>
+<jsp:forward page="home.jsp"/>
\ No newline at end of file
Added: shiro/sandbox/salty/samples/salty/src/main/webapp/login.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/login.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/login.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/login.jsp Sun Oct 24 02:32:21 2010
@@ -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/sandbox/salty/samples/salty/src/main/webapp/logout.jsp
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/logout.jsp?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/logout.jsp (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/logout.jsp Sun Oct 24 02:32:21 2010
@@ -0,0 +1,68 @@
+<%--
+~ 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" %>
+<%
+ /*
+ NOTE: In a web application using 'rememberMe'
+ services via Cookies, always make sure you
+ call subject.login() and subject.logout()
+ _before_ any output is rendered to the
+ corresponding request/response.
+
+ Detailed description:
+
+ When a user logs out, any 'rememberMe' identity
+ should always be cleared. In a web application,
+ Shiro uses a cipher-encrypted Cookie to
+ remember a user's identity by default, and it will
+ automatically delete the Cookie upon a logout.
+
+ But deleting a Cookie is actually performed by
+ overwriting it with a new one with the same name
+ and a 'maxAge' of 0. And because Cookies are
+ sent out in the HTTP Header, the Cookie must be
+ deleted (overwritten) _before_ any HTML output
+ is rendered.
+
+ This means the following logout() call must
+ execute before the page is rendered, so we make
+ that call here at the very beginning of the file.
+
+ In proper MVC applications, the following logout()
+ call _should_ be in a Controller, never a JSP page.
+ But since this is a Quickstart app with minimal
+ libraries (no MVC frameworks), we do it here in
+ the page itself - but we would never do this if
+ writing a 'real' application.
+ */
+
+ SecurityUtils.getSubject().logout();
+%>
+<html>
+<head>
+ <link type="text/css" rel="stylesheet" href="<c:url value="style.css"/>"/>
+</head>
+<body>
+
+<h2>Log out</h2>
+
+<p>You have succesfully logged out. <a href="<c:url value="/home.jsp"/>">Return to the home page.</a></p>
+
+</body>
+</html>
Added: shiro/sandbox/salty/samples/salty/src/main/webapp/style.css
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/main/webapp/style.css?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/main/webapp/style.css (added)
+++ shiro/sandbox/salty/samples/salty/src/main/webapp/style.css Sun Oct 24 02:32:21 2010
@@ -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/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/AbstractContainerTest.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/AbstractContainerTest.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/AbstractContainerTest.java (added)
+++ shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/AbstractContainerTest.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.test;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import static org.junit.Assert.assertTrue;
+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;
+
+public abstract class AbstractContainerTest {
+ protected static PauseableServer server;
+
+ protected static final int port = 9180;
+
+ protected static final String BASEURI = "http://localhost:" + port + "/";
+
+ protected final WebClient webClient = new WebClient();
+
+ @BeforeClass
+ public static void startContainer() throws Exception {
+ if (server == null) {
+ server = new PauseableServer();
+ Connector connector = new SelectChannelConnector();
+ connector.setPort(port);
+ server.setConnectors(new Connector[]{connector});
+ server.setHandler(new WebAppContext("src/main/webapp", "/"));
+ server.start();
+ assertTrue(server.isStarted());
+ }
+ }
+
+ @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/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java (added)
+++ shiro/sandbox/salty/samples/salty/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java Sun Oct 24 02:32:21 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.test;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+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;
+
+public class ContainerIntegrationTest extends AbstractContainerTest {
+
+ @Before
+ public void logOut() throws IOException {
+ // Make sure we are logged out
+ final HtmlPage homePage = webClient.getPage(BASEURI);
+ try {
+ homePage.getAnchorByHref("/logout.jsp").click();
+ }
+ catch (ElementNotFoundException e) {
+ //Ignore
+ }
+ }
+
+ @Test
+ public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
+
+ HtmlPage page = webClient.getPage(BASEURI + "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.jsp");
+ }
+
+ @Test
+ public void logInAndRememberMe() throws Exception {
+ HtmlPage page = webClient.getPage(BASEURI + "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(BASEURI);
+ // page.getAnchorByHref("/logout.jsp");
+ 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");
+ }
+
+}
Added: shiro/sandbox/salty/samples/salty/src/test/resources/salty.properties
URL: http://svn.apache.org/viewvc/shiro/sandbox/salty/samples/salty/src/test/resources/salty.properties?rev=1026733&view=auto
==============================================================================
--- shiro/sandbox/salty/samples/salty/src/test/resources/salty.properties (added)
+++ shiro/sandbox/salty/samples/salty/src/test/resources/salty.properties Sun Oct 24 02:32:21 2010
@@ -0,0 +1 @@
+logon-hash-password=saltypa$$w0rd