Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D5FA1200B38 for ; Fri, 8 Jul 2016 17:51:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D4F7E160A36; Fri, 8 Jul 2016 15:51:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 94CF4160A8A for ; Fri, 8 Jul 2016 17:51:29 +0200 (CEST) Received: (qmail 56835 invoked by uid 500); 8 Jul 2016 15:51:28 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 56741 invoked by uid 99); 8 Jul 2016 15:51:28 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jul 2016 15:51:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 37E76185806 for ; Fri, 8 Jul 2016 15:51:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id YdESUioNjGTj for ; Fri, 8 Jul 2016 15:51:26 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id B08295FDA0 for ; Fri, 8 Jul 2016 15:51:23 +0000 (UTC) Received: (qmail 53547 invoked by uid 99); 8 Jul 2016 15:51:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jul 2016 15:51:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A0262E2EE7; Fri, 8 Jul 2016 15:51:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jinmeiliao@apache.org To: commits@geode.incubator.apache.org Date: Fri, 08 Jul 2016 15:51:44 -0000 Message-Id: In-Reply-To: <0d0976df1fac43289eca21d332ddfa0a@git.apache.org> References: <0d0976df1fac43289eca21d332ddfa0a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [24/50] [abbrv] incubator-geode git commit: Added Size test and refactored Size archived-at: Fri, 08 Jul 2016 15:51:31 -0000 Added Size test and refactored Size Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/bad0a92d Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/bad0a92d Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/bad0a92d Branch: refs/heads/develop Commit: bad0a92d3868a39d9e1d2f01eff0c59f13c736c3 Parents: b782b6b Author: Kevin J. Duling Authored: Wed Jun 29 11:04:33 2016 -0700 Committer: Kevin J. Duling Committed: Wed Jun 29 11:04:33 2016 -0700 ---------------------------------------------------------------------- .../cache/tier/sockets/command/Size.java | 141 ++++++++----------- ...IntegratedClientSizeAuthDistributedTest.java | 57 ++++++++ 2 files changed, 115 insertions(+), 83 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bad0a92d/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java index 64aee67..8b11d3d 100644 --- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java @@ -15,20 +15,15 @@ * limitations under the License. */ /** - * + * */ package com.gemstone.gemfire.internal.cache.tier.sockets.command; import java.io.IOException; -import java.nio.ByteBuffer; -import com.gemstone.gemfire.cache.EntryNotFoundException; import com.gemstone.gemfire.cache.RegionDestroyedException; import com.gemstone.gemfire.distributed.internal.DistributionStats; -import com.gemstone.gemfire.i18n.LogWriterI18n; -import com.gemstone.gemfire.internal.cache.EventID; import com.gemstone.gemfire.internal.cache.LocalRegion; -import com.gemstone.gemfire.internal.cache.PartitionedRegion; import com.gemstone.gemfire.internal.cache.tier.CachedRegionHelper; import com.gemstone.gemfire.internal.cache.tier.Command; import com.gemstone.gemfire.internal.cache.tier.MessageType; @@ -39,6 +34,7 @@ import com.gemstone.gemfire.internal.cache.tier.sockets.Part; import com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection; import com.gemstone.gemfire.internal.i18n.LocalizedStrings; import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage; +import com.gemstone.gemfire.internal.security.GeodeSecurityUtil; import com.gemstone.gemfire.security.GemFireSecurityException; @@ -46,56 +42,60 @@ public class Size extends BaseCommand { private final static Size singleton = new Size(); + private Size() { + } + public static Command getCommand() { return singleton; } - private Size() { + private static void writeSizeResponse(Integer sizeCount, Message origMsg, ServerConnection servConn) + throws IOException { + Message responseMsg = servConn.getResponseMessage(); + responseMsg.setMessageType(MessageType.RESPONSE); + responseMsg.setNumberOfParts(1); + responseMsg.setTransactionId(origMsg.getTransactionId()); + responseMsg.addObjPart(sizeCount); + responseMsg.send(servConn); } @Override - public void cmdExecute(Message msg, ServerConnection servConn, long start) - throws IOException, InterruptedException { - Part regionNamePart = null, keyPart = null, callbackArgPart = null; - String regionName = null; - Part eventPart = null; - StringBuffer errMessage = new StringBuffer(); + public void cmdExecute(Message msg, ServerConnection servConn, long start) throws IOException, InterruptedException { + StringBuilder errMessage = new StringBuilder(); CachedRegionHelper crHelper = servConn.getCachedRegionHelper(); CacheServerStats stats = servConn.getCacheServerStats(); servConn.setAsTrue(REQUIRES_RESPONSE); - { - long oldStart = start; - start = DistributionStats.getStatTime(); - stats.incReadSizeRequestTime(start - oldStart); - } + long oldStart = start; + start = DistributionStats.getStatTime(); + stats.incReadSizeRequestTime(start - oldStart); // Retrieve the data from the message parts - regionNamePart = msg.getPart(0); - regionName = regionNamePart.getString(); - + Part regionNamePart = msg.getPart(0); + String regionName = regionNamePart.getString(); + if (regionName == null) { logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL, "size")); - errMessage - .append(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("size")); - writeErrorResponse(msg, MessageType.SIZE_ERROR, errMessage - .toString(), servConn); + errMessage.append(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("size")); + writeErrorResponse(msg, MessageType.SIZE_ERROR, errMessage.toString(), servConn); servConn.setAsTrue(RESPONDED); + return; + } + + LocalRegion region = (LocalRegion) crHelper.getRegion(regionName); + if (region == null) { + String reason = LocalizedStrings.BaseCommand__0_WAS_NOT_FOUND_DURING_1_REQUEST.toLocalizedString(regionName, "size"); + writeRegionDestroyedEx(msg, regionName, reason, servConn); + servConn.setAsTrue(RESPONDED); + return; } - else { - LocalRegion region = (LocalRegion)crHelper.getRegion(regionName); - if (region == null) { - String reason = LocalizedStrings.BaseCommand__0_WAS_NOT_FOUND_DURING_1_REQUEST.toLocalizedString(regionName,"size"); - writeRegionDestroyedEx(msg, regionName, reason, servConn); - servConn.setAsTrue(RESPONDED); - } - else { - // Size the entry - try { + GeodeSecurityUtil.authorizeRegionRead(regionName); + // Size the entry + try { /* - * + * * txtodo: doesn't seem like there is any notion of authzSize - * + * AuthorizeRequest authzRequest = servConn.getAuthzRequest(); if (authzRequest != null) { // TODO SW: This is to handle DynamicRegionFactory destroy @@ -113,55 +113,30 @@ public class Size extends BaseCommand { } } */ - writeSizeResponse(region.size(), msg, servConn); - servConn.setAsTrue(RESPONDED); - return; - } - catch (RegionDestroyedException rde) { - writeException(msg, rde, false, servConn); - servConn.setAsTrue(RESPONDED); - return; - } - catch (Exception e) { - // If an interrupted exception is thrown , rethrow it - checkForInterrupt(servConn, e); + writeSizeResponse(region.size(), msg, servConn); + } catch (RegionDestroyedException rde) { + writeException(msg, rde, false, servConn); + } catch (Exception e) { + // If an interrupted exception is thrown , rethrow it + checkForInterrupt(servConn, e); - // If an exception occurs during the destroy, preserve the connection - writeException(msg, e, false, servConn); - servConn.setAsTrue(RESPONDED); - if (e instanceof GemFireSecurityException) { - // Fine logging for security exceptions since these are already - // logged by the security logger - if (logger.isDebugEnabled()) - logger.debug("{}: Unexpected Security exception", servConn.getName(), e); - } - else { - logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand_0_UNEXPECTED_EXCEPTION, servConn.getName()), e); - } - servConn.setAsTrue(RESPONDED); - return; - } finally { - if (logger.isDebugEnabled()) { - logger.debug("{}: Sent size response for region {}", servConn.getName(), regionName); - } - stats.incWriteSizeResponseTime(DistributionStats.getStatTime() - - start); + // If an exception occurs during the destroy, preserve the connection + writeException(msg, e, false, servConn); + if (e instanceof GemFireSecurityException) { + // Fine logging for security exceptions since these are already + // logged by the security logger + if (logger.isDebugEnabled()) { + logger.debug("{}: Unexpected Security exception", servConn.getName(), e); } + } else { + logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand_0_UNEXPECTED_EXCEPTION, servConn.getName()), e); + } + } finally { + if (logger.isDebugEnabled()) { + logger.debug("{}: Sent size response for region {}", servConn.getName(), regionName); } + servConn.setAsTrue(RESPONDED); + stats.incWriteSizeResponseTime(DistributionStats.getStatTime() - start); } - - - } - - private static void writeSizeResponse(Integer sizeCount, Message origMsg, - ServerConnection servConn) throws IOException { - Message responseMsg = servConn.getResponseMessage(); - responseMsg.setMessageType(MessageType.RESPONSE); - responseMsg.setNumberOfParts(1); - responseMsg.setTransactionId(origMsg.getTransactionId()); - responseMsg.addObjPart(sizeCount); - responseMsg.send(servConn); - } - } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bad0a92d/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java new file mode 100644 index 0000000..96ea297 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.security; + + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache.client.internal.InternalPool; +import com.gemstone.gemfire.cache.client.internal.SizeOp; +import com.gemstone.gemfire.test.dunit.AsyncInvocation; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; + +@Category(DistributedTest.class) +public class IntegratedClientSizeAuthDistributedTest extends AbstractIntegratedClientAuthDistributedTest { + + @Test + public void testSize() throws InterruptedException { + + AsyncInvocation ai1 = client1.invokeAsync(() -> { + ClientCache cache = new ClientCacheFactory(createClientProperties("stranger", "1234567")).setPoolSubscriptionEnabled(true) + .addPoolServer("localhost", serverPort) + .create(); + + assertNotAuthorized(() -> SizeOp.execute((InternalPool) cache.getDefaultPool(), REGION_NAME), "DATA:READ:AuthRegion"); + }); + + AsyncInvocation ai2 = client2.invokeAsync(() -> { + ClientCache cache = new ClientCacheFactory(createClientProperties("authRegionReader", "1234567")).setPoolSubscriptionEnabled(true) + .addPoolServer("localhost", serverPort) + .create(); + + SizeOp.execute((InternalPool) cache.getDefaultPool(), REGION_NAME); + }); + + ai1.join(); + ai2.join(); + ai1.checkException(); + ai2.checkException(); + } +}