Search in sources :

Example 1 with OperationContext

use of org.apache.geode.cache.operations.OperationContext in project geode by apache.

the class CacheClientProxy method getOperationContext.

private OperationContext getOperationContext(ClientMessage cmsg, String[] regionNameHolder) {
    ClientUpdateMessageImpl cmsgimpl = (ClientUpdateMessageImpl) cmsg;
    OperationContext opctxt = null;
    // TODO SW: Special handling for DynamicRegions; this should be reworked
    // when DynamicRegion API is deprecated
    String regionName = cmsgimpl.getRegionName();
    regionNameHolder[0] = regionName;
    if (cmsgimpl.isCreate()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionCreateOperationContext(true);
        } else {
            PutOperationContext tmp = new PutOperationContext(cmsgimpl.getKeyOfInterest(), cmsgimpl.getValue(), cmsgimpl.valueIsObject(), PutOperationContext.CREATE, true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isUpdate()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionCreateOperationContext(true);
        } else {
            PutOperationContext tmp = new PutOperationContext(cmsgimpl.getKeyOfInterest(), cmsgimpl.getValue(), cmsgimpl.valueIsObject(), PutOperationContext.UPDATE, true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isDestroy()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionDestroyOperationContext(true);
        } else {
            DestroyOperationContext tmp = new DestroyOperationContext(cmsgimpl.getKeyOfInterest(), true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isDestroyRegion()) {
        opctxt = new RegionDestroyOperationContext(true);
    } else if (cmsgimpl.isInvalidate()) {
        InvalidateOperationContext tmp = new InvalidateOperationContext(cmsgimpl.getKeyOfInterest(), true);
        tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
        opctxt = tmp;
    } else if (cmsgimpl.isClearRegion()) {
        RegionClearOperationContext tmp = new RegionClearOperationContext(true);
        tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
        opctxt = tmp;
    }
    return opctxt;
}
Also used : RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) OperationContext(org.apache.geode.cache.operations.OperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext)

Example 2 with OperationContext

use of org.apache.geode.cache.operations.OperationContext in project geode by apache.

the class CacheClientProxy method postDeliverAuthCheckPassed.

private boolean postDeliverAuthCheckPassed(ClientUpdateMessage clientMessage) {
    // process authorization
    if (AcceptorImpl.isAuthenticationRequired() && this.postAuthzCallback == null && AcceptorImpl.isPostAuthzCallbackPresent()) {
        // security is on and callback is null: it means multiuser mode.
        ClientUpdateMessageImpl cumi = (ClientUpdateMessageImpl) clientMessage;
        CqNameToOp clientCq = cumi.getClientCq(this.proxyID);
        if (clientCq != null && !clientCq.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("CCP clientCq size before processing auth {}", clientCq.size());
            }
            String[] regionNameHolder = new String[1];
            OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
            if (opctxt == null) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
                return false;
            }
            String[] cqNames = clientCq.getNames();
            if (logger.isDebugEnabled()) {
                logger.debug("CCP clientCq names array size {}", cqNames.length);
            }
            for (int i = 0; i < cqNames.length; i++) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("CCP clientCq name {}", cqNames[i]);
                    }
                    boolean isAuthorized = false;
                    if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
                        // need to take lock as we may be reinitializing proxy cache
                        synchronized (this.clientUserAuthsLock) {
                            AuthorizeRequestPP postAuthCallback = this.clientUserAuths.getUserAuthAttributes(cqNames[i]).getPostAuthzRequest();
                            if (logger.isDebugEnabled() && postAuthCallback == null) {
                                logger.debug("CCP clientCq post callback is null");
                            }
                            if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
                                isAuthorized = true;
                            }
                        }
                    } else {
                        UserAuthAttributes userAuthAttributes = this.clientUserAuths.getUserAuthAttributes(cqNames[i]);
                        AuthorizeRequestPP postAuthCallback = userAuthAttributes.getPostAuthzRequest();
                        if (postAuthCallback == null && logger.isDebugEnabled()) {
                            logger.debug("CCP clientCq post callback is null");
                        }
                        if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
                            isAuthorized = true;
                        }
                    }
                    if (!isAuthorized) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_CQ_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
                        clientCq.delete(cqNames[i]);
                    }
                } catch (Exception ex) {
                // ignore...
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("CCP clientCq size after processing auth {}", clientCq.size());
                }
            }
            // again need to check as there may be no CQ available
            if (!clientMessage.hasCqs(this.proxyID)) {
                this._statistics.incMessagesNotQueuedNotInterested();
                if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
                    logger.debug("{}: Not adding message to queue. It is not interested in this region and key: {}", clientMessage);
                }
                return false;
            }
        }
    } else if (this.postAuthzCallback != null) {
        String[] regionNameHolder = new String[1];
        boolean isAuthorize = false;
        OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
        if (opctxt == null) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
            return false;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("{}: Invoking authorizeOperation for message: {}", this, clientMessage);
        }
        if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
            synchronized (this.clientUserAuthsLock) {
                isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
            }
        } else {
            isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
        }
        if (!isAuthorize) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
            return false;
        }
    }
    return true;
}
Also used : RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) OperationContext(org.apache.geode.cache.operations.OperationContext) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) AuthorizeRequestPP(org.apache.geode.internal.security.AuthorizeRequestPP) RegionExistsException(org.apache.geode.cache.RegionExistsException) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) SocketException(java.net.SocketException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Aggregations

DestroyOperationContext (org.apache.geode.cache.operations.DestroyOperationContext)2 InvalidateOperationContext (org.apache.geode.cache.operations.InvalidateOperationContext)2 OperationContext (org.apache.geode.cache.operations.OperationContext)2 PutOperationContext (org.apache.geode.cache.operations.PutOperationContext)2 RegionClearOperationContext (org.apache.geode.cache.operations.RegionClearOperationContext)2 RegionCreateOperationContext (org.apache.geode.cache.operations.RegionCreateOperationContext)2 RegionDestroyOperationContext (org.apache.geode.cache.operations.RegionDestroyOperationContext)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 CancelException (org.apache.geode.CancelException)1 CacheException (org.apache.geode.cache.CacheException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 CqException (org.apache.geode.cache.query.CqException)1 CqNameToOp (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp)1 AuthorizeRequestPP (org.apache.geode.internal.security.AuthorizeRequestPP)1