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