Search in sources :

Example 31 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaGatewayTest method login.

@Test
public void login() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    SSOToken expectedSSOToken = new SSOToken("token");
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(expectedSSOToken).build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> actualSSOToken = simbaGateway.login(containerRequestMock);
    assertThat(actualSSOToken.isPresent()).isTrue();
    assertThat(actualSSOToken.get()).isEqualTo(expectedSSOToken.getToken());
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 32 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaCredentialsFactoryTest method create_SSOTokenIsMappedProperly.

@Test
public void create_SSOTokenIsMappedProperly() throws Exception {
    String token = "55687";
    ContainerRequest containerRequest = new ContainerRequestBuilderForTests().withRequestUri(URI.create(REQUESTURL)).addHeader(X_SSO_TOKEN, token).withHttpMethod(HttpMethods.GET).build();
    Map<String, String> requestParameters = Maps.newHashMap();
    SimbaCredentials expected = new SimbaCredentialsBuilderForTests().withRequestUrl(REQUESTURL).addHeader(X_SSO_TOKEN, token).withRequestParameters(requestParameters).withHostServerName(RequestUtil.HOST_SERVER_NAME).withSsotoken(token).build();
    SimbaCredentials actual = factory.create(containerRequest);
    assertThat(actual).isEqualTo(expected);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 33 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheRequestUriToTheSameProtocolAsTheXForwardProtoHeader.

@Test
public void shouldSetTheRequestUriToTheSameProtocolAsTheXForwardProtoHeader() throws Exception {
    // given
    final String theProtocol = "https";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_PROTO_HEADER_KEY, theProtocol);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://jimwebber.org:1234"), URI.create("http://jimwebber.org:1234/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertThat(result.getBaseUri().getScheme(), containsString(theProtocol));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 34 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader.

@Test
public void shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader() throws Exception {
    // given
    final String xForwardHostAndPort = "jimwebber.org:1234";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://iansrobinson.com"), URI.create("http://iansrobinson.com/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertThat(result.getBaseUri().toString(), containsString(xForwardHostAndPort));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 35 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader.

@Test
public void shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader() throws Exception {
    // given
    final String xForwardHostAndPort = "jimwebber.org:1234";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://iansrobinson.com"), URI.create("http://iansrobinson.com/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertTrue(result.getRequestUri().toString().startsWith("http://" + xForwardHostAndPort));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)43 Test (org.junit.Test)37 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)16 WebApplication (com.sun.jersey.spi.container.WebApplication)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 URI (java.net.URI)9 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)9 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)6 ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)5 THttpClient (org.apache.thrift.transport.THttpClient)5 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 XForwardFilter (org.neo4j.server.web.XForwardFilter)4 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)4 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)4 Before (org.junit.Before)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3