use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class TokenTargetFilterTest method tokenUsedOnTheWrongUser12ApiTest.
@Test(expected = AccessControlException.class)
public void tokenUsedOnTheWrongUser12ApiTest() {
setUpSecurityContext(ORCID1, CLIENT_ID, ScopePathType.READ_LIMITED);
ContainerRequest request = Mockito.mock(ContainerRequest.class);
Mockito.when(request.getPath()).thenReturn("http://api.test.orcid.org/v1.2/" + ORCID2);
Mockito.when(request.getHeaderValue(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME)).thenReturn("1.2");
TokenTargetFilter filter = new TokenTargetFilter();
filter.filter(request);
fail();
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method api2_0_rc4VersionTest.
@Test
public void api2_0_rc4VersionTest() {
MockHttpServletRequest mockReq = new MockHttpServletRequest();
mockReq.setAttribute("X-Forwarded-Proto", "https");
OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/v2.0_rc4/0000-0001-7510-9252/activities");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method apiOauthTokenTest.
@Test
public void apiOauthTokenTest() {
MockHttpServletRequest mockReq = new MockHttpServletRequest();
mockReq.setAttribute("X-Forwarded-Proto", "https");
OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/oauth/token");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
}
use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method api2_0VersionTest.
@Test
public void api2_0VersionTest() {
MockHttpServletRequest mockReq = new MockHttpServletRequest();
mockReq.setAttribute("X-Forwarded-Proto", "https");
OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/v2.0/0000-0001-7510-9252/activities");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
filter.filter(containerRequest);
} catch (Exception e) {
fail();
}
}
use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.
the class SimbaAuthenticatedInjectable method getValue.
@Override
public P getValue(HttpContext httpContext) {
SimbaCredentials credentials;
try {
final ContainerRequest containerRequest = (ContainerRequest) httpContext.getRequest();
credentials = simbaCredentialsFactory.create(containerRequest);
final Optional<SimbaPrincipal> result = authenticator.authenticate(credentials);
if (result.isPresent()) {
return domainProvider.lookUp(result.get());
}
} catch (AuthenticationException e) {
log.error("Something went wrong in the authentication process", e);
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Something went wrong in the authentication process").type(MediaType.APPLICATION_JSON).build());
}
if (required) {
log.warn("Error authenticating credentials: {}", credentials.getSsoToken());
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("You are not allowed to access this resource").type(MediaType.APPLICATION_JSON).build());
}
return null;
}
Aggregations