Skip to content

Commit

Permalink
JwtPermissionHandler should return true if no permissions are required (
Browse files Browse the repository at this point in the history
  • Loading branch information
mduesterhoeft authored Jul 25, 2019
1 parent 16720d7 commit 229543d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion router/src/main/kotlin/io/moia/router/PermissionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ open class JwtPermissionHandler(
) : this(JwtAccessor(request), permissionsClaim, permissionSeparator)

override fun hasAnyRequiredPermission(requiredPermissions: Set<String>): Boolean =
extractPermissions().any { requiredPermissions.contains(it) }
if (requiredPermissions.isEmpty()) true
else extractPermissions().any { requiredPermissions.contains(it) }

internal open fun extractPermissions(): Set<String> =
accessor.extractJwtClaims()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class JwtPermissionHandlerTest {
thenRecognizesRequiredPermissions(handler)
}

@Test
fun `should return true when no permissions are required`() {
val handler = permissionHandler(jwtWithScopeClaimSpace)

val result = handler.hasAnyRequiredPermission(emptySet())

then(result).isTrue()
}

@Test
fun `should work for missing header`() {
val handler = JwtPermissionHandler(JwtAccessor(APIGatewayProxyRequestEvent()))
Expand Down

0 comments on commit 229543d

Please sign in to comment.