use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.
the class SessionResourceAuthzModuleTest method shouldAllowLogoutAction.
@Test
public void shouldAllowLogoutAction() throws ExecutionException, InterruptedException {
//given
Context mockContext = mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("logout");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
//then
assertTrue(result.get().isAuthorized());
}
use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.
the class CoreTokenResourceAuthzModuleTest method shouldBlockAllAccessIfResourceDisabled.
@Test
public void shouldBlockAllAccessIfResourceDisabled() throws Exception {
//given
CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, false);
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
//then
assertFalse(result.get().isAuthorized());
}
use of org.forgerock.authz.filter.api.AuthorizationResult 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);
}
use of org.forgerock.authz.filter.api.AuthorizationResult 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);
}
use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.
the class AdminOnlyAuthzModuleTest method shouldAuthorizeValidContext.
@Test
public void shouldAuthorizeValidContext() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
SSOToken mockSSOToken = mock(SSOToken.class);
given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken);
given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("test");
given(mockService.isSuperUser("test")).willReturn(true);
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
//then
assertTrue(result.get().isAuthorized());
}
Aggregations