문제

I'm browsing around the web to find some kind of tutorial but I'm having trouble finding it. I guess I could just use the twitter example provided with securesocial

example:

def onlyAdmin = SecuredAction(WithAuth("admin")) { implicit request =>
      Ok("You could see this since you are admin")
}

case class WithAuth(role: String) extends Authorization {
  def isAuthorized(user: Identity) = {
val existingDbUser = User.findUserByProviderUserId(user)
    existingDbUser.hasRole(role)
}

User.findUserByProviderUserId(user) calls the db to find the stored user and it's roles. I would prefer not to call the db every time and make use of the Identity.

How would you solve this?

도움이 되었습니까?

해결책

That would be the right approach. You could, from the UserService.save() method return an instance of your own model (as long as it implements Identity). That would allow you to return your User object and then run user.hasRole(role) directly without querying the database again. But the query, needs to be done at some point.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top