/** * Creates a new {@code SubjectRunnable} that, when executed, will execute the target {@code delegate}, but * guarantees that it will run associated with the specified {@code Subject}. * * @param subject the Subject to associate with the delegate's execution. * @param delegate the runnable to run. */ public SubjectRunnable(Subject subject, Runnable delegate) { this(new SubjectThreadState(subject), delegate); }
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." ); } }
SecurityManager scm = internalInjector.getInstance(SecurityManager.class); internalSubject = new WebSubject.Builder(scm, request, response).buildWebSubject(); SubjectThreadState sts = new SubjectThreadState(internalSubject); sts.bind(); } else { internalSubject = null; }
public SubjectCallable(Subject subject, Callable<V> delegate) { this(new SubjectThreadState(subject), delegate); }
protected ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
/** * Binds the passed-in subject to the executing thread. Usage: * * <pre> * ThreadState state = null; * try { * state = securityService.bindSubject(subject); * // do the rest of the work as this subject * } finally { * if (state != null) * state.clear(); * } * </pre> */ @Override public ThreadState bindSubject(final Subject subject) { if (subject == null) { throw new AuthenticationRequiredException("Failed to find the authenticated user."); } ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); return threadState; }
/** * 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(); }
protected Subject newSubject(SecurityManager securityManager) { Subject subject = new Subject.Builder(securityManager).buildSubject(); threadState = new SubjectThreadState(subject); threadState.bind(); return subject; } }
/** * Creates a new {@code SubjectRunnable} that, when executed, will execute the target {@code delegate}, but * guarantees that it will run associated with the specified {@code Subject}. * * @param subject the Subject to associate with the delegate's execution. * @param delegate the runnable to run. */ public SubjectRunnable(Subject subject, Runnable delegate) { this(new SubjectThreadState(subject), delegate); }
public SubjectCallable(Subject subject, Callable<V> delegate) { this(new SubjectThreadState(subject), delegate); }
/** * Creates a new {@code SubjectRunnable} that, when executed, will execute the target {@code delegate}, but * guarantees that it will run associated with the specified {@code Subject}. * * @param subject the Subject to associate with the delegate's execution. * @param delegate the runnable to run. */ public SubjectRunnable(Subject subject, Runnable delegate) { this(new SubjectThreadState(subject), delegate); }
protected static ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); } }
/** * Method description * * * @param subject * * @return */ protected ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
public SubjectCallable(Subject subject, Callable<V> delegate) { this(new SubjectThreadState(subject), delegate); }
protected ThreadState createThreadState(Subject subject) { return new SubjectThreadState(subject); }
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); processRequest = ServletScopes.continueRequest(new Callable<String>() { @Override public String call() { threadState.bind(); UserIdMdcHelper.set(); try { return ExtDirectJsonRequestProcessorThread.super.processRequest(); } finally { UserIdMdcHelper.unset(); threadState.restore(); } } }, Collections.<Key<?>, Object>emptyMap()); }
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(); } } }); }
@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) { for (Map<String, Object> asset : assets) { 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(); } }