Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Rename enum parameter name #400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ trait BLPAuthorization[F[_], A, Auth] extends Authorization[F, A, Auth]
*/
sealed abstract case class BLPReadAction[F[_], Role, A, Auth](authLevel: Role)(
implicit authInfo: AuthorizationInfo[F, Role, A],
enum: SimpleAuthEnum[Role, Int],
authEnum: SimpleAuthEnum[Role, Int],
F: MonadError[F, Throwable]
) extends BLPAuthorization[F, A, Auth] {
def isAuthorized(
toAuth: authentication.SecuredRequest[F, A, Auth]
): OptionT[F, authentication.SecuredRequest[F, A, Auth]] = {
val out = authInfo.fetchInfo(toAuth.identity).map { info =>
val userAuthLevel = enum.getRepr(info)
if (enum.contains(info) && userAuthLevel <= enum.getRepr(authLevel))
val userAuthLevel = authEnum.getRepr(info)
if (authEnum.contains(info) && userAuthLevel <= authEnum.getRepr(authLevel))
Some(toAuth)
else
None
Expand All @@ -40,10 +40,10 @@ sealed abstract case class BLPReadAction[F[_], Role, A, Auth](authLevel: Role)(
object BLPReadAction {
def apply[F[_], Role, A, Auth](authLevel: Role)(
implicit authInfo: AuthorizationInfo[F, Role, A],
enum: SimpleAuthEnum[Role, Int],
authEnum: SimpleAuthEnum[Role, Int],
F: MonadError[F, Throwable]
): F[BLPReadAction[F, Role, A, Auth]] =
if (enum.getRepr(authLevel) < 0)
if (authEnum.getRepr(authLevel) < 0)
F.raiseError(InvalidAuthLevelError)
else
F.pure(new BLPReadAction[F, Role, A, Auth](authLevel) {})
Expand All @@ -55,15 +55,15 @@ object BLPReadAction {
*/
sealed abstract case class BLPWriteAction[F[_], Role, A, Auth](authLevel: Role)(
implicit authInfo: AuthorizationInfo[F, Role, A],
enum: SimpleAuthEnum[Role, Int],
authEnum: SimpleAuthEnum[Role, Int],
F: MonadError[F, Throwable]
) extends BLPAuthorization[F, A, Auth] {
def isAuthorized(
toAuth: authentication.SecuredRequest[F, A, Auth]
): OptionT[F, authentication.SecuredRequest[F, A, Auth]] = {
val out = authInfo.fetchInfo(toAuth.identity).map { info =>
val userAuthLevel = enum.getRepr(info)
if (enum.contains(info) && userAuthLevel == enum.getRepr(authLevel))
val userAuthLevel = authEnum.getRepr(info)
if (authEnum.contains(info) && userAuthLevel == authEnum.getRepr(authLevel))
Some(toAuth)
else
None
Expand All @@ -75,10 +75,10 @@ sealed abstract case class BLPWriteAction[F[_], Role, A, Auth](authLevel: Role)(
object BLPWriteAction {
def apply[F[_], Role, A, Auth](authLevel: Role)(
implicit authInfo: AuthorizationInfo[F, Role, A],
enum: SimpleAuthEnum[Role, Int],
authEnum: SimpleAuthEnum[Role, Int],
F: MonadError[F, Throwable]
): F[BLPWriteAction[F, Role, A, Auth]] =
if (enum.getRepr(authLevel) < 0)
if (authEnum.getRepr(authLevel) < 0)
F.raiseError(InvalidAuthLevelError)
else
F.pure(new BLPWriteAction[F, Role, A, Auth](authLevel) {})
Expand Down
12 changes: 6 additions & 6 deletions tsec-http4s/src/main/scala/tsec/authorization/BasicRBAC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.reflect.ClassTag

sealed abstract case class BasicRBAC[F[_], R, U, Auth](authorized: AuthGroup[R])(
implicit role: AuthorizationInfo[F, R, U],
enum: SimpleAuthEnum[R, String],
authEnum: SimpleAuthEnum[R, String],
F: MonadError[F, Throwable]
) extends Authorization[F, U, Auth] {

Expand All @@ -18,7 +18,7 @@ sealed abstract case class BasicRBAC[F[_], R, U, Auth](authorized: AuthGroup[R])
): OptionT[F, authentication.SecuredRequest[F, U, Auth]] =
OptionT {
role.fetchInfo(toAuth.identity).map { extractedRole =>
if (enum.contains(extractedRole) && authorized.contains(extractedRole))
if (authEnum.contains(extractedRole) && authorized.contains(extractedRole))
Some(toAuth)
else
None
Expand All @@ -28,22 +28,22 @@ sealed abstract case class BasicRBAC[F[_], R, U, Auth](authorized: AuthGroup[R])

object BasicRBAC {
def apply[F[_], R: ClassTag, U, Auth](roles: R*)(
implicit enum: SimpleAuthEnum[R, String],
implicit authEnum: SimpleAuthEnum[R, String],
role: AuthorizationInfo[F, R, U],
F: MonadError[F, Throwable]
): BasicRBAC[F, R, U, Auth] =
fromGroup[F, R, U, Auth](AuthGroup(roles: _*))

def fromGroup[F[_], R: ClassTag, U, Auth](valueSet: AuthGroup[R])(
implicit role: AuthorizationInfo[F, R, U],
enum: SimpleAuthEnum[R, String],
authEnum: SimpleAuthEnum[R, String],
F: MonadError[F, Throwable]
): BasicRBAC[F, R, U, Auth] = new BasicRBAC[F, R, U, Auth](valueSet) {}

def all[F[_], R: ClassTag, U, Auth](
implicit enum: SimpleAuthEnum[R, String],
implicit authEnum: SimpleAuthEnum[R, String],
role: AuthorizationInfo[F, R, U],
F: MonadError[F, Throwable]
): BasicRBAC[F, R, U, Auth] =
new BasicRBAC[F, R, U, Auth](enum.viewAll) {}
new BasicRBAC[F, R, U, Auth](authEnum.viewAll) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import tsec.authentication

case class DynamicRBAC[F[_], Role, U, Auth](dynamic: DynamicAuthGroup[F, Role])(
implicit authInfo: AuthorizationInfo[F, Role, U],
enum: SimpleAuthEnum[Role, String],
authEnum: SimpleAuthEnum[Role, String],
F: MonadError[F, Throwable]
) extends Authorization[F, U, Auth] {
def isAuthorized(
Expand All @@ -17,7 +17,7 @@ case class DynamicRBAC[F[_], Role, U, Auth](dynamic: DynamicAuthGroup[F, Role])(
info <- authInfo.fetchInfo(toAuth.identity)
group <- dynamic.fetchGroupInfo
} yield {
if (enum.contains(info) && group.contains(info))
if (authEnum.contains(info) && group.contains(info))
Some(toAuth)
else
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import tsec.authentication

sealed abstract case class HierarchyAuth[F[_], R, U, Auth](authLevel: R)(
implicit role: AuthorizationInfo[F, R, U],
enum: SimpleAuthEnum[R, Int],
authEnum: SimpleAuthEnum[R, Int],
F: MonadError[F, Throwable]
) extends Authorization[F, U, Auth] {

Expand All @@ -16,8 +16,8 @@ sealed abstract case class HierarchyAuth[F[_], R, U, Auth](authLevel: R)(
): OptionT[F, authentication.SecuredRequest[F, U, Auth]] =
OptionT {
role.fetchInfo(toAuth.identity).map { authRole =>
val intRepr = enum.getRepr(authRole)
if (0 <= intRepr && intRepr <= enum.getRepr(authLevel) && enum.contains(authRole))
val intRepr = authEnum.getRepr(authRole)
if (0 <= intRepr && intRepr <= authEnum.getRepr(authLevel) && authEnum.contains(authRole))
Some(toAuth)
else
None
Expand Down