use of org.forgerock.services.context.ClientContext in project OpenAM by OpenRock.
the class AuditTestUtils method mockAuditContext.
public static Context mockAuditContext() throws Exception {
final Context httpContext = new HttpContext(jsonFromFile("/org/forgerock/openam/rest/fluent/httpContext.json"), AbstractAuditFilterTest.class.getClassLoader());
final Subject callerSubject = new Subject();
final Context securityContext = new SecurityContext(httpContext, null, null);
final Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return callerSubject;
}
@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;
}
};
final Context clientContext = ClientContext.newInternalClientContext(subjectContext);
return new RequestAuditContext(new AuditInfoContext(clientContext, AuditConstants.Component.AUDIT));
}
use of org.forgerock.services.context.ClientContext in project OpenAM by OpenRock.
the class TokenRequestMarshallerImplTest method testX509CertificateTokenMarshalling.
@Test
public void testX509CertificateTokenMarshalling() throws Exception {
X509Certificate certificate = getCertificate();
ClientContext clientInfoContext = ClientContext.buildExternalClientContext(null).certificates(certificate).build();
@SuppressWarnings("unchecked") RestTokenTransformValidatorParameters<X509Certificate[]> params = (RestTokenTransformValidatorParameters<X509Certificate[]>) tokenMarshaller.buildTokenTransformValidatorParameters(new X509TokenState().toJson(), clientInfoContext);
assertEquals(certificate.getEncoded(), (params.getInputToken()[0].getEncoded()));
}
use of org.forgerock.services.context.ClientContext in project OpenAM by OpenRock.
the class TokenRequestMarshallerImplTest method testMissingX509CertificateTokenMarshalling.
@Test(expectedExceptions = TokenMarshalException.class)
public void testMissingX509CertificateTokenMarshalling() throws Exception {
ClientContext clientInfoContext = ClientContext.buildExternalClientContext(null).build();
//no certificate present in the ClientContext, and the offload header set to "" by the module above, so
//exception should be thrown
tokenMarshaller.buildTokenTransformValidatorParameters(new X509TokenState().toJson(), clientInfoContext);
}
use of org.forgerock.services.context.ClientContext in project OpenAM by OpenRock.
the class AMAccessAuditEventBuilder method forRequest.
/**
* Sets client, server and http details from CHF Request and Context.
*
* @param request Request from which client, server and http details will be retrieved.
* @param context Context from which client, server and http details will be retrieved.
* @return this builder
*/
public final AMAccessAuditEventBuilder forRequest(Request request, Context context) {
String clientIpAddress = ClientUtils.getClientIPAddress(context, request);
String ipAddrHeader = SystemPropertiesManager.get(Constants.CLIENT_IP_ADDR_HEADER);
if (ipAddressHeaderPropertyIsSet(ipAddrHeader) && requestHasIpAddressHeader(request, ipAddrHeader)) {
client(clientIpAddress);
} else {
ClientContext clientContext = context.asContext(ClientContext.class);
client(clientIpAddress, clientContext.getRemotePort());
}
MutableUri uri = request.getUri();
String uriScheme = request.getUri().getScheme();
if (StringUtils.isNotEmpty(uriScheme)) {
uriScheme = uriScheme.toLowerCase();
}
boolean isSecure = "https".equals(uriScheme);
httpRequest(isSecure, request.getMethod(), uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + uri.getPath(), getQueryParametersAsMap(request.getForm()), getHeadersAsMap(request.getHeaders()));
return this;
}
Aggregations