Skip to content

Commit a4494f9

Browse files
authored
Merge pull request #27 from coldbox-modules/hasPermission-GP
Simplifying the hasPermission interface by always handling the array …
2 parents 3c4bd4c + 168d0c1 commit a4494f9

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ test-harness/logs/**
1111
test-harness/modules/**
1212

1313
# log files
14-
logs/**
14+
logs/**
15+
16+
modules/**

interceptors/Security.cfc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,9 @@ component accessors="true" extends="coldbox.system.Interceptor" {
556556
* @return { allow:boolean, type:string(authentication|authorization)}
557557
*/
558558
private struct function verifySecuredAnnotation( required securedValue, required event ){
559-
// If no value, then default it to true
560-
if ( !len( arguments.securedValue ) ) {
561-
arguments.securedValue = true;
562-
}
563559

564560
// Are we securing?
565-
if ( isBoolean( arguments.securedValue ) && !arguments.securedValue ) {
561+
if ( len( arguments.securedValue ) && isBoolean( arguments.securedValue ) && !arguments.securedValue ) {
566562
return {
567563
"allow" : true,
568564
"type" : "authentication"

interfaces/IAuthUser.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ interface{
1212
function getId();
1313

1414
/**
15-
* Verify if the user has one or more of the passed in permissions
15+
* Verify if the user has the permission passed in
1616
*
17-
* @permission One or a list of permissions to check for access
17+
* @permission A single permission to check for access
1818
*
1919
*/
2020
boolean function hasPermission( required permission );

interfaces/ISecurityValidator.cfc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ interface{
1010
* This function is called once an incoming event matches a security rule.
1111
* You will receive the security rule that matched and an instance of the ColdBox controller.
1212
*
13-
* You must return a struct with two keys:
13+
* You must return a struct with three keys:
1414
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
1515
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
16+
* - messages:string Info/debug messages
1617
*
1718
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
1819
*/
@@ -22,9 +23,10 @@ interface{
2223
* This function is called once access to a handler/action is detected.
2324
* You will receive the secured annotation value and an instance of the ColdBox Controller
2425
*
25-
* You must return a struct with two keys:
26+
* You must return a struct with three keys:
2627
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
2728
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
29+
* - messages:string Info/debug messages
2830
*
2931
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
3032
*/

models/jwt/JwtService.cfc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,7 @@ component accessors="true" singleton {
759759
results.allow = (
760760
tokenHasScopes( arguments.permissions, payload.scope )
761761
||
762-
variables.cbSecurity
763-
.getAuthService()
764-
.getUser()
765-
.hasPermission( arguments.permissions )
762+
variables.cbSecurity.has( arguments.permissions )
766763
);
767764
results.type = "authorization";
768765
} else {

models/validators/CBAuthValidator.cfc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ component singleton {
1515
* You will receive the security rule that matched and an instance of the
1616
* ColdBox controller.
1717
*
18-
* You must return a struct with two keys:
18+
* You must return a struct with three keys:
1919
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
2020
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
2121
* - messages:string Info/debug messages
2222
*
23-
* @return { allow:boolean, type:authentication|authorization, messages:string }
23+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
2424
*/
2525
struct function ruleValidator( required rule, required controller ){
2626
return validateSecurity( arguments.rule.permissions );
@@ -30,12 +30,12 @@ component singleton {
3030
* This function is called once access to a handler/action is detected.
3131
* You will receive the secured annotation value and an instance of the ColdBox Controller
3232
*
33-
* You must return a struct with two keys:
33+
* You must return a struct with three keys:
3434
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
3535
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
3636
* - messages:string Info/debug messages
3737
*
38-
* @return { allow:boolean, type:authentication|authorization, messages:string }
38+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
3939
*/
4040
struct function annotationValidator( required securedValue, required controller ){
4141
return validateSecurity( arguments.securedValue );
@@ -57,7 +57,7 @@ component singleton {
5757
if ( variables.cbSecurity.getAuthService().isLoggedIn() ) {
5858
// Do we have any permissions?
5959
if ( listLen( arguments.permissions ) ) {
60-
results.allow = variables.cbSecurity.getAuthService().getUser().hasPermission( arguments.permissions );
60+
results.allow = variables.cbSecurity.has( arguments.permissions );
6161
results.type = "authorization";
6262
} else {
6363
// We are satisfied!

models/validators/CFValidator.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ component singleton {
1212
* You will receive the security rule that matched and an instance of the
1313
* ColdBox controller.
1414
*
15-
* You must return a struct with two keys:
15+
* You must return a struct with three keys:
1616
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
1717
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
1818
* - messages:string Info/debug messages
1919
*
20-
* @return { allow:boolean, type:authentication|authorization, messages:string }
20+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
2121
*/
2222
struct function ruleValidator( required rule, required controller ){
2323
return validateSecurity( arguments.rule.roles );
@@ -27,12 +27,12 @@ component singleton {
2727
* This function is called once access to a handler/action is detected.
2828
* You will receive the secured annotation value and an instance of the ColdBox Controller
2929
*
30-
* You must return a struct with two keys:
30+
* You must return a struct with three keys:
3131
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
3232
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
3333
* - messages:string Info/debug messages
3434
*
35-
* @return { allow:boolean, type:authentication|authorization, messages:string }
35+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
3636
*/
3737
struct function annotationValidator( required securedValue, required controller ){
3838
return validateSecurity( arguments.securedValue );

0 commit comments

Comments
 (0)