Skip to content

Commit

Permalink
Merge pull request #2675 from IBM/lee-main-2
Browse files Browse the repository at this point in the history
Add support for user/ scopes
  • Loading branch information
lmsurpre committed Aug 11, 2021
2 parents 28d2b7b + 5b5f012 commit d0545fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ private boolean isAllowed(Resource resource, Set<String> contextIds, Permission
// Then group the scopes by their context type
.collect(Collectors.groupingBy(s -> s.getContextType()));

if (approvedScopeMap.containsKey(ContextType.USER)) {
// For `user` scopes, we grant access to all resources of the requested type.
// Implementers that use these scopes are encouraged to layer on their own permissions model beyond this.
if (log.isLoggable(Level.FINE)) {
log.fine(requiredPermission.value() + " permission for '" + resourceType + "/" + resource.getId() +
"' is granted via scope " + approvedScopeMap.get(ContextType.USER));
}
return true;
}

if (approvedScopeMap.containsKey(ContextType.PATIENT)) {
if (resource instanceof Provenance) {
// Addressed for issue #1881, Provenance is a special-case: a Patient-compartment resource type that
Expand Down Expand Up @@ -476,10 +486,6 @@ private boolean isAllowed(Resource resource, Set<String> contextIds, Permission
return isInCompartment(resource, CompartmentType.PATIENT, contextIds);
}

if (approvedScopeMap.containsKey(ContextType.USER)) {
throw new UnsupportedOperationException("SMART scopes with context type 'user' are not yet supported.");
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ public static Object[][] scopeStrings() {
final Set<ResourceType.Value> provenance = Collections.singleton(PROVENANCE);

return new Object[][] {
//String scopeString, Set<ResourceType.Value> resourceTypesPermittedByScope, Permission permission
{"patient/*.*", all_resources, Permission.ALL},
{"patient/*.read", all_resources, Permission.READ},
{"patient/*.write", all_resources, Permission.WRITE},
Expand All @@ -798,6 +799,10 @@ public static Object[][] scopeStrings() {

{"patient/Patient.read patient/Observation.read", union(patient, observation), Permission.READ},

{"user/*.*", all_resources, Permission.ALL},
{"user/Patient.read", patient, Permission.READ},
{"user/Observation.write", observation, Permission.WRITE},

{"openid profile", Collections.EMPTY_SET, null},
};
}
Expand Down

0 comments on commit d0545fb

Please sign in to comment.