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());
}
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;
}
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());
}
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());
}
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);
}
Aggregations