@Test public void verifyThatVersionEndpointIsPassed() throws Exception { when(uriInfo.getPath()).thenReturn("/api/version"); when(containerRequestContext.getUriInfo()).thenReturn(uriInfo); when(containerRequestContext.getMethod()).thenReturn("GET"); authRequestFilter.filter(containerRequestContext); verify(containerRequestContext, never()).abortWith(any(Response.class)); verify(authenticator, never()).authenticate(any(ContainerRequestContext.class)); }
@Override public void filter(ContainerRequestContext requestContext) { String method = requestContext.getMethod(); if (method.equals("OPTIONS") || method.equals("TRACE")) { return; } if (requestContext.getUriInfo().getPath().equals("/api/version")) { return; } Authenticator.Result result = auth.authenticate(requestContext); if (result.isAccepted()) { requestContext.setProperty("siteId", result.getSiteId()); requestContext.setProperty("userInfo", result.getUserInfo().or(cf.create())); requestContext.setProperty("secrets", result.getSecrets().or(Suppliers.ofInstance(ImmutableMap.of()))); requestContext.setProperty("admin", result.isAdmin()); } else { requestContext.abortWith(errorResultHandler.toResponse(result.getErrorMessage())); } }
AuthRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { String method = requestContext.getMethod(); if (method.equals("OPTIONS") || method.equals("TRACE")) { return; } if (requestContext.getUriInfo().getPath().equals("/api/version")) { return; } Authenticator.Result result = auth.authenticate(requestContext); if (result.isAccepted()) { requestContext.setProperty("siteId", result.getSiteId()); requestContext.setProperty("userInfo", result.getUserInfo().or(cf.create())); requestContext.setProperty("secrets", result.getSecrets().or(Suppliers.ofInstance(ImmutableMap.of()))); requestContext.setProperty("admin", result.isAdmin()); } else { requestContext.abortWith(errorResultHandler.toResponse(result.getErrorMessage())); } } }
AuthRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { String method = requestContext.getMethod(); if (method.equals("OPTIONS") || method.equals("TRACE")) { return; } if (requestContext.getUriInfo().getPath().equals("/api/version")) { return; } Authenticator.Result result = auth.authenticate(requestContext); if (result.isAccepted()) { requestContext.setProperty("siteId", result.getSiteId()); requestContext.setProperty("userInfo", result.getUserInfo().or(cf.create())); requestContext.setProperty("secrets", result.getSecrets().or(Suppliers.ofInstance(ImmutableMap.of()))); requestContext.setProperty("admin", result.isAdmin()); } else { requestContext.abortWith(errorResultHandler.toResponse(result.getErrorMessage())); } } @Inject  AuthRequestFilter(Authenticator auth, ConfigFactory cf); }
AuthRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { String method = requestContext.getMethod(); if (method.equals("OPTIONS") || method.equals("TRACE")) { return; } if (requestContext.getUriInfo().getPath().equals("/api/version")) { return; } Authenticator.Result result = auth.authenticate(requestContext); if (result.isAccepted()) { requestContext.setProperty("siteId", result.getSiteId()); requestContext.setProperty("userInfo", result.getUserInfo().or(cf.create())); requestContext.setProperty("secrets", result.getSecrets().or(Suppliers.ofInstance(ImmutableMap.of()))); requestContext.setProperty("admin", result.isAdmin()); } else { requestContext.abortWith(errorResultHandler.toResponse(result.getErrorMessage())); } } @Inject  AuthRequestFilter(Authenticator auth, ConfigFactory cf); @Override void filter(ContainerRequestContext requestContext); }
AuthRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { String method = requestContext.getMethod(); if (method.equals("OPTIONS") || method.equals("TRACE")) { return; } if (requestContext.getUriInfo().getPath().equals("/api/version")) { return; } Authenticator.Result result = auth.authenticate(requestContext); if (result.isAccepted()) { requestContext.setProperty("siteId", result.getSiteId()); requestContext.setProperty("userInfo", result.getUserInfo().or(cf.create())); requestContext.setProperty("secrets", result.getSecrets().or(Suppliers.ofInstance(ImmutableMap.of()))); requestContext.setProperty("admin", result.isAdmin()); } else { requestContext.abortWith(errorResultHandler.toResponse(result.getErrorMessage())); } } @Inject  AuthRequestFilter(Authenticator auth, ConfigFactory cf); @Override void filter(ContainerRequestContext requestContext);  }