Search in sources :

Example 26 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method shouldUpdateResourceTypeName.

@Test
public void shouldUpdateResourceTypeName() throws Exception {
    //given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    JsonValue v = createdResource.getContent();
    v.remove("name");
    v.add("name", "modifiedName");
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(v);
    doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
    //then
    assertThat(promise).succeeded().withContent().stringAt("name").isEqualTo("modifiedName");
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 27 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method updateShouldFailWhenJsonInvalid.

@Test
public void updateShouldFailWhenJsonInvalid() throws Exception {
    //given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    // modify value created to contain invalid Json resource type
    JsonValue modifiedValue = createdResource.getContent();
    modifiedValue.remove("name");
    modifiedValue.add("x-y", "z");
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(modifiedValue);
    doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
    //then
    assertResourcePromiseFailedWithCodes(promise, ResourceException.BAD_REQUEST, EntitlementException.INVALID_CLASS);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 28 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method shouldUpdateResourceTypes.

@Test
public void shouldUpdateResourceTypes() throws Exception {
    //given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(createdResource.getContent());
    doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
    //then
    assertThat(promise).succeeded();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 29 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class PrivilegeAuthzModuleTest method crestUpdateIsAllowed.

@Test
public void crestUpdateIsAllowed() throws SSOException, DelegationException {
    // Given...
    final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
    final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
    given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS)).willReturn(permission);
    given(subjectContext.getCallerSSOToken()).willReturn(token);
    given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
    JsonValue jsonValue = json(object(field("someKey", "someValue")));
    Promise<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
    given(provider.updateInstance(isA(Context.class), eq("123"), isA(UpdateRequest.class))).willReturn(promise);
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm("abc", "abc");
    final UpdateRequest request = Requests.newUpdateRequest("/policies/123", JsonValue.json(new Object()));
    Promise<ResourceResponse, ResourceException> result = router.handleUpdate(context, request);
    // Then...
    assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) UpdateRequest(org.forgerock.json.resource.UpdateRequest) FilterChain(org.forgerock.json.resource.FilterChain) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) Matchers.anyString(org.mockito.Matchers.anyString) DelegationPermission(com.sun.identity.delegation.DelegationPermission) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 30 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class AuditFilterTest method shouldAuditFailureForExceptions.

@Test
public void shouldAuditFailureForExceptions() throws Exception {
    Promise<ResourceResponse, ResourceException> myPromise = new NotFoundException("message").asPromise();
    given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
    given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
    AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
    auditFilter.filterUpdate(context, updateRequest, filterChain);
    verify(auditor).auditAccessFailure(404, "message");
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) NotFoundException(org.forgerock.json.resource.NotFoundException) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Aggregations

UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 Test (org.testng.annotations.Test)33 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 JsonValue (org.forgerock.json.JsonValue)26 ResourceException (org.forgerock.json.resource.ResourceException)26 Context (org.forgerock.services.context.Context)16 Matchers.anyString (org.mockito.Matchers.anyString)13 Subject (javax.security.auth.Subject)11 Application (com.sun.identity.entitlement.Application)9 RealmContext (org.forgerock.openam.rest.RealmContext)9 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)7 ClientContext (org.forgerock.services.context.ClientContext)7 HashSet (java.util.HashSet)6 ResourceType (org.forgerock.openam.entitlement.ResourceType)5 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 Router (org.forgerock.json.resource.Router)2 UmaPolicy (org.forgerock.openam.uma.UmaPolicy)2 DelegationPermission (com.sun.identity.delegation.DelegationPermission)1 Privilege (com.sun.identity.entitlement.Privilege)1