-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from Viva-con-Agua/develop
- Loading branch information
Showing
15 changed files
with
173 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils.authorization | ||
|
||
import com.mohiva.play.silhouette.api.Authorization | ||
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator | ||
import models.User | ||
import play.api.i18n.Messages | ||
import play.api.mvc.Request | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
import scala.concurrent.Future | ||
|
||
case class AuthAndCombination(one: CombinableRestriction, two: CombinableRestriction) extends Authorization[User,CookieAuthenticator] { | ||
override def isAuthorized[B](identity: User, authenticator: CookieAuthenticator)(implicit request: Request[B], messages: Messages): Future[Boolean] = | ||
one.isAuthorized(identity, authenticator).flatMap( | ||
(first) => two.isAuthorized(identity, authenticator).map( | ||
(second) => first && second | ||
) | ||
) | ||
} | ||
|
||
|
||
case class AuthOrCombination(one: CombinableRestriction, two: CombinableRestriction) extends Authorization[User,CookieAuthenticator] { | ||
override def isAuthorized[B](identity: User, authenticator: CookieAuthenticator)(implicit request: Request[B], messages: Messages): Future[Boolean] = | ||
one.isAuthorized(identity, authenticator).flatMap( | ||
(first) => two.isAuthorized(identity, authenticator).map( | ||
(second) => first || second | ||
) | ||
) | ||
} | ||
|
||
trait CombinableRestriction extends Authorization[User,CookieAuthenticator] { | ||
def isAuthorized[B](identity: User, authenticator: CookieAuthenticator)(implicit request: Request[B], messages: Messages): Future[Boolean] | ||
|
||
def &&(other: CombinableRestriction) : Authorization[User,CookieAuthenticator] = { | ||
AuthAndCombination(this, other) | ||
} | ||
|
||
def ||(other: CombinableRestriction) : Authorization[User,CookieAuthenticator] = { | ||
AuthOrCombination(this, other) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package utils.authorization | ||
|
||
import com.mohiva.play.silhouette.api.Authorization | ||
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator | ||
import models.{Role, RoleAdmin, User} | ||
import play.api.i18n.Messages | ||
import play.api.mvc.Request | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* Gets a parameter indicating if an active connection to Pool 1 exists. If the parameter is true (connection exists): | ||
* Only admins have permissions to access the requested resource; all other users are rejected. If it's false, there is | ||
* no need to consider this restriction. | ||
* | ||
* @author Johann Sell | ||
* @param active indicates if a connection does exists | ||
*/ | ||
case class Pool1Restriction(active: Boolean) extends Authorization[User,CookieAuthenticator] with CombinableRestriction { | ||
def isAuthorized[B](user: User, authenticator: CookieAuthenticator)(implicit request : Request[B], messages: Messages) = | ||
user.roles match { | ||
case list: Set[Role] => Future.successful(list.contains(RoleAdmin) || !active) | ||
case _ => Future.successful(!active) | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
app/utils/WithRole.scala → app/utils/authorization/WithRole.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.