private void authenticate(WorkContext context) { HttpServletRequest request = (HttpServletRequest) context.getHeaders().get("fabric3.httpRequest"); if (!"https".equals(request.getScheme())) { // authentication must be done over HTTPS //throw new WebApplicationException(Response.Status.FORBIDDEN); } // check if the subject was cached in the session HttpSession session = request.getSession(false); if (session != null) { SecuritySubject subject = (SecuritySubject) session.getAttribute(FABRIC3_SUBJECT); if (subject != null) { context.setSubject(subject); return; } } try { authenticator.authenticate(request, context); } catch (NoCredentialsException e) { Response rsResponse = Response.status(UNAUTHORIZED).header("WWW-Authenticate", "Basic realm=\"fabric3\"").build(); throw new WebApplicationException(rsResponse); } catch (AuthenticationException e) { throw new WebApplicationException(FORBIDDEN); } }
private <T> PropagatingCallable<T> createCallable(Callable<T> callable) { WorkContext context = WorkContextCache.getThreadWorkContext(); List<CallbackReference> stack = context.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes stack = new ArrayList<CallbackReference>(stack); } Map<String, Object> headers = context.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes headers = new HashMap<String, Object>(headers); } SecuritySubject subject = context.getSubject(); return new PropagatingCallable<T>(callable, stack, headers, subject); }
private PropagatingRunnable createRunnable(Runnable runnable) { WorkContext context = WorkContextCache.getThreadWorkContext(); List<CallbackReference> stack = context.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes stack = new ArrayList<CallbackReference>(stack); } Map<String, Object> headers = context.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes headers = new HashMap<String, Object>(headers); } SecuritySubject subject = context.getSubject(); return new PropagatingRunnable(runnable, stack, headers, subject); }
public Message invoke(final Message msg) { WorkContext workContext = msg.getWorkContext(); List<CallbackReference> newStack = null; List<CallbackReference> stack = workContext.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes newStack = new ArrayList<CallbackReference>(stack); } Map<String, Object> newHeaders = null; Map<String, Object> headers = workContext.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes newHeaders = new HashMap<String, Object>(headers); } SecuritySubject subject = workContext.getSubject(); Object payload = msg.getBody(); AsyncRequest request = new AsyncRequest(next, payload, subject, newStack, newHeaders, monitor); executorService.execute(request); return RESPONSE; }