/** * Convenience method that simplifies binding a Subject to the ThreadContext. * <p/> * <p>The method's existence is to help reduce casting in your own code and to simplify remembering of * ThreadContext key names. The implementation is simple in that, if the Subject is not <tt>null</tt>, * it binds it to the thread, i.e.: * <p/> * <pre> * if (subject != null) { * put( SUBJECT_KEY, subject ); * }</pre> * * @param subject the Subject object to bind to the thread. If the argument is null, nothing will be done. * @since 0.2 */ public static void bind(Subject subject) { if (subject != null) { put(SUBJECT_KEY, subject); } }
/** * Convenience method that simplifies binding the application's SecurityManager instance to the ThreadContext. * <p/> * <p>The method's existence is to help reduce casting in code and to simplify remembering of * ThreadContext key names. The implementation is simple in that, if the SecurityManager is not <tt>null</tt>, * it binds it to the thread, i.e.: * <p/> * <pre> * if (securityManager != null) { * put( SECURITY_MANAGER_KEY, securityManager); * }</pre> * * @param securityManager the application's SecurityManager instance to bind to the thread. If the argument is * null, nothing will be done. * @since 0.9 */ public static void bind(SecurityManager securityManager) { if (securityManager != null) { put(SECURITY_MANAGER_KEY, securityManager); } }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpservletRequest = (HttpServletRequest) servletRequest; URL requestURL = URI.create(httpservletRequest.getRequestURL().toString()).toURL(); String currentResourceURI = ((Request) httpservletRequest).getHttpURI().getPathQuery(); ThreadContext.put("currentResourceURI", currentResourceURI); ThreadContext.put("currentURLProtocol", requestURL.getProtocol()); ThreadContext.put("currentURLHost", requestURL.getHost()); ThreadContext.put("currentURLPort", requestURL.getPort()); filterChain.doFilter(servletRequest, servletResponse); ThreadContext.remove(); }
private void bindUserDataToThread(User user) throws IResourceStore.ResourceStoreException, IResourceStore.ResourceNotFoundException { String username = user.getUsername(); ThreadContext.put("currentuser:userid", userStore.searchUser(username)); ThreadContext.put("currentuser:displayname", user.getDisplayName()); ThreadContext.put("currentuser:username", username); }