Search in sources :

Example 56 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext 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());
}
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 57 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class RestLogTest method generateTestSSOTokenContext.

private SSOTokenContext generateTestSSOTokenContext(final String name) {
    SSOTokenContext tokenContext = mock(SSOTokenContext.class);
    HashSet<Principal> princes = new HashSet<Principal>();
    Principal p = new Principal() {

        @Override
        public String getName() {
            return name;
        }
    };
    princes.add(p);
    Subject subject = new Subject(false, princes, Collections.EMPTY_SET, Collections.EMPTY_SET);
    when(tokenContext.getCallerSubject()).thenReturn(subject);
    return tokenContext;
}
Also used : SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 58 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class RestLogTest method shouldReturnNullWithNoPrincipalAndMessage.

@Test
public void shouldReturnNullWithNoPrincipalAndMessage() {
    //given
    SSOTokenContext tokenContext = generateTestSSOTokenContext(null);
    //when
    String principal = restLog.debugOperationAttemptAsPrincipal("", "", tokenContext, null, mockDebug);
    //then
    assertNull(principal);
    verify(mockDebug).message(anyString());
}
Also used : SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 59 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class RestLogTest method shouldReturnPrincipalAndMessage.

@Test
public void shouldReturnPrincipalAndMessage() throws ResourceException {
    //given
    SSOTokenContext tokenContext = generateTestSSOTokenContext("test");
    //when
    String principal = restLog.debugOperationAttemptAsPrincipal("", "", tokenContext, null, mockDebug);
    //then
    assertEquals("test", principal);
    verify(mockDebug).message(anyString());
}
Also used : SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 60 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class DashboardResource method readInstance.

/**
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
    SSOTokenContext tokenContext = context.asContext(SSOTokenContext.class);
    SSOToken token = tokenContext.getCallerSSOToken();
    final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
    JsonValue val = new JsonValue(new HashMap<String, Object>());
    if (resourceId.equals("defined")) {
        if (debug.messageEnabled()) {
            debug.message("DashboardResource :: READ by " + principalName + ": Locating definitions from DashboardService.");
        }
        val = Dashboard.getDefinitions(token);
    } else if (resourceId.equals("available")) {
        if (debug.messageEnabled()) {
            debug.message("DashboardResource :: READ by " + principalName + ": Locating allowed apps from DashboardService.");
        }
        val = Dashboard.getAllowedDashboard(token);
    } else if (resourceId.equals("assigned")) {
        if (debug.messageEnabled()) {
            debug.message("DashboardResource :: READ by " + principalName + ": Locating assigned apps from DashboardService.");
        }
        val = Dashboard.getAssignedDashboard(token);
    }
    ResourceResponse resource = newResourceResponse("0", String.valueOf(val.getObject().hashCode()), val);
    return newResultPromise(resource);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue)

Aggregations

SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)62 Test (org.testng.annotations.Test)52 ResourceException (org.forgerock.json.resource.ResourceException)43 RealmContext (org.forgerock.openam.rest.RealmContext)43 Context (org.forgerock.services.context.Context)39 Subject (javax.security.auth.Subject)38 ClientContext (org.forgerock.services.context.ClientContext)37 ResourceResponse (org.forgerock.json.resource.ResourceResponse)33 Matchers.anyString (org.mockito.Matchers.anyString)21 SSOToken (com.iplanet.sso.SSOToken)17 Application (com.sun.identity.entitlement.Application)16 EntitlementException (com.sun.identity.entitlement.EntitlementException)14 JsonValue (org.forgerock.json.JsonValue)13 BeforeTest (org.testng.annotations.BeforeTest)12 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)11 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)9 QueryRequest (org.forgerock.json.resource.QueryRequest)8 Principal (java.security.Principal)7 CreateRequest (org.forgerock.json.resource.CreateRequest)7 QueryResponse (org.forgerock.json.resource.QueryResponse)7