Search in sources :

Example 21 with HttpContext

use of org.forgerock.json.resource.http.HttpContext 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;
        }
    };
}
Also used : 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) Debug(com.sun.identity.shared.debug.Debug) Subject(javax.security.auth.Subject)

Example 22 with HttpContext

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

the class ScriptResourceTest method setUp.

@BeforeMethod
public void setUp() throws ResourceException {
    Logger logger = mock(Logger.class);
    ScriptingService scriptingService = new MockScriptingService();
    ScriptingServiceFactory serviceFactory = mock(ScriptingServiceFactory.class);
    when(serviceFactory.create(any(Subject.class), anyString())).thenReturn(scriptingService);
    ExceptionMappingHandler<ScriptException, ResourceException> errorHandler = new ScriptExceptionMappingHandler();
    scriptResource = new ScriptResource(logger, serviceFactory, errorHandler, new StandardScriptValidator(new StandardScriptEngineManager()));
    context = mock(Context.class);
    given(context.asContext(HttpContext.class)).willReturn(new HttpContext(json(object(field("headers", Collections.emptyMap()), field("parameters", Collections.emptyMap()))), null));
}
Also used : StandardScriptEngineManager(org.forgerock.openam.scripting.StandardScriptEngineManager) HttpContext(org.forgerock.json.resource.http.HttpContext) ScriptContext(org.forgerock.openam.scripting.ScriptConstants.ScriptContext) Context(org.forgerock.services.context.Context) ScriptingService(org.forgerock.openam.scripting.service.ScriptingService) HttpContext(org.forgerock.json.resource.http.HttpContext) StandardScriptValidator(org.forgerock.openam.scripting.StandardScriptValidator) Logger(org.slf4j.Logger) ScriptingServiceFactory(org.forgerock.openam.scripting.service.ScriptingServiceFactory) Subject(javax.security.auth.Subject) ScriptException(org.forgerock.openam.scripting.ScriptException) ResourceException(org.forgerock.json.resource.ResourceException) ScriptExceptionMappingHandler(org.forgerock.openam.scripting.rest.ScriptExceptionMappingHandler) ScriptResource(org.forgerock.openam.scripting.rest.ScriptResource) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 23 with HttpContext

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

the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextWithContext.

@Test
public void testGetBaseURLFromHTTPContextWithContext() 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("/openam");
    // When
    String url = provider.getRootURL(httpContext);
    // Then
    assertThat(url).isEqualTo("http://fred/openam");
}
Also used : HashMap(java.util.HashMap) HttpContext(org.forgerock.json.resource.http.HttpContext) List(java.util.List) Test(org.testng.annotations.Test)

Example 24 with HttpContext

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

the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextNoHeader.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testGetBaseURLFromHTTPContextNoHeader() throws Exception {
    // Given
    HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, Collections.emptyMap()), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    // When
    String url = provider.getRootURL(httpContext);
// Then - illegal argument exception;
}
Also used : HttpContext(org.forgerock.json.resource.http.HttpContext) Test(org.testng.annotations.Test)

Example 25 with HttpContext

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

the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextHeaderMissingAttributes.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testGetBaseURLFromHTTPContextHeaderMissingAttributes() throws Exception {
    // Given
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("host", Arrays.asList("fred"));
    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 - illegal argument exception;
}
Also used : HashMap(java.util.HashMap) HttpContext(org.forgerock.json.resource.http.HttpContext) List(java.util.List) Test(org.testng.annotations.Test)

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