To enable Shiro in your Wicket application, you must do three things: add the necessary JAR dependencies to your project, set up your {@code web.xml}, and configure your Wicket application instance.
First, add the necessary Shiro JARs to your project. The easiest way, using Maven, is to declare the following dependency. This will automatically pull in the shiro-core and shiro-web JARs:
<dependency> <groupId>com.55minutes</groupId> <artifactId>fiftyfive-wicket-shiro</artifactId> <version>4.0-SNAPSHOT</version> </dependency>
You'll also need this repository:
<repository> <id>fiftyfive-opensource-snapshots</id> <name>55 Minutes Open Source Maven Snapshots Repository</name> <url>http://opensource.55minutes.com/maven-snapshots</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>false</enabled></releases> </repository> <repository> <id>fiftyfive-opensource-releases</id> <name>55 Minutes Open Source Maven Releases Repository</name> <url>http://opensource.55minutes.com/maven-releases</url> <snapshots><enabled>false</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository>
Next, add the Shiro filter to your {@code web.xml}. This is the core of Shiro's configuration; it is not Wicket-specific. The JDBC, LDAP or other backend for loading the underlying authentication and authorization data is configured here (a Spring-based configuration is also possible). In this example we will configure an extremely simple plaintext list of accounts and passwords. See the Shiro configuration reference for more examples.
Note that the Shiro filter must appear before the Wicket filter.
<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> [users] # Format is: username = password, roleName1, roleName2, ..., roleNameN admin = secret, admin testaccount = test </param-value></init-param> </filter> <filter-mapping> <filter-name>ShiroFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Finally, connect Shiro to your Wicket application using the instructions in {@link fiftyfive.wicket.shiro.ShiroWicketPlugin ShiroWicketPlugin}.