Skip to content
Browse files

Added a locparam applied snippet to supply the login snippet without …

…boiler plate and also added a boxed assessor for obtaining the principal subject
  • Loading branch information...
1 parent 386eed0 commit e753133111b91a2b1cd3e66fb2ffa2aa10672c99 @timperrett committed
View
2 example/src/main/scala/bootstrap/liftweb/Boot.scala
@@ -14,7 +14,7 @@ class Boot {
LiftRules.setSiteMap(SiteMap(List(
Menu("Home") / "index" >> RequireAuthentication,
Menu("Role Test") / "restricted" >> RequireAuthentication >> HasRole("admin"),
- Menu("Login") / "login" >> RequireNoAuthentication
+ Menu("Login") / "login" >> DefaultLogin >> RequireNoAuthentication
) ::: Shiro.menus: _*
))
}
View
9 example/src/main/scala/eu/getintheloop/snippet/login.scala
@@ -1,9 +0,0 @@
-package eu.getintheloop.snippet
-
-import shiro.snippet.DefaultUsernamePasswordLogin
-
-class Login extends DefaultUsernamePasswordLogin {
- def dispatch = {
- case _ => render
- }
-}
View
10 library/src/main/scala/shiro/sitemap/locs.scala
@@ -11,7 +11,7 @@ object Locs {
import net.liftweb.common.{Full,Box}
import net.liftweb.http.{RedirectResponse, RedirectWithState, S, RedirectState}
import net.liftweb.sitemap.{Menu,Loc}
- import net.liftweb.sitemap.Loc.{If,EarlyResponse,Unless,Hidden,Link}
+ import net.liftweb.sitemap.Loc.{If,EarlyResponse,Unless,Hidden,Link,DispatchLocSnippets}
import shiro.Utils._
// import org.apache.shiro.SecurityUtils
@@ -46,6 +46,14 @@ object Locs {
Full(RedirectResponse(Shiro.indexURL.vend))
}) :: Nil
+ object DefaultLogin
+ extends DispatchLocSnippets
+ with shiro.snippet.DefaultUsernamePasswordLogin {
+ def dispatch = {
+ case "login" => render
+ }
+ }
+
def HasRole(role: String) =
If(() => hasRole(role),
DisplayError("You are the wrong role to access that resource."))
View
4 library/src/main/scala/shiro/utils.scala
@@ -4,12 +4,16 @@ object Utils extends Utils
private[shiro] trait Utils {
import org.apache.shiro.SecurityUtils
import org.apache.shiro.subject.Subject
+ import net.liftweb.common.Box
implicit def subject = SecurityUtils.getSubject
private def test(f: Subject => Boolean)(implicit subject: Subject): Boolean =
f(subject)
+ def principal[T]: Box[T] =
+ Box !! subject.getPrincipal.asInstanceOf[T]
+
def isAuthenticated =
test { _.isAuthenticated }

0 comments on commit e753133

Please sign in to comment.
Something went wrong with that request. Please try again.