Java Code Examples for org.acegisecurity.context.SecurityContextHolder#getContext()
The following examples show how to use
org.acegisecurity.context.SecurityContextHolder#getContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AcegiSafeSessionFilter.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if(1 + 1 == 2) { SecurityContext oldCtx = SecurityContextHolder.getContext(); SecurityContextHolder.setContext(null); // try { super.doFilter(req, res, chain); } finally { SecurityContextHolder.setContext(oldCtx); } } else { super.doFilter(req, res, chain); } }
Example 2
Source File: TestImpl.java From ramus with GNU General Public License v3.0 | 5 votes |
@Override public void test() { SecurityContext sc = SecurityContextHolder.getContext(); if (sc.getAuthentication() != null) System.out.println(sc.getAuthentication().getName() + " logged by test"); }
Example 3
Source File: JwtAuthenticationFilter.java From blueocean-plugin with MIT License | 5 votes |
@Override public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; if(!shouldApply(request)) { chain.doFilter(req,rsp); return; } Authentication token = verifyToken(request); if(token==null) { // no JWT token found, which is fine --- we just assume the request is authenticated in other means // Some routes that require valid JWT token will check for the presence of JWT token during Stapler // request routing, not here. chain.doFilter(req,rsp); return; } // run the rest of the request with the new identity // create a new context and set it to holder to not clobber existing context SecurityContext sc = new SecurityContextImpl(); sc.setAuthentication(token); SecurityContext previous = SecurityContextHolder.getContext(); SecurityContextHolder.setContext(sc); request.setAttribute(JWT_TOKEN_VALIDATED,true); try { chain.doFilter(req,rsp); } finally { if(previous != null){ SecurityContextHolder.setContext(previous); }else { SecurityContextHolder.clearContext(); } } }
Example 4
Source File: FolderRoleBenchmark.java From folder-auth-plugin with MIT License | 4 votes |
@Setup(Level.Iteration) public void setup() { SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(Objects.requireNonNull(User.getById("user33", true)).impersonate()); }
Example 5
Source File: GlobalRoleBenchmark.java From folder-auth-plugin with MIT License | 4 votes |
@Setup(Level.Iteration) public void setup() { SecurityContext holder = SecurityContextHolder.getContext(); holder.setAuthentication(Objects.requireNonNull(User.getById("user3", true)).impersonate()); }
Example 6
Source File: UserProviderImpl.java From ramus with GNU General Public License v3.0 | 4 votes |
protected String getLogin() { SecurityContext sc = SecurityContextHolder.getContext(); if (sc.getAuthentication() == null) return null; return sc.getAuthentication().getName(); }
Example 7
Source File: ServerAccessRules.java From ramus with GNU General Public License v3.0 | 4 votes |
private SecurityContext getSecurityContext() { return SecurityContextHolder.getContext(); }