Skip to content
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
2 changes: 1 addition & 1 deletion nae.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
},
"access": {
"authority": [
"ADMIN"
"ROLE_ADMIN"
]
},
"navigation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import {UserResource} from '../../resources/interface/user-resource';
import {AnonymousService} from '../../authentication/anonymous/anonymous.service';

export var SCOPE_SUFFIX = "*";

Check failure on line 17 in projects/netgrif-components-core/src/lib/user/services/user.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Exporting mutable 'var' binding, use 'const' instead.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AaDDqcnSyr8NlECzooR3&open=AaDDqcnSyr8NlECzooR3&pullRequest=169

Check failure on line 17 in projects/netgrif-components-core/src/lib/user/services/user.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AaDDqcnSyr8NlECzooR4&open=AaDDqcnSyr8NlECzooR4&pullRequest=169

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -102,9 +103,19 @@
return false;
}
if (authority instanceof Array) {
return authority.some(a => user.authorities.some(u => u === a));
return authority.some(a => user.authorities.some(u => u === a || this.hasAuthorityFromScope(a, u)));
} else {
return user.authorities.some(a => a === authority);
return user.authorities.some(a => a === authority || this.hasAuthorityFromScope(authority, a));
}
}

public hasAuthorityFromScope(authorityScope: string, authorityToCheck: string): boolean {
if (authorityScope.includes(SCOPE_SUFFIX) && authorityScope.indexOf(SCOPE_SUFFIX) != authorityScope.length - 1) {
this._log.error('The authority name or scope is not valid.')
return false;
}
else {
return authorityToCheck.startsWith(authorityScope.replace(SCOPE_SUFFIX, ''));
}
}

Expand Down
Loading