Search in sources :

Example 1 with HttpContext

use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.

the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContext.

@Test
public void testGetBaseURLFromHTTPContext() throws Exception {
    // Given
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Forwarded", Arrays.asList("host=\"fred\";proto=\"http\""));
    HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, headers), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    provider.setContextPath("");
    // When
    String url = provider.getRootURL(httpContext);
    // Then
    assertThat(url).isEqualTo("http://fred");
}
Also used : HashMap(java.util.HashMap) HttpContext(org.forgerock.json.resource.http.HttpContext) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with HttpContext

use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.

the class RequestValuesBaseURLProviderTest method testGetBaseURLFromHTTPContext.

@Test
public void testGetBaseURLFromHTTPContext() throws Exception {
    // Given
    HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, Collections.emptyMap()), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()), field("path", "http://fred:8080/toto"))), null);
    // When
    String url = provider.getRootURL(httpContext);
    // Then
    assertThat(url).isEqualTo("http://fred:8080");
}
Also used : HttpContext(org.forgerock.json.resource.http.HttpContext) Test(org.testng.annotations.Test)

Example 3 with HttpContext

use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.

the class TokenResource method getLocale.

private java.util.Locale getLocale(Context context) throws SSOException, SMSException {
    ISLocaleContext locale = new ISLocaleContext();
    HttpContext httpContext = context.asContext(HttpContext.class);
    locale.setLocale(httpContext);
    return locale.getLocale();
}
Also used : HttpContext(org.forgerock.json.resource.http.HttpContext) ISLocaleContext(com.sun.identity.common.ISLocaleContext)

Example 4 with HttpContext

use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.

the class SelfServiceRequestHandlerTest method setUp.

@BeforeMethod
public void setUp() {
    MockitoAnnotations.initMocks(this);
    context = new HttpContext(json(object(field("headers", Collections.emptyMap()), field("parameters", Collections.emptyMap()))), null);
    selfServiceHandler = new SelfServiceRequestHandler<>(MockBuilder.class, consoleConfigHandler, providerFactory, serviceFactory);
}
Also used : HttpContext(org.forgerock.json.resource.http.HttpContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with HttpContext

use of org.forgerock.json.resource.http.HttpContext 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)

Aggregations

HttpContext (org.forgerock.json.resource.http.HttpContext)26 Test (org.testng.annotations.Test)8 SSOException (com.iplanet.sso.SSOException)7 List (java.util.List)6 ResourceException (org.forgerock.json.resource.ResourceException)6 SMSException (com.sun.identity.sm.SMSException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 HashMap (java.util.HashMap)5 JsonValue (org.forgerock.json.JsonValue)5 NotFoundException (org.forgerock.json.resource.NotFoundException)5 NotSupportedException (org.forgerock.json.resource.NotSupportedException)5 SSOToken (com.iplanet.sso.SSOToken)4 ISLocaleContext (com.sun.identity.common.ISLocaleContext)4 IdRepoException (com.sun.identity.idm.IdRepoException)4 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)4 MessagingException (javax.mail.MessagingException)4 Subject (javax.security.auth.Subject)4 BadRequestException (org.forgerock.json.resource.BadRequestException)4 ConflictException (org.forgerock.json.resource.ConflictException)4 ForbiddenException (org.forgerock.json.resource.ForbiddenException)4