Search in sources :

Example 1 with ObjectPartList651

use of org.apache.geode.internal.cache.tier.sockets.ObjectPartList651 in project geode by apache.

the class GetAll651 method fillAndSendGetAllResponseChunks.

private void fillAndSendGetAllResponseChunks(Region region, String regionName, Object[] keys, ServerConnection servConn) throws IOException {
    // Interpret null keys object as a request to get all key,value entry pairs
    // of the region; otherwise iterate each key and perform the get behavior.
    Iterator allKeysIter;
    int numKeys;
    if (keys != null) {
        allKeysIter = null;
        numKeys = keys.length;
    } else {
        Set allKeys = region.keySet();
        allKeysIter = allKeys.iterator();
        numKeys = allKeys.size();
    }
    ObjectPartList651 values = getObjectPartsList(keys == null);
    AuthorizeRequest authzRequest = servConn.getAuthzRequest();
    AuthorizeRequestPP postAuthzRequest = servConn.getPostAuthzRequest();
    Request request = (Request) Request.getCommand();
    Object[] valueAndIsObject = new Object[3];
    final boolean isDebugEnabled = logger.isDebugEnabled();
    for (int i = 0; i < numKeys; i++) {
        // Send the intermediate chunk if necessary
        if (values.size() == MAXIMUM_CHUNK_SIZE) {
            // Send the chunk and clear the list
            sendGetAllResponseChunk(region, values, false, servConn);
            values.clear();
        }
        Object key;
        boolean keyNotPresent = false;
        if (keys != null) {
            key = keys[i];
        } else {
            key = allKeysIter.next();
        }
        if (isDebugEnabled) {
            logger.debug("{}: Getting value for key={}", servConn.getName(), key);
        }
        // Determine if the user authorized to get this key
        GetOperationContext getContext = null;
        if (authzRequest != null) {
            try {
                getContext = authzRequest.getAuthorize(regionName, key, null);
                if (isDebugEnabled) {
                    logger.debug("{}: Passed GET pre-authorization for key={}", servConn.getName(), key);
                }
            } catch (NotAuthorizedException ex) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { servConn.getName(), key }), ex);
                values.addExceptionPart(key, ex);
                continue;
            }
        }
        try {
            this.securityService.authorizeRegionRead(regionName, key.toString());
        } catch (NotAuthorizedException ex) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { servConn.getName(), key }), ex);
            values.addExceptionPart(key, ex);
            continue;
        }
        // Get the value and update the statistics. Do not deserialize
        // the value if it is a byte[].
        // Getting a value in serialized form is pretty nasty. I split this out
        // so the logic can be re-used by the CacheClientProxy.
        request.getValueAndIsObject(region, key, null, servConn, valueAndIsObject);
        Object value = valueAndIsObject[0];
        boolean isObject = ((Boolean) valueAndIsObject[1]).booleanValue();
        keyNotPresent = ((Boolean) valueAndIsObject[2]).booleanValue();
        ;
        if (isDebugEnabled) {
            logger.debug("{}: Retrieved value for key={}: {}", servConn.getName(), key, value);
        }
        if (postAuthzRequest != null) {
            try {
                getContext = postAuthzRequest.getAuthorize(regionName, key, value, isObject, getContext);
                byte[] serializedValue = getContext.getSerializedValue();
                if (serializedValue == null) {
                    value = getContext.getObject();
                } else {
                    value = serializedValue;
                }
                isObject = getContext.isObject();
                if (isDebugEnabled) {
                    logger.debug("{}: Passed GET post-authorization for key={}: {}", servConn.getName(), key, value);
                }
            } catch (NotAuthorizedException ex) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { servConn.getName(), key }), ex);
                values.addExceptionPart(key, ex);
                continue;
            }
        }
        value = this.securityService.postProcess(regionName, key, value, isObject);
        if (isDebugEnabled) {
            logger.debug("{}: Returning value for key={}: {}", servConn.getName(), key, value);
        }
        // Add the value to the list of values
        if (keyNotPresent) {
            if (logger.isDebugEnabled()) {
                logger.debug("{}: key={} is not present on server.", servConn.getName(), key);
            }
            values.addObjectPartForAbsentKey(key, value);
        } else {
            values.addObjectPart(key, value, isObject, null);
        }
    }
    // Send the last chunk even if the list is of zero size.
    sendGetAllResponseChunk(region, values, true, servConn);
    servConn.setAsTrue(RESPONDED);
}
Also used : Set(java.util.Set) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) ObjectPartList651(org.apache.geode.internal.cache.tier.sockets.ObjectPartList651) AuthorizeRequestPP(org.apache.geode.internal.security.AuthorizeRequestPP) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) GetOperationContext(org.apache.geode.cache.operations.GetOperationContext) Iterator(java.util.Iterator)

Aggregations

Iterator (java.util.Iterator)1 Set (java.util.Set)1 GetOperationContext (org.apache.geode.cache.operations.GetOperationContext)1 ObjectPartList651 (org.apache.geode.internal.cache.tier.sockets.ObjectPartList651)1 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)1 AuthorizeRequestPP (org.apache.geode.internal.security.AuthorizeRequestPP)1 NotAuthorizedException (org.apache.geode.security.NotAuthorizedException)1