Search in sources :

Example 6 with AuthorizationResult

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

the class AdminOnlyAuthzModuleTest method shouldFailNonSuperUser.

@Test
public void shouldFailNonSuperUser() 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(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 7 with AuthorizationResult

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

the class SpecialOrAdminOrAgentAuthzModuleTest method shouldAuthorizeAdmin.

@Test
public void shouldAuthorizeAdmin() 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(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) Principal(java.security.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with AuthorizationResult

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

the class SpecialOrAdminOrAgentAuthzModuleTest method shouldAuthorizeSpecialUser.

@Test
public void shouldAuthorizeSpecialUser() 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(true);
    given(mockService.isSuperUser("test")).willReturn(false);
    //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) Principal(java.security.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with AuthorizationResult

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

the class SpecialOrAdminOrAgentAuthzModuleTest method shouldAuthorizeAgent.

@Test
public void shouldAuthorizeAgent() 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(true);
    given(mockSpecialUserIdentity.isSpecialUser(mockSSOToken)).willReturn(false);
    given(mockService.isSuperUser("test")).willReturn(false);
    //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) Principal(java.security.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with AuthorizationResult

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

the class SpecialOrAdminOrAgentAuthzModuleTest method shouldErrorInvalidContext.

@Test
public void shouldErrorInvalidContext() 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)).willThrow(new SSOException(""));
    //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) SSOException(com.iplanet.sso.SSOException) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Principal(java.security.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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