Search in sources :

Example 36 with ResourceException

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

the class OathDevicesResourceTest method shouldNotDeleteTrustedDeviceWhenNotFound.

@Test
public void shouldNotDeleteTrustedDeviceWhenNotFound() throws ResourceException, SSOException {
    // Given
    DeleteRequest request = Requests.newDeleteRequest("UUID_3");
    List<JsonValue> devices = new ArrayList<JsonValue>();
    devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
    devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
    given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
    // When
    Promise<ResourceResponse, ResourceException> promise = resource.deleteInstance(ctx(), request.getResourcePath(), request);
    // Then
    assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_FOUND);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 37 with ResourceException

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

the class CoreTokenResourceTest method shouldGetBadRequestForMissingTokenId.

@Test
public void shouldGetBadRequestForMissingTokenId() throws CoreTokenException {
    // Given
    CreateRequest request = mock(CreateRequest.class);
    given(request.getContent()).willReturn(new JsonValue(""));
    doThrow(IllegalArgumentException.class).when(mockStore).createAsync(any(Token.class));
    // When
    Promise<ResourceResponse, ResourceException> promise = resource.createInstance(null, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Token(org.forgerock.openam.cts.api.tokens.Token) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 38 with ResourceException

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

the class SmsRouteTreeTest method shouldUseProvidedAuthModuleForMatchingPath.

@Test
public void shouldUseProvidedAuthModuleForMatchingPath() throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    Context context = mock(Context.class);
    ReadRequest request = Requests.newReadRequest("/not-authorized/service");
    Promise<AuthorizationResult, ResourceException> failResult = newResultPromise(accessDenied("no"));
    given(authModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(failResult);
    //When
    routeTree.handles("NOT_AUTHORIZED").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
    Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
    //Then
    assertThat(result).failedWithException();
    verify(authModule).authorizeRead(any(Context.class), any(ReadRequest.class));
    verifyNoMoreInteractions(requestHandler, defaultAuthModule);
}
Also used : Context(org.forgerock.services.context.Context) RequestHandler(org.forgerock.json.resource.RequestHandler) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 39 with ResourceException

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

the class TokenOwnerAuthzModuleTest method shouldFailInvalidQueryParamToken.

@Test
public void shouldFailInvalidQueryParamToken() throws SSOException, ExecutionException, InterruptedException, BadRequestException {
    //given
    ActionRequest request = Requests.newActionRequest("resource", "deleteProperty");
    request.setAdditionalParameter("tokenId", "token");
    given(mockService.isSuperUser(eq("universal_id"))).willReturn(false);
    given(mockTokenManager.createSSOToken(eq("token"))).willThrow(new SSOException(""));
    //when
    Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, request);
    //then
    assertThat(result).failedWithException().isInstanceOf(ForbiddenException.class);
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) SSOException(com.iplanet.sso.SSOException) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 40 with ResourceException

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

the class PolicyResourceEvaluationTest method shouldHandleEntitlementExceptions.

@Test
public void shouldHandleEntitlementExceptions() throws EntitlementException {
    // Given...
    given(request.getAction()).willReturn("evaluate");
    Context context = buildContextStructure("/abc");
    EntitlementException eE = new EntitlementException(EntitlementException.INVALID_VALUE);
    given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willThrow(eE);
    given(request.getRequestType()).willReturn(RequestType.ACTION);
    // When...
    Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
    // Then...
    verify(request).getAction();
    verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
    verify(request).getRequestType();
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
    verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Aggregations

ResourceException (org.forgerock.json.resource.ResourceException)323 Test (org.testng.annotations.Test)233 ResourceResponse (org.forgerock.json.resource.ResourceResponse)179 JsonValue (org.forgerock.json.JsonValue)145 Context (org.forgerock.services.context.Context)145 RealmContext (org.forgerock.openam.rest.RealmContext)110 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)71 Subject (javax.security.auth.Subject)58 ClientContext (org.forgerock.services.context.ClientContext)56 NotFoundException (org.forgerock.json.resource.NotFoundException)47 BadRequestException (org.forgerock.json.resource.BadRequestException)44 QueryResponse (org.forgerock.json.resource.QueryResponse)43 HashSet (java.util.HashSet)42 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)42 CreateRequest (org.forgerock.json.resource.CreateRequest)40 SSOException (com.iplanet.sso.SSOException)38 ActionResponse (org.forgerock.json.resource.ActionResponse)37 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)37 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)35