use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method shouldThrowErrorWthInvalidCondition.
@Test
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, "invalidCondition", mockRequest);
//then
assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved() throws Exception {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
//then
assertThat(promise).succeeded().withContent().hasString("title");
assertThat(promise).succeeded().withContent().stringAt("title").isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(promise).succeeded().withContent().hasBoolean("logical");
assertThat(promise).succeeded().withContent().booleanAt("logical").isFalse();
assertThat(promise.get().getContent().get("config").getObject().toString()).isEqualTo("{\"type\":\"object\",\"properties\":{}}");
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class STSPublishServiceAuthzModule method isSoapSTSAgent.
private boolean isSoapSTSAgent(Context context) throws ResourceException {
SSOTokenContext tokenContext = context.asContext(SSOTokenContext.class);
String userId;
SSOToken token;
try {
token = tokenContext.getCallerSSOToken();
userId = token.getPrincipal().getName();
} catch (SSOException e) {
if (debug.messageEnabled()) {
debug.message("STSPublishServiceAuthzModule :: Unable to obtain SSOToken or principal", e);
}
throw ResourceException.getException(HttpURLConnection.HTTP_UNAUTHORIZED, e.getMessage());
}
if (agentIdentity.isSoapSTSAgent(token)) {
if (debug.messageEnabled()) {
debug.message("STSPublishServiceAuthzModule :: User " + userId + " accepted as Soap STS Agent.");
}
return true;
} else {
if (debug.messageEnabled()) {
debug.message("STSPublishServiceAuthzModule :: User " + userId + " is not a Soap STS Agent.");
}
return false;
}
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class RestRouterIT method mockRequiredContexts.
private Context mockRequiredContexts() {
final HttpContext httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("Accept-Language", Arrays.asList("en"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
SecurityContext securityContext = new SecurityContext(mockContext(httpContext), null, null);
return new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return new Subject();
}
@Override
public SSOToken getCallerSSOToken() {
SSOToken token = mock(SSOToken.class);
try {
given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
} catch (SSOException e) {
// won't happen - it's a mock
}
return token;
}
};
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class AdminOnlyAuthzModuleTest method shouldErrorInvalidContext.
@Test
public void shouldErrorInvalidContext() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
SSOToken mockSSOToken = mock(SSOToken.class);
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());
}
Aggregations