Skip to content

Commit d0545fb

Browse files
authored
Merge pull request #2675 from IBM/lee-main-2
Add support for user/ scopes
2 parents 28d2b7b + 5b5f012 commit d0545fb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

fhir-smart/src/main/java/com/ibm/fhir/smart/AuthzPolicyEnforcementPersistenceInterceptor.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ private boolean isAllowed(Resource resource, Set<String> contextIds, Permission
436436
// Then group the scopes by their context type
437437
.collect(Collectors.groupingBy(s -> s.getContextType()));
438438

439+
if (approvedScopeMap.containsKey(ContextType.USER)) {
440+
// For `user` scopes, we grant access to all resources of the requested type.
441+
// Implementers that use these scopes are encouraged to layer on their own permissions model beyond this.
442+
if (log.isLoggable(Level.FINE)) {
443+
log.fine(requiredPermission.value() + " permission for '" + resourceType + "/" + resource.getId() +
444+
"' is granted via scope " + approvedScopeMap.get(ContextType.USER));
445+
}
446+
return true;
447+
}
448+
439449
if (approvedScopeMap.containsKey(ContextType.PATIENT)) {
440450
if (resource instanceof Provenance) {
441451
// Addressed for issue #1881, Provenance is a special-case: a Patient-compartment resource type that
@@ -476,10 +486,6 @@ private boolean isAllowed(Resource resource, Set<String> contextIds, Permission
476486
return isInCompartment(resource, CompartmentType.PATIENT, contextIds);
477487
}
478488

479-
if (approvedScopeMap.containsKey(ContextType.USER)) {
480-
throw new UnsupportedOperationException("SMART scopes with context type 'user' are not yet supported.");
481-
}
482-
483489
return false;
484490
}
485491

fhir-smart/src/test/java/com/ibm/fhir/smart/test/AuthzPolicyEnforcementTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ public static Object[][] scopeStrings() {
778778
final Set<ResourceType.Value> provenance = Collections.singleton(PROVENANCE);
779779

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

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

802+
{"user/*.*", all_resources, Permission.ALL},
803+
{"user/Patient.read", patient, Permission.READ},
804+
{"user/Observation.write", observation, Permission.WRITE},
805+
801806
{"openid profile", Collections.EMPTY_SET, null},
802807
};
803808
}

0 commit comments

Comments
 (0)