org.apache.shiro.subject.support.SubjectThreadState Java Examples
The following examples show how to use
org.apache.shiro.subject.support.SubjectThreadState.
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: ExtDirectJsonRequestProcessorThread.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public ExtDirectJsonRequestProcessorThread() { Subject subject = SecurityUtils.getSubject(); checkState(subject != null, "Subject is not set"); // create the thread state by this moment as this is created in the master (web container) thread threadState = new SubjectThreadState(subject); final String baseUrl = BaseUrlHolder.get(); processRequest = ServletScopes.transferRequest(new Callable<String>() { @Override public String call() { threadState.bind(); UserIdMdcHelper.set(); try { // apply base-url from the original thread BaseUrlHolder.set(baseUrl); return ExtDirectJsonRequestProcessorThread.super.processRequest(); } finally { UserIdMdcHelper.unset(); threadState.restore(); } } }); }
Example #2
Source File: ContentAuthPluginScript.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { // NOSONAR: pooled ES thread log.error("Thread.sleep interruped", e); } } } }
Example #3
Source File: AbstractShiroTest.java From seed with Mozilla Public License 2.0 | 4 votes |
protected ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
Example #4
Source File: ShiroTestUtils.java From dubai with MIT License | 4 votes |
/** * 綁定Subject到當前線程. */ protected static void bindSubject(Subject subject) { clearSubject(); threadState = new SubjectThreadState(subject); threadState.bind(); }
Example #5
Source File: AbstractShiroTest.java From gazpachoquest with GNU General Public License v3.0 | 4 votes |
protected ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
Example #6
Source File: ShiroLogin.java From gazpachoquest with GNU General Public License v3.0 | 4 votes |
protected static ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
Example #7
Source File: CustomResolverTest.java From usergrid with Apache License 2.0 | 4 votes |
/** * Allows subclasses to set the currently executing {@link Subject} instance. * * @param subject the Subject instance */ protected void setSubject( Subject subject ) { doClearSubject(); subjectThreadState = new SubjectThreadState( subject ); subjectThreadState.bind(); }
Example #8
Source File: ClearShiroSubject.java From usergrid with Apache License 2.0 | 3 votes |
public void clear(){ Subject subject = SecurityUtils.getSubject(); if ( subject == null ) { logger.info( "Shiro Subject was null. No need to clear manually." ); return; } new SubjectThreadState( subject ).clear(); logger.info( "Shiro Subject was NOT null. Subject has been cleared manually." ); }