/** * Return the current RequestAttributes instance as ServletRequestAttributes. * @see RequestContextHolder#currentRequestAttributes() */ private static ServletRequestAttributes currentRequestAttributes() { RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes(); if (!(requestAttr instanceof ServletRequestAttributes)) { throw new IllegalStateException("Current request is not a servlet request"); } return (ServletRequestAttributes) requestAttr; }
/** * Return the current RequestAttributes instance as ServletRequestAttributes. * @see RequestContextHolder#currentRequestAttributes() */ private static ServletRequestAttributes currentRequestAttributes() { RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes(); if (!(requestAttr instanceof ServletRequestAttributes)) { throw new IllegalStateException("Current request is not a servlet request"); } return (ServletRequestAttributes) requestAttr; }
@Override @Nullable public Object resolveContextualObject(String key) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); return attributes.resolveReference(key); }
@Override public String getConversationId() { return RequestContextHolder.currentRequestAttributes().getSessionId(); }
@Override @Nullable public Object remove(String name) { Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex(); synchronized (mutex) { return super.remove(name); } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex(); synchronized (mutex) { return super.get(name, objectFactory); } }
@Override public void registerDestructionCallback(String name, Runnable callback) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); attributes.registerDestructionCallback(name, callback, getScope()); }
@Override @Nullable public Object resolveContextualObject(String key) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); return attributes.resolveReference(key); }
@Override public String getConversationId() { return RequestContextHolder.currentRequestAttributes().getSessionId(); }
@Override @Nullable public Object remove(String name) { Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex(); synchronized (mutex) { return super.remove(name); } }
@Override @Nullable public Object remove(String name) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); Object scopedObject = attributes.getAttribute(name, getScope()); if (scopedObject != null) { attributes.removeAttribute(name, getScope()); return scopedObject; } else { return null; } }
@Override public void registerDestructionCallback(String name, Runnable callback) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); attributes.registerDestructionCallback(name, callback, getScope()); }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex(); synchronized (mutex) { return super.get(name, objectFactory); } }
public void configureRelayRedirect(String relayState) { //configure relay state if (UaaUrlUtils.isUrl(relayState)) { RequestContextHolder.currentRequestAttributes() .setAttribute( UaaSavedRequestAwareAuthenticationSuccessHandler.URI_OVERRIDE_ATTRIBUTE, relayState, RequestAttributes.SCOPE_REQUEST ); } }
@Override @Nullable public Object remove(String name) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); Object scopedObject = attributes.getAttribute(name, getScope()); if (scopedObject != null) { attributes.removeAttribute(name, getScope()); return scopedObject; } else { return null; } }
/** * Display a report page. * @throws ServletException e * @throws IOException e */ @ReadOperation public void report() throws ServletException, IOException { final ServletRequestAttributes currentRequestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest httpServletRequest = currentRequestAttributes.getRequest(); final HttpServletResponse httpResponse = currentRequestAttributes.getResponse(); reportServlet.service(httpServletRequest, httpResponse); } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); Object scopedObject = attributes.getAttribute(name, getScope()); if (scopedObject == null) { scopedObject = objectFactory.getObject(); attributes.setAttribute(name, scopedObject, getScope()); // Retrieve object again, registering it for implicit session attribute updates. // As a bonus, we also allow for potential decoration at the getAttribute level. Object retrievedObject = attributes.getAttribute(name, getScope()); if (retrievedObject != null) { // Only proceed with retrieved object if still present (the expected case). // If it disappeared concurrently, we return our locally created instance. scopedObject = retrievedObject; } } return scopedObject; }
@Test public void relay_sets_attribute() { for (String url : Arrays.asList("test", "www.google.com", null)) { authprovider.configureRelayRedirect(url); assertNull(RequestContextHolder.currentRequestAttributes().getAttribute(UaaSavedRequestAwareAuthenticationSuccessHandler.URI_OVERRIDE_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)); } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); Object scopedObject = attributes.getAttribute(name, getScope()); if (scopedObject == null) { scopedObject = objectFactory.getObject(); attributes.setAttribute(name, scopedObject, getScope()); // Retrieve object again, registering it for implicit session attribute updates. // As a bonus, we also allow for potential decoration at the getAttribute level. Object retrievedObject = attributes.getAttribute(name, getScope()); if (retrievedObject != null) { // Only proceed with retrieved object if still present (the expected case). // If it disappeared concurrently, we return our locally created instance. scopedObject = retrievedObject; } } return scopedObject; }
RequestContextHolder.currentRequestAttributes(); fail();