Search in sources :

Example 31 with AuthorizeRequest

use of org.apache.geode.internal.security.AuthorizeRequest in project geode by apache.

the class RegisterInterest method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    InterestResultPolicy policy = null;
    // Retrieve the interest type
    int interestType = clientMessage.getPart(1).getInt();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(3);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Retrieve the key
    keyPart = clientMessage.getPart(4);
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > 5) {
        try {
            Part notifyPart = clientMessage.getPart(5);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    // Process the register interest request
    if (key == null || regionName == null) {
        StringId message = null;
        if (key == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_KEY_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        if (regionName == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        logger.warn("{}: {}", serverConnection.getName(), message.toLocalizedString());
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, message.toLocalizedString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // input key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterest_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // Register interest
    try {
        if (interestType == InterestType.REGULAR_EXPRESSION) {
            this.securityService.authorizeRegionRead(regionName);
        } else {
            this.securityService.authorizeRegionRead(regionName, key.toString());
        }
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestAuthorize(regionName, key, interestType, policy);
                key = registerContext.getKey();
            }
        }
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, key, serverConnection.getProxyID(), interestType, isDurable, sendUpdatesAsInvalidates, false, 0, true);
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // System.out.println("Received register interest for " + regionName);
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    CacheClientProxy ccp = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID());
    if (ccp == null) {
        // fix for 37593
        IOException ioex = new IOException(LocalizedStrings.RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL.toLocalizedString());
        writeChunkedException(clientMessage, ioex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isPrimary = ccp.isPrimary();
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else // !isPrimary
    {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, key, interestType, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection, chunkedResponseMsg);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for region {} key {}", serverConnection.getName(), regionName, key);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) IOException(java.io.IOException) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) Part(org.apache.geode.internal.cache.tier.sockets.Part) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 32 with AuthorizeRequest

use of org.apache.geode.internal.security.AuthorizeRequest in project geode by apache.

the class RegisterInterest61 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    InterestResultPolicy policy = null;
    // Retrieve the interest type
    int interestType = clientMessage.getPart(1).getInt();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(3);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // region data policy
    byte[] regionDataPolicyPartBytes;
    boolean serializeValues = false;
    try {
        Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
        regionDataPolicyPartBytes = (byte[]) regionDataPolicyPart.getObject();
        if (serverConnection.getClientVersion().compareTo(Version.GFE_80) >= 0) {
            // The second byte here is serializeValues
            serializeValues = regionDataPolicyPartBytes[1] == (byte) 0x01;
        }
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Retrieve the key
    keyPart = clientMessage.getPart(4);
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > 5) {
        try {
            Part notifyPart = clientMessage.getPart(5);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest 61 request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    if (VMOTION_DURING_REGISTER_INTEREST_FLAG) {
        VMotionObserver vmo = VMotionObserverHolder.getInstance();
        vmo.vMotionBeforeRegisterInterest();
    }
    // Process the register interest request
    if (key == null || regionName == null) {
        StringId message = null;
        if (key == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_KEY_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        if (regionName == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        logger.warn("{}: {}", serverConnection.getName(), message.toLocalizedString());
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, message.toLocalizedString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // input key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterest_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // Register interest
    try {
        if (interestType == InterestType.REGULAR_EXPRESSION) {
            this.securityService.authorizeRegionRead(regionName);
        } else {
            this.securityService.authorizeRegionRead(regionName, key.toString());
        }
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestAuthorize(regionName, key, interestType, policy);
                key = registerContext.getKey();
            }
        }
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, key, serverConnection.getProxyID(), interestType, isDurable, sendUpdatesAsInvalidates, true, regionDataPolicyPartBytes[0], true);
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // System.out.println("Received register interest for " + regionName);
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    CacheClientProxy ccp = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID());
    if (ccp == null) {
        // fix for 37593
        IOException ioex = new IOException(LocalizedStrings.RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL.toLocalizedString());
        writeChunkedException(clientMessage, ioex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isPrimary = ccp.isPrimary();
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else // !isPrimary
    {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, key, interestType, serializeValues, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection, chunkedResponseMsg);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for region {} key {}", serverConnection.getName(), regionName, key);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) VMotionObserver(org.apache.geode.internal.cache.vmotion.VMotionObserver) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) Part(org.apache.geode.internal.cache.tier.sockets.Part) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 33 with AuthorizeRequest

use of org.apache.geode.internal.security.AuthorizeRequest in project geode by apache.

the class Put65 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long p_start) throws IOException, InterruptedException {
    long start = p_start;
    Part regionNamePart = null, keyPart = null, valuePart = null, callbackArgPart = null;
    String regionName = null;
    Object callbackArg = null, key = null;
    Part eventPart = null;
    StringBuffer errMessage = new StringBuffer();
    boolean isDelta = false;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    // requiresResponse = true;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadPutRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    int idx = 0;
    regionNamePart = clientMessage.getPart(idx++);
    Operation operation;
    try {
        operation = (Operation) clientMessage.getPart(idx++).getObject();
        if (operation == null) {
            // native clients send a null since the op is java-serialized
            operation = Operation.UPDATE;
        }
    } catch (ClassNotFoundException e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    int flags = clientMessage.getPart(idx++).getInt();
    boolean requireOldValue = ((flags & 0x01) == 0x01);
    boolean haveExpectedOldValue = ((flags & 0x02) == 0x02);
    Object expectedOldValue = null;
    if (haveExpectedOldValue) {
        try {
            expectedOldValue = clientMessage.getPart(idx++).getObject();
        } catch (ClassNotFoundException e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    keyPart = clientMessage.getPart(idx++);
    try {
        isDelta = ((Boolean) clientMessage.getPart(idx).getObject()).booleanValue();
        idx += 1;
    } catch (Exception e) {
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        // CachePerfStats not available here.
        return;
    }
    valuePart = clientMessage.getPart(idx++);
    eventPart = clientMessage.getPart(idx++);
    if (clientMessage.getNumberOfParts() > idx) {
        callbackArgPart = clientMessage.getPart(idx++);
        try {
            callbackArg = callbackArgPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("{}: Received {}put request ({} bytes) from {} for region {} key {} txId {} posdup: {}", serverConnection.getName(), (isDelta ? " delta " : " "), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key, clientMessage.getTransactionId(), clientMessage.isRetry());
    }
    // Process the put request
    if (key == null || regionName == null) {
        if (key == null) {
            String putMsg = " The input key for the put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        if (regionName == null) {
            String putMsg = " The input region name for the put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        String reason = " was not found during put request";
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (valuePart.isNull() && operation != Operation.PUT_IF_ABSENT && region.containsKey(key)) {
        // Invalid to 'put' a null value in an existing key
        String putMsg = " Attempted to put a null value for existing key " + key;
        if (isDebugEnabled) {
            logger.debug("{}:{}", serverConnection.getName(), putMsg);
        }
        errMessage.append(putMsg);
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart.getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventIDHolder clientEvent = new EventIDHolder(new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId));
    Breadcrumbs.setEventId(clientEvent.getEventId());
    // msg.isRetry might be set by v7.0 and later clients
    if (clientMessage.isRetry()) {
        // if (logger.isDebugEnabled()) {
        // logger.debug("DEBUG: encountered isRetry in Put65");
        // }
        clientEvent.setPossibleDuplicate(true);
        if (region.getAttributes().getConcurrencyChecksEnabled()) {
            // recover the version tag from other servers
            clientEvent.setRegion(region);
            if (!recoverVersionTagForRetriedOperation(clientEvent)) {
                // no-one has seen this event
                clientEvent.setPossibleDuplicate(false);
            }
        }
    }
    boolean result = false;
    boolean sendOldValue = false;
    boolean oldValueIsObject = true;
    Object oldValue = null;
    try {
        Object value = null;
        if (!isDelta) {
            value = valuePart.getSerializedForm();
        }
        boolean isObject = valuePart.isObject();
        boolean isMetaRegion = region.isUsedForMetaRegion();
        clientMessage.setMetaRegion(isMetaRegion);
        this.securityService.authorizeRegionWrite(regionName, key.toString());
        AuthorizeRequest authzRequest = null;
        if (!isMetaRegion) {
            authzRequest = serverConnection.getAuthzRequest();
        }
        if (authzRequest != null) {
            if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                authzRequest.createRegionAuthorize((String) key);
            } else // Allow PUT operations on meta regions (bug #38961)
            {
                PutOperationContext putContext = authzRequest.putAuthorize(regionName, key, value, isObject, callbackArg);
                value = putContext.getValue();
                isObject = putContext.isObject();
                callbackArg = putContext.getCallbackArg();
            }
        }
        if (isDebugEnabled) {
            logger.debug("processing put65 with operation={}", operation);
        }
        // to be publicly accessible.
        if (operation == Operation.PUT_IF_ABSENT) {
            // try {
            if (clientMessage.isRetry() && clientEvent.getVersionTag() != null) {
                // version tag
                if (isDebugEnabled) {
                    logger.debug("putIfAbsent operation was successful last time with version {}", clientEvent.getVersionTag());
                }
                // invoke basicBridgePutIfAbsent anyway to ensure that the event is distributed to all
                // servers - bug #51664
                region.basicBridgePutIfAbsent(key, value, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent);
                oldValue = null;
            } else {
                oldValue = region.basicBridgePutIfAbsent(key, value, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent);
            }
            sendOldValue = true;
            oldValueIsObject = true;
            Version clientVersion = serverConnection.getClientVersion();
            if (oldValue instanceof CachedDeserializable) {
                oldValue = ((CachedDeserializable) oldValue).getSerializedValue();
            } else if (oldValue instanceof byte[]) {
                oldValueIsObject = false;
            } else if ((oldValue instanceof Token) && clientVersion.compareTo(Version.GFE_651) <= 0) {
                // older clients don't know that Token is now a DSFID class, so we
                // put the token in a serialized form they can consume
                HeapDataOutputStream str = new HeapDataOutputStream(Version.CURRENT);
                DataOutput dstr = new DataOutputStream(str);
                InternalDataSerializer.writeSerializableObject(oldValue, dstr);
                oldValue = str.toByteArray();
            }
            result = true;
        // } catch (Exception e) {
        // writeException(msg, e, false, servConn);
        // servConn.setAsTrue(RESPONDED);
        // return;
        // }
        } else if (operation == Operation.REPLACE) {
            // try {
            if (requireOldValue) {
                // <V> replace(<K>, <V>)
                if (clientMessage.isRetry() && clientEvent.isConcurrencyConflict() && clientEvent.getVersionTag() != null) {
                    if (isDebugEnabled) {
                        logger.debug("replace(k,v) operation was successful last time with version {}", clientEvent.getVersionTag());
                    }
                }
                oldValue = region.basicBridgeReplace(key, value, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent);
                sendOldValue = !clientEvent.isConcurrencyConflict();
                oldValueIsObject = true;
                Version clientVersion = serverConnection.getClientVersion();
                if (oldValue instanceof CachedDeserializable) {
                    oldValue = ((CachedDeserializable) oldValue).getSerializedValue();
                } else if (oldValue instanceof byte[]) {
                    oldValueIsObject = false;
                } else if ((oldValue instanceof Token) && clientVersion.compareTo(Version.GFE_651) <= 0) {
                    // older clients don't know that Token is now a DSFID class, so we
                    // put the token in a serialized form they can consume
                    HeapDataOutputStream str = new HeapDataOutputStream(Version.CURRENT);
                    DataOutput dstr = new DataOutputStream(str);
                    InternalDataSerializer.writeSerializableObject(oldValue, dstr);
                    oldValue = str.toByteArray();
                }
                if (isDebugEnabled) {
                    logger.debug("returning {} from replace(K,V)", oldValue);
                }
                result = true;
            } else {
                // boolean replace(<K>, <V>, <V>) {
                boolean didPut;
                didPut = region.basicBridgeReplace(key, expectedOldValue, value, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent);
                if (clientMessage.isRetry() && clientEvent.getVersionTag() != null) {
                    if (isDebugEnabled) {
                        logger.debug("replace(k,v,v) operation was successful last time with version {}", clientEvent.getVersionTag());
                    }
                    didPut = true;
                }
                sendOldValue = true;
                oldValueIsObject = true;
                oldValue = didPut ? Boolean.TRUE : Boolean.FALSE;
                if (isDebugEnabled) {
                    logger.debug("returning {} from replace(K,V,V)", oldValue);
                }
                result = true;
            }
        // } catch (Exception e) {
        // writeException(msg, e, false, servConn);
        // servConn.setAsTrue(RESPONDED);
        // return;
        // }
        } else if (value == null && !isDelta) {
            // Create the null entry. Since the value is null, the value of the
            // isObject
            // the true after null doesn't matter and is not used.
            result = region.basicBridgeCreate(key, null, true, callbackArg, serverConnection.getProxyID(), true, clientEvent, false);
            if (clientMessage.isRetry() && clientEvent.isConcurrencyConflict() && clientEvent.getVersionTag() != null) {
                result = true;
                if (isDebugEnabled) {
                    logger.debug("create(k,null) operation was successful last time with version {}", clientEvent.getVersionTag());
                }
            }
        } else {
            // Put the entry
            byte[] delta = null;
            if (isDelta) {
                delta = valuePart.getSerializedForm();
            }
            TXManagerImpl txMgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
            // bug 43068 - use create() if in a transaction and op is CREATE
            if (txMgr.getTXState() != null && operation.isCreate()) {
                result = region.basicBridgeCreate(key, (byte[]) value, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent, true);
            } else {
                result = region.basicBridgePut(key, value, delta, isObject, callbackArg, serverConnection.getProxyID(), true, clientEvent);
            }
            if (clientMessage.isRetry() && clientEvent.isConcurrencyConflict() && clientEvent.getVersionTag() != null) {
                if (isDebugEnabled) {
                    logger.debug("put(k,v) operation was successful last time with version {}", clientEvent.getVersionTag());
                }
                result = true;
            }
        }
        if (result) {
            serverConnection.setModificationInfo(true, regionName, key);
        } else {
            String message = serverConnection.getName() + ": Failed to put entry for region " + regionName + " key " + key + " value " + valuePart;
            if (isDebugEnabled) {
                logger.debug(message);
            }
            throw new Exception(message);
        }
    } catch (RegionDestroyedException rde) {
        writeException(clientMessage, rde, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (ResourceException re) {
        writeException(clientMessage, re, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (InvalidDeltaException ide) {
        logger.info(LocalizedMessage.create(LocalizedStrings.UpdateOperation_ERROR_APPLYING_DELTA_FOR_KEY_0_OF_REGION_1, new Object[] { key, regionName }));
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, ide, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        region.getCachePerfStats().incDeltaFullValuesRequested();
        return;
    } catch (Exception ce) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ce);
        // If an exception occurs during the put, preserve the connection
        writeException(clientMessage, ce, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        if (ce instanceof GemFireSecurityException) {
            // logged by the security logger
            if (isDebugEnabled) {
                logger.debug("{}: Unexpected Security exception", serverConnection.getName(), ce);
            }
        } else if (isDebugEnabled) {
            logger.debug("{}: Unexpected Exception", serverConnection.getName(), ce);
        }
        return;
    } finally {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessPutTime(start - oldStart);
    }
    // Increment statistics and write the reply
    if (region instanceof PartitionedRegion) {
        PartitionedRegion pr = (PartitionedRegion) region;
        if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
            writeReplyWithRefreshMetadata(clientMessage, serverConnection, pr, sendOldValue, oldValueIsObject, oldValue, pr.getNetworkHopType(), clientEvent.getVersionTag());
            pr.clearNetworkHopData();
        } else {
            writeReply(clientMessage, serverConnection, sendOldValue, oldValueIsObject, oldValue, clientEvent.getVersionTag());
        }
    } else {
        writeReply(clientMessage, serverConnection, sendOldValue, oldValueIsObject, oldValue, clientEvent.getVersionTag());
    }
    serverConnection.setAsTrue(RESPONDED);
    if (isDebugEnabled) {
        logger.debug("{}: Sent put response back to {} for region {} key {} value {}", serverConnection.getName(), serverConnection.getSocketString(), regionName, key, valuePart);
    }
    stats.incWritePutResponseTime(DistributionStats.getStatTime() - start);
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) DataOutput(java.io.DataOutput) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) DataOutputStream(java.io.DataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Token(org.apache.geode.internal.cache.Token) Operation(org.apache.geode.cache.Operation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) Version(org.apache.geode.internal.Version) ResourceException(org.apache.geode.cache.ResourceException) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) ByteBuffer(java.nio.ByteBuffer) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) ResourceException(org.apache.geode.cache.ResourceException) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EventID(org.apache.geode.internal.cache.EventID) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext)

Example 34 with AuthorizeRequest

use of org.apache.geode.internal.security.AuthorizeRequest in project geode by apache.

the class RegisterInterestList method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null, numberOfKeysPart = null;
    String regionName = null;
    Object key = null;
    InterestResultPolicy policy;
    List keys = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    int numberOfKeys = 0, partNumber = 0;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(1).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(2);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    numberOfKeysPart = clientMessage.getPart(3);
    numberOfKeys = numberOfKeysPart.getInt();
    partNumber = 4;
    keys = new ArrayList();
    for (int i = 0; i < numberOfKeys; i++) {
        keyPart = clientMessage.getPart(partNumber + i);
        try {
            key = keyPart.getStringOrObject();
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        keys.add(key);
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > (numberOfKeys + partNumber)) {
        try {
            Part notifyPart = clientMessage.getPart(numberOfKeys + partNumber);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest request ({} bytes) from {} for the following {} keys in region {}: {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), numberOfKeys, regionName, keys);
    }
    // Process the register interest request
    if (keys.isEmpty() || regionName == null) {
        StringId errMessage = null;
        if (keys.isEmpty() && regionName == null) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_IS_EMPTY_AND_THE_INPUT_REGION_NAME_IS_NULL_FOR_THE_REGISTER_INTEREST_REQUEST;
        } else if (keys.isEmpty()) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_FOR_THE_REGISTER_INTEREST_REQUEST_IS_EMPTY;
        } else if (regionName == null) {
            errMessage = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        String s = errMessage.toLocalizedString();
        logger.warn("{}: {}", serverConnection.getName(), s);
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, s, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterestList_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_LIST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // else { // region not null
    try {
        this.securityService.authorizeRegionRead(regionName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestListAuthorize(regionName, keys, policy);
                keys = (List) registerContext.getKey();
            }
        }
        // Register interest
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, keys, serverConnection.getProxyID(), isDurable, sendUpdatesAsInvalidates, false, 0, true);
    } catch (Exception ex) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ex);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, ex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    boolean isPrimary = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID()).isPrimary();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, keys, InterestType.KEY, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            // If an interrupted exception is thrown , rethrow it
            checkForInterrupt(serverConnection, e);
            // otherwise send the exception back to client
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for the following {} keys in region {}: {}", serverConnection.getName(), numberOfKeys, regionName, keys);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
// } // region not null
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with AuthorizeRequest

use of org.apache.geode.internal.security.AuthorizeRequest in project geode by apache.

the class RegisterInterestList66 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    // numberOfKeysPart = null;
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    InterestResultPolicy policy;
    List keys = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    int numberOfKeys = 0, partNumber = 0;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(1).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(2);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // region data policy
    byte[] regionDataPolicyPartBytes;
    boolean serializeValues = false;
    try {
        Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
        regionDataPolicyPartBytes = (byte[]) regionDataPolicyPart.getObject();
        if (serverConnection.getClientVersion().compareTo(Version.GFE_80) >= 0) {
            // The second byte here is serializeValues
            serializeValues = regionDataPolicyPartBytes[1] == (byte) 0x01;
        }
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    partNumber = 3;
    Part list = clientMessage.getPart(partNumber);
    try {
        keys = (List) list.getObject();
        numberOfKeys = keys.size();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    try {
        Part notifyPart = clientMessage.getPart(partNumber + 1);
        byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
        sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest 66 request ({} bytes) from {} for the following {} keys in region {}: {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), numberOfKeys, regionName, keys);
    }
    // Process the register interest request
    if (keys.isEmpty() || regionName == null) {
        StringId errMessage = null;
        if (keys.isEmpty() && regionName == null) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_IS_EMPTY_AND_THE_INPUT_REGION_NAME_IS_NULL_FOR_THE_REGISTER_INTEREST_REQUEST;
        } else if (keys.isEmpty()) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_FOR_THE_REGISTER_INTEREST_REQUEST_IS_EMPTY;
        } else if (regionName == null) {
            errMessage = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        String s = errMessage.toLocalizedString();
        logger.warn("{}: {}", serverConnection.getName(), s);
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, s, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    }
    // key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterestList_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_LIST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // else { // region not null
    try {
        this.securityService.authorizeRegionRead(regionName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestListAuthorize(regionName, keys, policy);
                keys = (List) registerContext.getKey();
            }
        }
        // Register interest
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, keys, serverConnection.getProxyID(), isDurable, sendUpdatesAsInvalidates, true, regionDataPolicyPartBytes[0], true);
    } catch (Exception ex) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ex);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, ex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    boolean isPrimary = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID()).isPrimary();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, keys, InterestType.KEY, serializeValues, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            // If an interrupted exception is thrown , rethrow it
            checkForInterrupt(serverConnection, e);
            // otherwise send the exception back to client
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for the following {} keys in region {}: {}", serverConnection.getName(), numberOfKeys, regionName, keys);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
// } // region not null
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) List(java.util.List)

Aggregations

AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)48 IOException (java.io.IOException)40 Part (org.apache.geode.internal.cache.tier.sockets.Part)33 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 EventID (org.apache.geode.internal.cache.EventID)13 ByteBuffer (java.nio.ByteBuffer)12 ChunkedMessage (org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)12 NotAuthorizedException (org.apache.geode.security.NotAuthorizedException)12 Set (java.util.Set)11 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)11 StringId (org.apache.geode.i18n.StringId)11 Region (org.apache.geode.cache.Region)8 Function (org.apache.geode.cache.execute.Function)8 FunctionException (org.apache.geode.cache.execute.FunctionException)8 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)8 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)8 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)8