Search in sources :

Example 1 with ThreadState

use of org.apache.shiro.util.ThreadState in project geode by apache.

the class CacheClientProxy method deliverMessage.

/**
   * 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) {
                    // 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();
}
Also used : ThreadState(org.apache.shiro.util.ThreadState)

Example 2 with ThreadState

use of org.apache.shiro.util.ThreadState in project geode by apache.

the class IntegratedSecurityService method bindSubject.

/**
   * 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;
}
Also used : SubjectThreadState(org.apache.shiro.subject.support.SubjectThreadState) ThreadState(org.apache.shiro.util.ThreadState) SubjectThreadState(org.apache.shiro.subject.support.SubjectThreadState)

Example 3 with ThreadState

use of org.apache.shiro.util.ThreadState in project geode by apache.

the class ServerConnection method doNormalMsg.

private void doNormalMsg() {
    Message msg = null;
    msg = BaseCommand.readRequest(this);
    ThreadState threadState = null;
    try {
        if (msg != null) {
            // 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();
            }
            // 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();
        }
    }
}
Also used : LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Command(org.apache.geode.internal.cache.tier.Command) ThreadState(org.apache.shiro.util.ThreadState) Subject(org.apache.shiro.subject.Subject)

Aggregations

ThreadState (org.apache.shiro.util.ThreadState)3 Command (org.apache.geode.internal.cache.tier.Command)1 LocalizedMessage (org.apache.geode.internal.logging.log4j.LocalizedMessage)1 Subject (org.apache.shiro.subject.Subject)1 SubjectThreadState (org.apache.shiro.subject.support.SubjectThreadState)1