use of org.forgerock.authz.filter.api.AuthorizationResult in project OpenAM by OpenRock.
the class SpecialOrAdminOrAgentAuthzModuleTest method shouldFailNonAgentNonSuperUser.
@Test
public void shouldFailNonAgentNonSuperUser() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
SSOToken mockSSOToken = mock(SSOToken.class);
Principal principal = mock(Principal.class);
given(mockSSOToken.getPrincipal()).willReturn(principal);
given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken);
given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("test");
given(mockAgentIdentity.isAgent(mockSSOToken)).willReturn(false);
given(mockSpecialUserIdentity.isSpecialUser(mockSSOToken)).willReturn(false);
given(mockService.isSuperUser("test")).willReturn(false);
//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 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());
}
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());
}
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);
}
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());
}
Aggregations