Search in sources :

Example 1 with ClientContext

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));
}
Also used : SecurityContext(org.forgerock.services.context.SecurityContext) HttpContext(org.forgerock.json.resource.http.HttpContext) AuditInfoContext(org.forgerock.openam.rest.resource.AuditInfoContext) Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) SSOException(com.iplanet.sso.SSOException) AuditInfoContext(org.forgerock.openam.rest.resource.AuditInfoContext) Subject(javax.security.auth.Subject) Debug(com.sun.identity.shared.debug.Debug)

Example 2 with ClientContext

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()));
}
Also used : X509TokenState(org.forgerock.openam.sts.user.invocation.X509TokenState) RestTokenTransformValidatorParameters(org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters) ClientContext(org.forgerock.services.context.ClientContext) X509Certificate(java.security.cert.X509Certificate) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with ClientContext

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);
}
Also used : X509TokenState(org.forgerock.openam.sts.user.invocation.X509TokenState) ClientContext(org.forgerock.services.context.ClientContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with ClientContext

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;
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) MutableUri(org.forgerock.http.MutableUri)

Aggregations

ClientContext (org.forgerock.services.context.ClientContext)4 X509TokenState (org.forgerock.openam.sts.user.invocation.X509TokenState)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 Debug (com.sun.identity.shared.debug.Debug)1 X509Certificate (java.security.cert.X509Certificate)1 Subject (javax.security.auth.Subject)1 MutableUri (org.forgerock.http.MutableUri)1 HttpContext (org.forgerock.json.resource.http.HttpContext)1 AuditInfoContext (org.forgerock.openam.rest.resource.AuditInfoContext)1 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)1 RestTokenTransformValidatorParameters (org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters)1 Context (org.forgerock.services.context.Context)1 RequestAuditContext (org.forgerock.services.context.RequestAuditContext)1 SecurityContext (org.forgerock.services.context.SecurityContext)1