[KEYCLOAK-3249] - AuthorizationContext.hasScopePermission() gives NPE

This commit is contained in:
Pedro Igor 2016-07-06 09:39:56 -03:00
parent 948f37b01a
commit 5ef65e837c
2 changed files with 8 additions and 8 deletions

View file

@ -16,8 +16,10 @@
*/ */
package org.keycloak.representations.idm.authorization; package org.keycloak.representations.idm.authorization;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
@ -31,6 +33,7 @@ public class Permission {
@JsonProperty("resource_set_name") @JsonProperty("resource_set_name")
private final String resourceSetName; private final String resourceSetName;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Set<String> scopes; private Set<String> scopes;
public Permission() { public Permission() {
@ -52,6 +55,10 @@ public class Permission {
} }
public Set<String> getScopes() { public Set<String> getScopes() {
if (this.scopes == null) {
this.scopes = new HashSet<>();
}
return this.scopes; return this.scopes;
} }

View file

@ -95,11 +95,7 @@ public final class Permissions {
resourceName = resource.getName(); resourceName = resource.getName();
} }
Set<String> scopes = null; Set<String> scopes = permission.getScopes().stream().map(Scope::getName).collect(Collectors.toSet());
if (!permission.getScopes().isEmpty()) {
scopes = permission.getScopes().stream().map(Scope::getName).collect(Collectors.toSet());
}
return new Permission(resourceId, resourceName, scopes); return new Permission(resourceId, resourceName, scopes);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@ -111,9 +107,6 @@ public final class Permissions {
if (evalPermission == null) { if (evalPermission == null) {
evalPermission = permission; evalPermission = permission;
if (evalPermission.getScopes() != null && evalPermission.getScopes().isEmpty()) {
evalPermission.setScopes(null);
}
perms.put(permission.getResourceSetId(), evalPermission); perms.put(permission.getResourceSetId(), evalPermission);
} }