Permalink
Browse files

Refactored build and added an example app

  • Loading branch information...
1 parent 3cb1225 commit 876c5864b16157fcb2c026a9e49940662dd91068 @timperrett committed Aug 17, 2011
View
@@ -7,7 +7,7 @@ h2. Usage
First, add the SBT dependency:
<code>
- libraryDependencies += "eu.getintheloop" %% "lift-shiro" % "0.0.1"
+ libraryDependencies += "eu.getintheloop" %% "lift-shiro" % "0.0.2-SNAPSHOT"
</code>
Next, you need to add this to the web.xml within your project in order to initialise the Shiro context when your application receives a request:
@@ -29,7 +29,8 @@ Next, you need to add some configuration to your Boot.scala like so:
<pre><code>class Boot {
def boot {
- import shiro._, Locs._
+ import shiro.Shiro
+ import shiro.sitemap.Locs._
Shiro.init()
...
}
View
@@ -1,4 +1,5 @@
h2. TODO:
* Expodite hardcoded strings into a resource bundle
-* REST guards so you can protect resources that are not "pages"
+* REST guards so you can protect resources that are not "pages"
+
View
@@ -19,3 +19,11 @@ libraryDependencies ++= Seq(
)
resolvers += Resolver.file(".m2", file(Path.userHome+"/.m2/repository"))
+
+publishTo <<= version { (v: String) =>
+ val nexus = "http://nexus.scala-tools.org/content/repositories/"
+ if(v endsWith "-SNAPSHOT") Some("Scala Tools Nexus" at nexus + "snapshots/")
+ else Some("Scala Tools Nexus" at nexus + "releases/")
+}
+
+credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
@@ -0,0 +1,40 @@
+# =============================================================================
+# Quickstart INI Realm configuration
+#
+# For those that might not understand the references in this file, the
+# definitions are all based on the classic Mel Brooks' film "Spaceballs". ;)
+# =============================================================================
+
+# -----------------------------------------------------------------------------
+# Users and their assigned roles
+#
+# Each line conforms to the format defined in the
+# org.apache.shiro.realm.text.TextConfigurationRealm#setUserDefinitions JavaDoc
+# -----------------------------------------------------------------------------
+[users]
+# user 'root' with password 'secret' and the 'admin' role
+root = secret, admin
+# user 'guest' with the password 'guest' and the 'guest' role
+guest = guest, guest
+# user 'presidentskroob' with password '12345' ("That's the same combination on
+# my luggage!!!" ;)), and role 'president'
+presidentskroob = 12345, president
+# user 'darkhelmet' with password 'ludicrousspeed' and roles 'darklord' and 'schwartz'
+darkhelmet = ludicrousspeed, darklord, schwartz
+# user 'lonestarr' with password 'vespa' and roles 'goodguy' and 'schwartz'
+lonestarr = vespa, goodguy, schwartz
+
+# -----------------------------------------------------------------------------
+# Roles with assigned permissions
+#
+# Each line conforms to the format defined in the
+# org.apache.shiro.realm.text.TextConfigurationRealm#setRoleDefinitions JavaDoc
+# -----------------------------------------------------------------------------
+[roles]
+# 'admin' role has all permissions, indicated by the wildcard '*'
+admin = *
+# The 'schwartz' role can do anything (*) with any lightsaber:
+schwartz = lightsaber:*
+# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with
+# license plate 'eagle5' (instance specific id)
+goodguy = winnebago:drive:eagle5
@@ -0,0 +1,21 @@
+package bootstrap.liftweb
+
+import net.liftweb.http.LiftRules
+import net.liftweb.sitemap._
+import shiro.Shiro
+import shiro.sitemap.Locs._
+
+class Boot {
+ def boot {
+ Shiro.init()
+
+ LiftRules.addToPackages("eu.getintheloop")
+
+ LiftRules.setSiteMap(SiteMap(List(
+ Menu("Home") / "index" >> RequireAuthentication,
+ Menu("Role Test") / "restricted" >> RequireAuthentication >> HasRole("admin"),
+ Menu("Login") / "login" >> RequireNoAuthentication
+ ) ::: Shiro.menus: _*
+ ))
+ }
+}
@@ -0,0 +1,9 @@
+package eu.getintheloop.snippet
+
+import shiro.snippet.DefaultUsernamePasswordLogin
+
+class Login extends DefaultUsernamePasswordLogin {
+ def dispatch = {
+ case _ => render
+ }
+}
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="2.5"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <listener>
+ <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
+ </listener>
+ <filter>
+ <filter-name>ShiroFilter</filter-name>
+ <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ShiroFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <filter>
+ <filter-name>LiftFilter</filter-name>
+ <display-name>Lift Filter</display-name>
+ <description>The Filter that intercepts lift calls</description>
+ <filter-class>net.liftweb.http.LiftFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>LiftFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+</web-app>
@@ -0,0 +1,8 @@
+<lift:surround with="default" at="content">
+ <h2>Home</h2>
+
+ <lift:has_role name="admin">
+ <p>This content is only available for admins</p>
+ </lift:has_role>
+
+</lift:surround>
@@ -0,0 +1,10 @@
+<lift:surround with="default" at="content">
+ <h2>Login</h2>
+
+ <form lift="login?form=post">
+ <p>Username: <br /><input type="text" /></p>
+ <p>Password: <br /><input type="password" /></p>
+ <p><input type="submit" value="login" /></p>
+ </form>
+
+</lift:surround>
@@ -0,0 +1,3 @@
+<lift:surround with="default" at="content">
+ <h2>Restricted to admin</h2>
+</lift:surround>
@@ -0,0 +1,14 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>Lift Shiro</title>
+ <script id="jquery" src="/classpath/jquery.js" type="text/javascript" />
+ </head>
+ <body>
+ <lift:menu.builder />
+ <hr />
+ <lift:bind name="content" />
+ <hr />
+ <lift:msgs showAll="true" />
+ </body>
+</html>
View
@@ -0,0 +1,42 @@
+import sbt._, Keys._
+
+object BuildSettings {
+ val buildOrganization = "eu.getintheloop"
+ val buildVersion = "0.0.2-SNAPSHOT"
+ val buildScalaVersion = "2.9.0-1"
+
+ val buildSettings = Defaults.defaultSettings ++ Seq (
+ organization := buildOrganization,
+ version := buildVersion,
+ scalaVersion := buildScalaVersion,
+ scalacOptions += "-deprecation",
+ crossScalaVersions := Seq("2.8.1", "2.9.0", "2.9.0-1"),
+ resolvers += Resolver.file(".m2", file(Path.userHome+"/.m2/repository"))
+ )
+}
+
+object SudsBuild extends Build {
+ lazy val root = Project("root", file("."),
+ settings = BuildSettings.buildSettings
+ ) aggregate(library, example)
+
+ lazy val library: Project = Project("lift-shiro", file("library"),
+ settings = BuildSettings.buildSettings ++ (
+ libraryDependencies ++= Seq(
+ "net.liftweb" %% "lift-webkit" % "2.4-M2",
+ "org.apache.shiro" % "shiro-core" % "1.2.0-SNAPSHOT",
+ "org.apache.shiro" % "shiro-web" % "1.2.0-SNAPSHOT",
+ "commons-beanutils" % "commons-beanutils" % "20030211.134440"
+ )
+ )
+ )
+
+ lazy val example = Project("lift-shiro-example", file("example"),
+ settings = BuildSettings.buildSettings ++ (
+ libraryDependencies ++= Seq(
+ "org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "jetty",
+ "ch.qos.logback" % "logback-classic" % "0.9.26"
+ )
+ )
+ ) settings(com.github.siasia.WebPlugin.webSettings :_*) dependsOn(library)
+}
@@ -0,0 +1,4 @@
+resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
+
+libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % ("0.1.1-"+v))
+
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 876c586

Please sign in to comment.