Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-8782: Add getPrincipal method to FunctionContext interface (#5897)
- Add the ability to retrieve the Principal from the FunctionContext when a SecurityManager is enabled. - For rolling upgrade purposes this also includes a new ordinal version for GEODE_1_12_1. - Various test fixes to account for new version (cherry picked from commit a42f89a) (cherry picked from commit 0ab6771) * add 1.13.0 to old versions and set as Benchmarks baseline on develop * leave HTTP service off in WAN and Lucene rolling upgrade tests to avoid port conflict Co-authored-by: Bill Burcham <bill.burcham@gmail.com> (cherry picked from commit 9d139b5) * also add 1.13.1 that was missing from old-versions * clean up overzealous cherry-pick Co-authored-by: Dave Barnes <dbarnes@apache.org> Co-authored-by: Owen Nichols <onichols@apache.org>
- Loading branch information
1 parent
0333dad
commit b2d2054
Showing
20 changed files
with
312 additions
and
23 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
...java/org/apache/geode/internal/cache/execute/FunctionExecutionWithPrincipalDUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* 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 org.apache.geode.internal.cache.execute; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import org.apache.geode.cache.Region; | ||
import org.apache.geode.cache.RegionShortcut; | ||
import org.apache.geode.cache.client.ClientCache; | ||
import org.apache.geode.cache.execute.Function; | ||
import org.apache.geode.cache.execute.FunctionService; | ||
import org.apache.geode.distributed.ConfigurationProperties; | ||
import org.apache.geode.examples.SimpleSecurityManager; | ||
import org.apache.geode.management.internal.security.TestFunctions.ReadFunction; | ||
import org.apache.geode.test.dunit.rules.ClusterStartupRule; | ||
import org.apache.geode.test.dunit.rules.MemberVM; | ||
import org.apache.geode.test.dunit.rules.SerializableFunction; | ||
import org.apache.geode.test.junit.rules.ClientCacheRule; | ||
import org.apache.geode.test.junit.rules.ServerStarterRule; | ||
|
||
public class FunctionExecutionWithPrincipalDUnitTest { | ||
|
||
private static String PR_REGION_NAME = "partitioned-region"; | ||
private static String REGION_NAME = "replicated-region"; | ||
private static Region<String, String> replicateRegion; | ||
private static Region<String, String> partitionedRegion; | ||
|
||
private static Function<?> readFunction = new ReadFunction(); | ||
|
||
private static MemberVM locator; | ||
private static MemberVM server1; | ||
private static MemberVM server2; | ||
private static ClientCache client; | ||
|
||
@ClassRule | ||
public static ClusterStartupRule cluster = new ClusterStartupRule(); | ||
|
||
@ClassRule | ||
public static ClientCacheRule clientRule = new ClientCacheRule(); | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
locator = cluster.startLocatorVM(0, x -> x | ||
.withSecurityManager(SimpleSecurityManager.class)); | ||
int locatorPort = locator.getPort(); | ||
|
||
SerializableFunction<ServerStarterRule> startupFunction = x -> x | ||
.withConnectionToLocator(locatorPort) | ||
.withCredential("cluster", "cluster") | ||
.withProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER, | ||
"org.apache.geode.management.internal.security.TestFunctions*"); | ||
|
||
server1 = cluster.startServerVM(1, startupFunction); | ||
server2 = cluster.startServerVM(2, startupFunction); | ||
|
||
Stream.of(server1, server2).forEach(v -> v.invoke(() -> { | ||
ClusterStartupRule.getCache().createRegionFactory(RegionShortcut.REPLICATE).create( | ||
REGION_NAME); | ||
ClusterStartupRule.getCache().createRegionFactory(RegionShortcut.PARTITION_REDUNDANT) | ||
.create(PR_REGION_NAME); | ||
})); | ||
|
||
client = clientRule | ||
.withLocatorConnection(locatorPort) | ||
.withCredential("data", "data") | ||
.createCache(); | ||
|
||
replicateRegion = clientRule.createProxyRegion(REGION_NAME); | ||
partitionedRegion = clientRule.createProxyRegion(PR_REGION_NAME); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
replicateRegion.put("key-" + i, "value-" + i); | ||
partitionedRegion.put("key-" + i, "value-" + i); | ||
} | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingReplicateRegion_andCallingOnRegion() { | ||
FunctionService.onRegion(replicateRegion) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingPartitionedRegion_andCallingOnRegion() { | ||
FunctionService.onRegion(partitionedRegion) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingPartitionedRegion_andCallingOnRegion_withFilter() { | ||
Set<String> filter = new HashSet<>(); | ||
filter.add("key-1"); | ||
filter.add("key-2"); | ||
filter.add("key-4"); | ||
filter.add("key-7"); | ||
|
||
FunctionService.onRegion(partitionedRegion) | ||
.withFilter(filter) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingPartitionedRegion_andCallingOnServer() { | ||
FunctionService.onServer(partitionedRegion.getRegionService()) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingPartitionedRegion_andCallingOnServers() { | ||
FunctionService.onServers(partitionedRegion.getRegionService()) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
@Test | ||
public void verifyPrincipal_whenUsingReplicateRegion_andCallingOnServers() { | ||
FunctionService.onServers(replicateRegion.getRegionService()) | ||
.execute(readFunction) | ||
.getResult(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.