use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthenticationFilterTest method testAuthorizedApiKey.
@Test
public void testAuthorizedApiKey() throws IOException {
// Define ApiConfig
FF4jAuthenticationFilter.setApiConfig(new ApiConfig().createApiKey("12", true, true, Util.set("USER")));
// Given
FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
when(mockRequest.getHeaderString("Authorization")).thenReturn("apiKey=12");
when(mockRequest.getMethod()).thenReturn("GET");
UriInfo mockUriInfo = mock(UriInfo.class);
when(mockUriInfo.getPath()).thenReturn("someURL");
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthenticationFilterTest method testGETWadl.
@Test
public void testGETWadl() throws IOException {
// Given
FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
when(mockRequest.getMethod()).thenReturn("GET");
UriInfo mockUriInfo = mock(UriInfo.class);
when(mockUriInfo.getPath()).thenReturn("application.wadl");
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
faf.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testRoleNothing.
@Test
public void testRoleNothing() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = new ResourceInfo() {
public Method getResourceMethod() {
return methodNothing;
}
public Class<?> getResourceClass() {
return targetResource;
}
};
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// OK
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testPermitAll.
@Test
public void testPermitAll() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = mock(ResourceInfo.class);
when(mockResInfo.getResourceMethod()).thenReturn(methodPermit);
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// Then expecte 403
}
use of javax.ws.rs.container.ContainerRequestContext in project narayana by jbosstm.
the class ServerLRAFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
// a request is leaving the container so clear any context on the thread and fix up the LRA response header
Object suspendedLRA = Current.getState("suspendedLRA");
Object newLRA = Current.getState("newLRA");
URL current = Current.peek();
try {
if (current != null) {
int status = responseContext.getStatus();
Response.Status.Family[] cancel0nFamily = (Response.Status.Family[]) requestContext.getProperty(CANCEL_ON_FAMILY_PROP);
Response.Status[] cancel0n = (Response.Status[]) requestContext.getProperty(CANCEL_ON_PROP);
Boolean closeCurrent = (Boolean) requestContext.getProperty(TERMINAL_LRA_PROP);
if (closeCurrent == null)
closeCurrent = false;
if (cancel0nFamily != null)
if (Arrays.stream(cancel0nFamily).anyMatch(f -> Response.Status.Family.familyOf(status) == f))
closeCurrent = true;
if (cancel0n != null && !closeCurrent)
if (Arrays.stream(cancel0n).anyMatch(f -> status == f.getStatusCode()))
closeCurrent = true;
if (closeCurrent) {
lraTrace(requestContext, (URL) newLRA, "ServerLRAFilter after: closing LRA becasue http status is " + status);
lraClient.cancelLRA(current);
if (current.equals(newLRA))
// don't try to cancle newKRA twice
newLRA = null;
}
}
if (newLRA != null) {
lraTrace(requestContext, (URL) newLRA, "ServerLRAFilter after: closing LRA");
lraClient.closeLRA((URL) newLRA);
}
if (responseContext.getStatus() == Response.Status.OK.getStatusCode() && NarayanaLRAClient.isAsyncCompletion(resourceInfo.getResourceMethod())) {
LRALogger.i18NLogger.warn_lraParticipantqForAsync(resourceInfo.getResourceMethod().getDeclaringClass().getName(), resourceInfo.getResourceMethod().getName(), Response.Status.ACCEPTED.getStatusCode(), Response.Status.OK.getStatusCode());
}
} finally {
if (suspendedLRA != null)
Current.push((URL) suspendedLRA);
Current.updateLRAContext(responseContext.getHeaders());
Current.popAll();
}
}
Aggregations