本文整理汇总了Java中org.apache.shiro.util.ThreadState类的典型用法代码示例。如果您正苦于以下问题:Java ThreadState类的具体用法?Java ThreadState怎么用?Java ThreadState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadState类属于org.apache.shiro.util包,在下文中一共展示了ThreadState类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSecurityContext
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
@Override
public SecurityContext initSecurityContext(String securityContextInfo) {
if (securityContextInfo == null || !securityContextInfo.startsWith(this.getClass().getSimpleName())) {
return new SecurityContext(false);
}
String ssid = securityContextInfo.substring(this.getClass().getSimpleName().length());
if (ssid != null) {
Subject subject = new Subject.Builder().sessionId(ssid).buildSubject();
if (subject.getPrincipal() != null) {
Context.sessionScope().setUser(subject.getPrincipal().toString());
ThreadState threadState = new SubjectThreadState(subject);
threadState.bind();
log.debug("init Shiro security context for user " + subject.getPrincipal().toString());
return new SecurityContext(true, threadState);
}
}
return new SecurityContext(false);
}
示例2: run
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
@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);
return contentPermissionChecker.isPermitted(repositoryName, format, BROWSE, variableSource);
}
}
return false;
}
finally {
threadState.clear();
}
}
示例3: bindSubject
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
/**
* this binds the passed-in subject to the executing thread, normally, you would do this:
*
* ThreadState state = null; try{ state = IntegratedSecurityService.bindSubject(subject); //do the
* rest of the work as this subject } finally{ if(state!=null) state.clear(); }
*/
public ThreadState bindSubject(Subject subject) {
if (subject == null) {
return null;
}
ThreadState threadState = new SubjectThreadState(subject);
threadState.bind();
return threadState;
}
示例4: SubjectRunnable
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
/**
* Creates a new {@code SubjectRunnable} that, when executed, will perform thread state
* {@link ThreadState#bind binding} and guaranteed {@link ThreadState#restore restoration} before and after the
* {@link Runnable Runnable}'s execution, respectively.
*
* @param threadState the thread state to bind and unbind before and after the runnable's execution.
* @param delegate the delegate {@code Runnable} to execute when this instance is {@link #run() run()}.
* @throws IllegalArgumentException if either the {@code ThreadState} or {@link Runnable} arguments are {@code null}.
*/
protected SubjectRunnable(ThreadState threadState, Runnable delegate) throws IllegalArgumentException {
if (threadState == null) {
throw new IllegalArgumentException("ThreadState argument cannot be null.");
}
this.threadState = threadState;
if (delegate == null) {
throw new IllegalArgumentException("Runnable argument cannot be null.");
}
this.runnable = delegate;
}
示例5: SubjectCallable
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
protected SubjectCallable(ThreadState threadState, Callable<V> delegate) {
if (threadState == null) {
throw new IllegalArgumentException("ThreadState argument cannot be null.");
}
this.threadState = threadState;
if (delegate == null) {
throw new IllegalArgumentException("Callable delegate instance cannot be null.");
}
this.callable = delegate;
}
示例6: bindFakeUser
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
/**
*
* @param userName
* @return
*/
@Override
public boolean bindFakeUser(String userName) {
if (baseRealm.accountExists(userName)) {
PrincipalCollection principals = new SimplePrincipalCollection(userName, UserRealm.USER_REALM_NAME);
Subject subj = new Subject.Builder().principals(principals).buildSubject();
ThreadState threadState = new SubjectThreadState(subj);
threadState.bind();
return true;
}
return false;
}
示例7: doNormalMsg
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
private void doNormalMsg() {
Message msg = null;
msg = BaseCommand.readRequest(this);
ThreadState threadState = null;
try {
if (msg != null) {
// this.logger.fine("donormalMsg() msgType " + msg.getMessageType());
// Since this thread is not interrupted when the cache server is
// shutdown,
// test again after a message has been read. This is a bit of a hack. I
// think this thread should be interrupted, but currently AcceptorImpl
// doesn't keep track of the threads that it launches.
if (!this.processMessages || (crHelper.isShutdown())) {
if (logger.isDebugEnabled()) {
logger.debug("{} ignoring message of type {} from client {} due to shutdown.",
getName(), MessageType.getString(msg.getMessageType()), this.proxyId);
}
return;
}
if (msg.getMessageType() != MessageType.PING) {
// check for invalid number of message parts
if (msg.getNumberOfParts() <= 0) {
failureCount++;
if (failureCount > 3) {
this.processMessages = false;
return;
} else {
return;
}
}
}
if (logger.isTraceEnabled()) {
logger.trace("{} received {} with txid {}", getName(),
MessageType.getString(msg.getMessageType()), msg.getTransactionId());
if (msg.getTransactionId() < -1) { // TODO: why is this happening?
msg.setTransactionId(-1);
}
}
if (msg.getMessageType() != MessageType.PING) {
// we have a real message (non-ping),
// so let's call receivedPing to let the CHM know client is busy
acceptor.getClientHealthMonitor().receivedPing(this.proxyId);
}
Command command = getCommand(Integer.valueOf(msg.getMessageType()));
if (command == null) {
command = Default.getCommand();
}
// if a subject exists for this uniqueId, binds the subject to this thread so that we can do
// authorization later
if (AcceptorImpl.isIntegratedSecurity() && !isInternalMessage()
&& this.communicationMode != Acceptor.GATEWAY_TO_GATEWAY) {
long uniqueId = getUniqueId();
Subject subject = this.clientUserAuths.getSubject(uniqueId);
if (subject != null) {
threadState = securityService.bindSubject(subject);
}
}
command.execute(msg, this);
}
} finally {
// Keep track of the fact that a message is no longer being
// processed.
setNotProcessingMessage();
clearRequestMsg();
if (threadState != null) {
threadState.clear();
}
}
}
示例8: deliverMessage
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
/**
* Delivers the message to the client representing this client proxy.
*
* @param conflatable
*/
protected void deliverMessage(Conflatable conflatable) {
ThreadState state = this.securityService.bindSubject(this.subject);
ClientUpdateMessage clientMessage = null;
if (conflatable instanceof HAEventWrapper) {
clientMessage = ((HAEventWrapper) conflatable).getClientUpdateMessage();
} else {
clientMessage = (ClientUpdateMessage) conflatable;
}
this._statistics.incMessagesReceived();
// post process
if (this.securityService.needPostProcess()) {
Object oldValue = clientMessage.getValue();
Object newValue = securityService.postProcess(clientMessage.getRegionName(),
clientMessage.getKeyOfInterest(), oldValue, clientMessage.valueIsObject());
clientMessage.setLatestValue(newValue);
}
if (clientMessage.needsNoAuthorizationCheck() || postDeliverAuthCheckPassed(clientMessage)) {
// If dispatcher is getting initialized, add the event to temporary queue.
if (this.messageDispatcherInit) {
synchronized (this.queuedEventsSync) {
if (this.messageDispatcherInit) { // Check to see value did not changed while getting the
// synchronize lock.
if (logger.isDebugEnabled()) {
logger.debug(
"Message dispatcher for proxy {} is getting initialized. Adding message to the queuedEvents.",
this);
}
this.queuedEvents.add(conflatable);
return;
}
}
}
if (this._messageDispatcher != null) {
this._messageDispatcher.enqueueMessage(conflatable);
} else {
this._statistics.incMessagesFailedQueued();
if (logger.isDebugEnabled()) {
logger.debug(
"Message is not added to the queue. Message dispatcher for proxy: {} doesn't exist.",
this);
}
}
} else {
this._statistics.incMessagesFailedQueued();
}
if (state != null)
state.clear();
}
示例9: createThreadState
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
protected ThreadState createThreadState(Subject subject) {
return new SubjectThreadState(subject);
}
示例10: createThreadState
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
private ThreadState createThreadState(Subject subject) {
return new SubjectThreadState(subject);
}
示例11: stopSecurityContext
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
@Override
public void stopSecurityContext(SecurityContext secCtx) {
if (secCtx != null && secCtx.getAnyContext() instanceof ThreadState) {
((ThreadState) secCtx.getAnyContext()).clear();
}
}
示例12: createThreadState
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
protected ThreadState createThreadState(Subject subject) {
return new SubjectThreadState(subject);
}
示例13: createThreadState
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
protected static ThreadState createThreadState(Subject subject) {
return new SubjectThreadState(subject);
}
示例14: bindSubject
import org.apache.shiro.util.ThreadState; //导入依赖的package包/类
ThreadState bindSubject(Subject subject);