[KEYCLOAK-3135] - Fixing permission test

This commit is contained in:
Pedro Igor 2017-04-07 16:02:50 -03:00
parent 55f747ecd0
commit 0b8fc3d6e1
2 changed files with 32 additions and 5 deletions

View file

@ -70,6 +70,10 @@ public class PolicyResourceService {
public Response update(String payload) { public Response update(String payload) {
this.auth.requireManage(); this.auth.requireManage();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
doUpdate(policy, payload); doUpdate(policy, payload);
return Response.status(Status.CREATED).build(); return Response.status(Status.CREATED).build();
@ -102,6 +106,11 @@ public class PolicyResourceService {
@DELETE @DELETE
public Response delete() { public Response delete() {
this.auth.requireManage(); this.auth.requireManage();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
StoreFactory storeFactory = authorization.getStoreFactory(); StoreFactory storeFactory = authorization.getStoreFactory();
PolicyStore policyStore = storeFactory.getPolicyStore(); PolicyStore policyStore = storeFactory.getPolicyStore();
PolicyProviderAdminService resource = getPolicyProviderAdminResource(policy.getType()); PolicyProviderAdminService resource = getPolicyProviderAdminResource(policy.getType());
@ -132,6 +141,11 @@ public class PolicyResourceService {
@NoCache @NoCache
public Response findById() { public Response findById() {
this.auth.requireView(); this.auth.requireView();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(toRepresentation(policy)).build(); return Response.ok(toRepresentation(policy)).build();
} }
@ -145,6 +159,11 @@ public class PolicyResourceService {
@NoCache @NoCache
public Response getDependentPolicies() { public Response getDependentPolicies() {
this.auth.requireView(); this.auth.requireView();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
List<Policy> policies = authorization.getStoreFactory().getPolicyStore().findDependentPolicies(policy.getId(), resourceServer.getId()); List<Policy> policies = authorization.getStoreFactory().getPolicyStore().findDependentPolicies(policy.getId(), resourceServer.getId());
return Response.ok(policies.stream().map(policy -> { return Response.ok(policies.stream().map(policy -> {
@ -164,6 +183,11 @@ public class PolicyResourceService {
@NoCache @NoCache
public Response getScopes() { public Response getScopes() {
this.auth.requireView(); this.auth.requireView();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(policy.getScopes().stream().map(scope -> { return Response.ok(policy.getScopes().stream().map(scope -> {
ScopeRepresentation representation = new ScopeRepresentation(); ScopeRepresentation representation = new ScopeRepresentation();
@ -181,6 +205,10 @@ public class PolicyResourceService {
public Response getResources() { public Response getResources() {
this.auth.requireView(); this.auth.requireView();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(policy.getResources().stream().map(resource -> { return Response.ok(policy.getResources().stream().map(resource -> {
ResourceRepresentation representation = new ResourceRepresentation(); ResourceRepresentation representation = new ResourceRepresentation();
@ -198,6 +226,10 @@ public class PolicyResourceService {
public Response getAssociatedPolicies() { public Response getAssociatedPolicies() {
this.auth.requireView(); this.auth.requireView();
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(policy.getAssociatedPolicies().stream().map(policy -> { return Response.ok(policy.getAssociatedPolicies().stream().map(policy -> {
PolicyRepresentation representation1 = new PolicyRepresentation(); PolicyRepresentation representation1 = new PolicyRepresentation();

View file

@ -72,7 +72,6 @@ public class PolicyService {
@Path("{type}") @Path("{type}")
public Object getResource(@PathParam("type") String type) { public Object getResource(@PathParam("type") String type) {
this.auth.requireManage();
PolicyProviderFactory providerFactory = authorization.getProviderFactory(type); PolicyProviderFactory providerFactory = authorization.getProviderFactory(type);
if (providerFactory != null) { if (providerFactory != null) {
@ -81,10 +80,6 @@ public class PolicyService {
Policy policy = authorization.getStoreFactory().getPolicyStore().findById(type, resourceServer.getId()); Policy policy = authorization.getStoreFactory().getPolicyStore().findById(type, resourceServer.getId());
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
return doCreatePolicyResource(policy); return doCreatePolicyResource(policy);
} }