Search in sources :

Example 11 with AuthorizationResult

use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.

the class CoreTokenResourceAuthzModuleTest method shouldAuthorizeAccessToSuperUserIfResourceEnabled.

@Test
public void shouldAuthorizeAccessToSuperUserIfResourceEnabled() throws Exception {
    //given
    CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, true);
    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());
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with AuthorizationResult

use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.

the class CoreTokenResourceAuthzModuleTest method shouldBlockAllAccessIfResourceEnabledButNonSuperUser.

@Test
public void shouldBlockAllAccessIfResourceEnabledButNonSuperUser() throws Exception {
    //given
    CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, true);
    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(false);
    //when
    Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
    //then
    assertFalse(result.get().isAuthorized());
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with AuthorizationResult

use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.

the class SessionResourceAuthzModuleTest method shouldDeferAllOthers.

@Test
public void shouldDeferAllOthers() {
    //given
    RootContext rootContext = new RootContext();
    ActionRequest mockRequest = mock(ActionRequest.class);
    given(mockRequest.getAction()).willReturn("something else");
    //when
    Promise<AuthorizationResult, ResourceException> promise = testModule.authorizeAction(rootContext, mockRequest);
    //then
    assertThat(promise).failedWithException().isExactlyInstanceOf(ForbiddenException.class);
}
Also used : RootContext(org.forgerock.services.context.RootContext) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 14 with AuthorizationResult

use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.

the class SessionResourceAuthzModuleTest method shouldAllowValidateAction.

@Test
public void shouldAllowValidateAction() throws ExecutionException, InterruptedException {
    //given
    Context mockContext = mock(Context.class);
    ActionRequest mockRequest = mock(ActionRequest.class);
    given(mockRequest.getAction()).willReturn("validate");
    //when
    Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
    //then
    assertTrue(result.get().isAuthorized());
}
Also used : Context(org.forgerock.services.context.Context) RootContext(org.forgerock.services.context.RootContext) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 15 with AuthorizationResult

use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.

the class SmsRouteTreeTest method shouldUseOtherAuthModuleForMatchingPath.

@Test
public void shouldUseOtherAuthModuleForMatchingPath() throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    given(requestHandler.handleRead(any(Context.class), any(ReadRequest.class))).willReturn(newResourceResponse("id", "1", json(object())).asPromise());
    Promise<AuthorizationResult, ResourceException> successResult = newResultPromise(accessPermitted());
    given(defaultAuthModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(successResult);
    Context context = mock(Context.class);
    ReadRequest request = Requests.newReadRequest("/service");
    //When
    routeTree.handles("OTHERSERVICE").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
    Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
    //Then
    assertThat(result).succeeded();
    verify(defaultAuthModule).authorizeRead(any(Context.class), any(ReadRequest.class));
    verifyNoMoreInteractions(authModule);
}
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)

Aggregations

AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)20 ResourceException (org.forgerock.json.resource.ResourceException)20 Test (org.testng.annotations.Test)20 BeforeTest (org.testng.annotations.BeforeTest)17 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)12 SSOToken (com.iplanet.sso.SSOToken)10 ActionRequest (org.forgerock.json.resource.ActionRequest)6 Context (org.forgerock.services.context.Context)6 Principal (java.security.Principal)5 SSOException (com.iplanet.sso.SSOException)3 ReadRequest (org.forgerock.json.resource.ReadRequest)3 RequestHandler (org.forgerock.json.resource.RequestHandler)3 RootContext (org.forgerock.services.context.RootContext)3 ResourceResponse (org.forgerock.json.resource.ResourceResponse)2 SmsRouteTree (org.forgerock.openam.core.rest.sms.SmsRouteTree)1