You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/06/02 20:58:54 UTC
[2/3] geode git commit: Fix precheckin failures
Fix precheckin failures
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/21b1e19e
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/21b1e19e
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/21b1e19e
Branch: refs/heads/feature/GEODE-2632-19
Commit: 21b1e19e311d7327ae4bb7ab84f888e6b837cb82
Parents: 9b1905c
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Jun 2 12:50:00 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Jun 2 13:38:10 2017 -0700
----------------------------------------------------------------------
.../RestAPIsAndInterOpsDUnitTest.java | 807 +++++++++----------
.../org/apache/geode/cache/CacheFactory.java | 1 +
.../distributed/internal/InternalLocator.java | 2 +
.../internal/membership/gms/Services.java | 13 +-
.../membership/gms/auth/GMSAuthenticator.java | 39 +-
.../geode/internal/cache/GemFireCacheImpl.java | 11 -
.../security/CustomSecurityService.java | 8 +-
.../security/DisabledSecurityService.java | 4 +-
.../security/EnabledSecurityService.java | 3 +-
.../security/LegacySecurityService.java | 4 +-
.../internal/security/SecurityService.java | 6 +-
.../security/SecurityServiceFactory.java | 53 +-
.../internal/security/SecurityServiceType.java | 4 +-
.../auth/AbstractGMSAuthenticatorTestCase.java | 33 +-
.../GMSAuthenticatorWithAuthenticatorTest.java | 76 +-
...GMSAuthenticatorWithSecurityManagerTest.java | 62 +-
.../security/IntegratedSecurityServiceTest.java | 222 -----
.../internal/security/SecurityServiceTest.java | 227 ++++++
.../CacheServerMBeanShiroJUnitTest.java | 109 ---
...eServerMBeanWithShiroIniIntegrationTest.java | 109 +++
...atedSecurityServiceCustomRealmJUnitTest.java | 44 -
...atedSecurityServiceWithIniFileJUnitTest.java | 154 ----
...tyServiceWithCustomRealmIntegrationTest.java | 44 +
...urityServiceWithShiroIniIntegrationTest.java | 154 ++++
...edSecurityCacheLifecycleIntegrationTest.java | 74 --
...SecurityManagerCallbacksDistributedTest.java | 132 ---
...SecurityManagerLifecycleDistributedTest.java | 143 ++++
...SecurityManagerLifecycleIntegrationTest.java | 73 ++
.../geode/security/SpySecurityManager.java | 19 +-
.../security/ClientAuthzObjectModDUnitTest.java | 22 +-
.../cli/LuceneIndexCommandsJUnitTest.java | 43 +-
31 files changed, 1325 insertions(+), 1370 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
index 45e7a61..a5a71d2 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
@@ -14,37 +14,19 @@
*/
package org.apache.geode.rest.internal.web.controllers;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
@@ -72,6 +54,32 @@ import org.apache.geode.test.dunit.NetworkUtils;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
/**
* Dunit Test containing inter - operations between REST Client and Gemfire cache client
@@ -81,10 +89,9 @@ import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactor
@Category(DistributedTest.class)
@RunWith(Parameterized.class)
@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
-@SuppressWarnings("serial")
public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
- public static final String PEOPLE_REGION_NAME = "People";
+ private static final String PEOPLE_REGION_NAME = "People";
private static final String findAllPeopleQuery =
"/queries?id=findAllPeople&q=SELECT%20*%20FROM%20/People";
@@ -96,10 +103,10 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
private static final String[] PARAM_QUERY_IDS_ARRAY =
{"findAllPeople", "filterByGender", "filterByLastName"};
- final static String QUERY_ARGS =
+ private static final String QUERY_ARGS =
"[" + "{" + "\"@type\": \"string\"," + "\"@value\": \"Patel\"" + "}" + "]";
- final static String PERSON_AS_JSON_CAS = "{" + "\"@old\" :" + "{"
+ private static final String PERSON_AS_JSON_CAS = "{" + "\"@old\" :" + "{"
+ "\"@type\": \"org.apache.geode.rest.internal.web.controllers.Person\"," + "\"id\": 101,"
+ " \"firstName\": \"Mithali\"," + " \"middleName\": \"Dorai\"," + " \"lastName\": \"Raj\","
+ " \"birthDate\": \"12/04/1982\"," + "\"gender\": \"FEMALE\"" + "}," + "\"@new\" :" + "{"
@@ -108,7 +115,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
+ " \"lastName\": \"Kohli\"," + " \"birthDate\": \"08/11/1988\"," + "\"gender\": \"MALE\""
+ "}" + "}";
- final static String PERSON_AS_JSON_REPLACE =
+ private static final String PERSON_AS_JSON_REPLACE =
"{" + "\"@type\": \"org.apache.geode.rest.internal.web.controllers.Person\"," + "\"id\": 501,"
+ " \"firstName\": \"Barack\"," + " \"middleName\": \"Hussein\","
+ " \"lastName\": \"Obama\"," + " \"birthDate\": \"04/08/1961\"," + "\"gender\": \"MALE\""
@@ -155,8 +162,9 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
return Arrays.asList("/geode", "/gemfire-api");
}
- public String startBridgeServerWithRestService(final String hostName, final String[] groups,
- final String locators, final String[] regions, final ServerLoadProbe probe) {
+ private String startBridgeServerWithRestService(final String hostName, final String[] groups,
+ final String locators, final String[] regions, final ServerLoadProbe probe)
+ throws IOException {
final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
// create Cache of given VM and start HTTP service with REST APIs service
@@ -166,8 +174,9 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
}
@SuppressWarnings("deprecation")
- protected int startBridgeServer(String hostName, int restServicerPort, final String[] groups,
- final String locators, final String[] regions, final ServerLoadProbe probe) {
+ private int startBridgeServer(String hostName, int restServicerPort, final String[] groups,
+ final String locators, final String[] regions, final ServerLoadProbe probe)
+ throws IOException {
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
@@ -192,16 +201,13 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
server.setPort(0);
server.setGroups(groups);
server.setLoadProbe(probe);
- try {
- server.start();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ server.start();
+
remoteObjects.put(CACHE_KEY, cache);
- return new Integer(server.getPort());
+ return server.getPort();
}
- public void doPutsInClientCache() {
+ private void doPutsInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
assertNotNull(cache);
Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);
@@ -263,114 +269,104 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
region.putAll(userMap);
- if (cache != null)
- cache.getLogger().info("Gemfire Cache Client: Puts successfully done");
-
+ cache.getLogger().info("Gemfire Cache Client: Puts successfully done");
}
- public void doQueryOpsUsingRestApis(String restEndpoint) {
+ private void doQueryOpsUsingRestApis(String restEndpoint) throws IOException {
String currentQueryOp = null;
- try {
- // Query TestCase-1 :: Prepare parameterized Queries
- {
- currentQueryOp = "findAllPeopleQuery";
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPost post = new HttpPost(restEndpoint + findAllPeopleQuery);
- post.addHeader("Content-Type", "application/json");
- post.addHeader("Accept", "application/json");
- CloseableHttpResponse createNamedQueryResponse = httpclient.execute(post);
- assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
- assertNotNull(createNamedQueryResponse.getEntity());
- createNamedQueryResponse.close();
-
- post = new HttpPost(restEndpoint + findPeopleByGenderQuery);
- post.addHeader("Content-Type", "application/json");
- post.addHeader("Accept", "application/json");
- createNamedQueryResponse = httpclient.execute(post);
- assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
- assertNotNull(createNamedQueryResponse.getEntity());
- createNamedQueryResponse.close();
-
- post = new HttpPost(restEndpoint + findPeopleByLastNameQuery);
- post.addHeader("Content-Type", "application/json");
- post.addHeader("Accept", "application/json");
- createNamedQueryResponse = httpclient.execute(post);
- assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
- assertNotNull(createNamedQueryResponse.getEntity());
- createNamedQueryResponse.close();
- }
-
- // Query TestCase-2 :: List all parameterized queries
- {
- currentQueryOp = "listAllQueries";
- HttpGet get = new HttpGet(restEndpoint + "/queries");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse listAllQueriesResponse = httpclient.execute(get);
- assertEquals(listAllQueriesResponse.getStatusLine().getStatusCode(), 200);
- assertNotNull(listAllQueriesResponse.getEntity());
-
- HttpEntity entity = listAllQueriesResponse.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer sb = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- sb.append(line);
- }
- listAllQueriesResponse.close();
-
- // Check whether received response contains expected query IDs.
-
- JSONObject jsonObject = new JSONObject(sb.toString());
- JSONArray jsonArray = jsonObject.getJSONArray("queries");
- for (int i = 0; i < jsonArray.length(); i++) {
- assertTrue("PREPARE_PARAMETERIZED_QUERY: function IDs are not matched", Arrays
- .asList(PARAM_QUERY_IDS_ARRAY).contains(jsonArray.getJSONObject(i).getString("id")));
- }
- }
-
- // Query TestCase-3 :: Run the specified named query passing in scalar values for query
- // parameters.
- {
- currentQueryOp = "filterByLastName";
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPost post = new HttpPost(restEndpoint + "/queries/filterByLastName");
- post.addHeader("Content-Type", "application/json");
- post.addHeader("Accept", "application/json");
- StringEntity entity = new StringEntity(QUERY_ARGS);
- post.setEntity(entity);
- CloseableHttpResponse runNamedQueryResponse = httpclient.execute(post);
-
- assertEquals(200, runNamedQueryResponse.getStatusLine().getStatusCode());
- assertNotNull(runNamedQueryResponse.getEntity());
- }
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
+
+ // Query TestCase-1 :: Prepare parameterized Queries
+
+ currentQueryOp = "findAllPeopleQuery";
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPost post = new HttpPost(restEndpoint + findAllPeopleQuery);
+ post.addHeader("Content-Type", "application/json");
+ post.addHeader("Accept", "application/json");
+ CloseableHttpResponse createNamedQueryResponse = httpclient.execute(post);
+ assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
+ assertNotNull(createNamedQueryResponse.getEntity());
+ createNamedQueryResponse.close();
+
+ post = new HttpPost(restEndpoint + findPeopleByGenderQuery);
+ post.addHeader("Content-Type", "application/json");
+ post.addHeader("Accept", "application/json");
+ createNamedQueryResponse = httpclient.execute(post);
+ assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
+ assertNotNull(createNamedQueryResponse.getEntity());
+ createNamedQueryResponse.close();
+
+ post = new HttpPost(restEndpoint + findPeopleByLastNameQuery);
+ post.addHeader("Content-Type", "application/json");
+ post.addHeader("Accept", "application/json");
+ createNamedQueryResponse = httpclient.execute(post);
+ assertEquals(createNamedQueryResponse.getStatusLine().getStatusCode(), 201);
+ assertNotNull(createNamedQueryResponse.getEntity());
+ createNamedQueryResponse.close();
+
+ // Query TestCase-2 :: List all parameterized queries
+
+ currentQueryOp = "listAllQueries";
+ HttpGet get = new HttpGet(restEndpoint + "/queries");
+ httpclient = HttpClients.createDefault();
+ CloseableHttpResponse listAllQueriesResponse = httpclient.execute(get);
+ assertEquals(listAllQueriesResponse.getStatusLine().getStatusCode(), 200);
+ assertNotNull(listAllQueriesResponse.getEntity());
+
+ HttpEntity entity = listAllQueriesResponse.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ StringBuilder sb = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ sb.append(line);
}
+ listAllQueriesResponse.close();
+
+ // Check whether received response contains expected query IDs.
+
+ JSONObject jsonObject = new JSONObject(sb.toString());
+ JSONArray jsonArray = jsonObject.getJSONArray("queries");
+ for (int i = 0; i < jsonArray.length(); i++) {
+ assertTrue("PREPARE_PARAMETERIZED_QUERY: function IDs are not matched", Arrays
+ .asList(PARAM_QUERY_IDS_ARRAY).contains(jsonArray.getJSONObject(i).getString("id")));
+ }
+
+ // Query TestCase-3 :: Run the specified named query passing in scalar values for query
+ // parameters.
+
+ currentQueryOp = "filterByLastName";
+ httpclient = HttpClients.createDefault();
+ post = new HttpPost(restEndpoint + "/queries/filterByLastName");
+ post.addHeader("Content-Type", "application/json");
+ post.addHeader("Accept", "application/json");
+ entity = new StringEntity(QUERY_ARGS);
+ post.setEntity(entity);
+ CloseableHttpResponse runNamedQueryResponse = httpclient.execute(post);
+
+ assertEquals(200, runNamedQueryResponse.getStatusLine().getStatusCode());
+ assertNotNull(runNamedQueryResponse.getEntity());
}
- public void verifyUpdatesInClientCache() {
+ private void verifyUpdatesInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
assertNotNull(cache);
Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);
- {
- Person expectedPerson = new Person(3L, "Nishka3", "Nilkanth3", "Patel3",
- DateTimeUtils.createDate(2009, Calendar.JULY, 31), Gender.FEMALE);
- Object value = region.get("3");
- if (value instanceof PdxInstance) {
- PdxInstance pi3 = (PdxInstance) value;
- Person actualPerson = (Person) pi3.getObject();
- assertEquals(actualPerson.getId(), expectedPerson.getId());
- assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
- assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
- assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
- assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
- assertEquals(actualPerson.getGender(), expectedPerson.getGender());
- } else if (value instanceof Person) {
- fail(
- "VerifyUpdatesInClientCache, Get on key 3, Expected to get value of type PdxInstance ");
- }
+ Person expectedPerson = new Person(3L, "Nishka3", "Nilkanth3", "Patel3",
+ DateTimeUtils.createDate(2009, Calendar.JULY, 31), Gender.FEMALE);
+ Object value = region.get("3");
+ // TODO: use assertion
+ if (value instanceof PdxInstance) {
+ PdxInstance pi3 = (PdxInstance) value;
+ Person actualPerson = (Person) pi3.getObject();
+ assertEquals(actualPerson.getId(), expectedPerson.getId());
+ assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
+ assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
+ assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
+ assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
+ assertEquals(actualPerson.getGender(), expectedPerson.getGender());
+ } else if (value instanceof Person) {
+ fail("VerifyUpdatesInClientCache, Get on key 3, Expected to get value of type PdxInstance ");
}
// TODO: uncomment it once following issue encountered in put?op=CAS is fixed or document the
@@ -391,86 +387,68 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
*/
// verify update on key "2"
- {
- Person expectedPerson = new Person(501L, "Barack", "Hussein", "Obama",
- DateTimeUtils.createDate(1961, Calendar.APRIL, 8), Gender.MALE);
- Object value = region.get("2");
- if (value instanceof PdxInstance) {
- PdxInstance pi3 = (PdxInstance) value;
- Person actualPerson = (Person) pi3.getObject();
- assertEquals(actualPerson.getId(), expectedPerson.getId());
- assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
- assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
- assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
- assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
- assertEquals(actualPerson.getGender(), expectedPerson.getGender());
- } else {
- fail(
- "VerifyUpdatesInClientCache, Get on key 2, Expected to get value of type PdxInstance ");
- }
+
+ expectedPerson = new Person(501L, "Barack", "Hussein", "Obama",
+ DateTimeUtils.createDate(1961, Calendar.APRIL, 8), Gender.MALE);
+ value = region.get("2");
+ // TODO: use assertion
+ if (value instanceof PdxInstance) {
+ PdxInstance pi3 = (PdxInstance) value;
+ Person actualPerson = (Person) pi3.getObject();
+ assertEquals(actualPerson.getId(), expectedPerson.getId());
+ assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
+ assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
+ assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
+ assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
+ assertEquals(actualPerson.getGender(), expectedPerson.getGender());
+ } else {
+ fail("VerifyUpdatesInClientCache, Get on key 2, Expected to get value of type PdxInstance ");
}
// verify Deleted key "13"
- {
- Object obj = region.get("13");
- assertEquals(obj, null);
- obj = region.get("14");
- assertEquals(obj, null);
+ Object obj = region.get("13");
+ assertEquals(obj, null);
- obj = region.get("15");
- assertEquals(obj, null);
+ obj = region.get("14");
+ assertEquals(obj, null);
- obj = region.get("16");
- assertEquals(obj, null);
- }
+ obj = region.get("15");
+ assertEquals(obj, null);
+ obj = region.get("16");
+ assertEquals(obj, null);
}
- public void doUpdatesUsingRestApis(String restEndpoint) {
+ private void doUpdatesUsingRestApis(String restEndpoint) throws IOException {
// UPdate keys using REST calls
- {
-
- try {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut put = new HttpPut(restEndpoint + "/People/3,4,5,6,7,8,9,10,11,12");
- put.addHeader("Content-Type", "application/json");
- put.addHeader("Accept", "application/json");
- StringEntity entity = new StringEntity(PERSON_LIST_AS_JSON);
- put.setEntity(entity);
- CloseableHttpResponse result = httpclient.execute(put);
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
- }
- }
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPut put = new HttpPut(restEndpoint + "/People/3,4,5,6,7,8,9,10,11,12");
+ put.addHeader("Content-Type", "application/json");
+ put.addHeader("Accept", "application/json");
+ StringEntity entity = new StringEntity(PERSON_LIST_AS_JSON);
+ put.setEntity(entity);
+ CloseableHttpResponse result = httpclient.execute(put);
// Delete Single keys
- {
- try {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpDelete delete = new HttpDelete(restEndpoint + "/People/13");
- delete.addHeader("Content-Type", "application/json");
- delete.addHeader("Accept", "application/json");
- CloseableHttpResponse result = httpclient.execute(delete);
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
- }
- }
+
+ httpclient = HttpClients.createDefault();
+ HttpDelete delete = new HttpDelete(restEndpoint + "/People/13");
+ delete.addHeader("Content-Type", "application/json");
+ delete.addHeader("Accept", "application/json");
+ result = httpclient.execute(delete);
// Delete set of keys
- {
- try {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpDelete delete = new HttpDelete(restEndpoint + "/People/14,15,16");
- delete.addHeader("Content-Type", "application/json");
- delete.addHeader("Accept", "application/json");
- CloseableHttpResponse result = httpclient.execute(delete);
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
- }
- }
+
+ httpclient = HttpClients.createDefault();
+ delete = new HttpDelete(restEndpoint + "/People/14,15,16");
+ delete.addHeader("Content-Type", "application/json");
+ delete.addHeader("Accept", "application/json");
+ result = httpclient.execute(delete);
// REST put?op=CAS for key 1
+
/*
* try { { HttpEntity<Object> entity = new HttpEntity<Object>(PERSON_AS_JSON_CAS, headers);
* ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange( restEndpoint +
@@ -483,262 +461,208 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
*/
// REST put?op=REPLACE for key 2
- {
- /*
- * HttpEntity<Object> entity = new HttpEntity<Object>(PERSON_AS_JSON_REPLACE, headers);
- * ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange( restEndpoint +
- * "/People/2?op=replace", HttpMethod.PUT, entity, String.class);
- */
-
- try {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut put = new HttpPut(restEndpoint + "/People/2?op=replace");
- put.addHeader("Content-Type", "application/json");
- put.addHeader("Accept", "application/json");
- StringEntity entity = new StringEntity(PERSON_AS_JSON_REPLACE);
- put.setEntity(entity);
- CloseableHttpResponse result = httpclient.execute(put);
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
- }
- }
+
+ /*
+ * HttpEntity<Object> entity = new HttpEntity<Object>(PERSON_AS_JSON_REPLACE, headers);
+ * ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange( restEndpoint +
+ * "/People/2?op=replace", HttpMethod.PUT, entity, String.class);
+ */
+
+ httpclient = HttpClients.createDefault();
+ put = new HttpPut(restEndpoint + "/People/2?op=replace");
+ put.addHeader("Content-Type", "application/json");
+ put.addHeader("Accept", "application/json");
+ entity = new StringEntity(PERSON_AS_JSON_REPLACE);
+ put.setEntity(entity);
+ result = httpclient.execute(put);
}
- public void fetchRestServerEndpoints(String restEndpoint) {
+ private void fetchRestServerEndpoints(String restEndpoint) throws IOException {
HttpGet get = new HttpGet(restEndpoint + "/servers");
get.addHeader("Content-Type", "application/json");
get.addHeader("Accept", "application/json");
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response;
- try {
- response = httpclient.execute(get);
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- // validate the satus code
- assertEquals(response.getStatusLine().getStatusCode(), 200);
-
- if (response.getStatusLine().getStatusCode() == 200) {
- JSONArray jsonArray = new JSONArray(str.toString());
-
- // verify total number of REST service endpoints in DS
- assertEquals(jsonArray.length(), 2);
- }
-
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- fail(" Rest Request should not have thrown ClientProtocolException!");
- } catch (IOException e) {
- e.printStackTrace();
- fail(" Rest Request should not have thrown IOException!");
- } catch (JSONException e) {
- e.printStackTrace();
- fail(" Rest Request should not have thrown JSONException!");
+ response = httpclient.execute(get);
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ StringBuilder str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
}
- }
+ // validate the satus code
+ assertEquals(response.getStatusLine().getStatusCode(), 200);
+
+ if (response.getStatusLine().getStatusCode() == 200) {
+ JSONArray jsonArray = new JSONArray(str.toString());
- public void doGetsUsingRestApis(String restEndpoint) {
+ // verify total number of REST service endpoints in DS
+ assertEquals(jsonArray.length(), 2);
+ }
+ }
+ private void doGetsUsingRestApis(String restEndpoint) throws IOException {
// HttpHeaders headers = setAcceptAndContentTypeHeaders();
String currentOperation = null;
JSONObject jObject;
JSONArray jArray;
- try {
- // 1. Get on key="1" and validate result.
- {
- currentOperation = "GET on key 1";
-
- HttpGet get = new HttpGet(restEndpoint + "/People/1");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response = httpclient.execute(get);
-
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- jObject = new JSONObject(str.toString());
-
- assertEquals(jObject.get("id"), 101);
- assertEquals(jObject.get("firstName"), "Mithali");
- assertEquals(jObject.get("middleName"), "Dorai");
- assertEquals(jObject.get("lastName"), "Raj");
- assertEquals(jObject.get("gender"), Gender.FEMALE.name());
- }
-
- // 2. Get on key="16" and validate result.
- {
- currentOperation = "GET on key 16";
-
- HttpGet get = new HttpGet(restEndpoint + "/People/16");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response = httpclient.execute(get);
-
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- jObject = new JSONObject(str.toString());
-
- assertEquals(jObject.get("id"), 104);
- assertEquals(jObject.get("firstName"), "Shila");
- assertEquals(jObject.get("middleName"), "kumari");
- assertEquals(jObject.get("lastName"), "Dixit");
- assertEquals(jObject.get("gender"), Gender.FEMALE.name());
- }
-
- // 3. Get all (getAll) entries in Region
- {
-
- HttpGet get = new HttpGet(restEndpoint + "/People");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse result = httpclient.execute(get);
- assertEquals(result.getStatusLine().getStatusCode(), 200);
- assertNotNull(result.getEntity());
-
- HttpEntity entity = result.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer sb = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- sb.append(line);
- }
- result.close();
-
- try {
- jObject = new JSONObject(sb.toString());
- jArray = jObject.getJSONArray("People");
- assertEquals(jArray.length(), 16);
- } catch (JSONException e) {
- fail(" Rest Request ::" + currentOperation + " :: should not have thrown JSONException ");
- }
- }
-
- // 4. GetAll?limit=10 (10 entries) and verify results
- {
- HttpGet get = new HttpGet(restEndpoint + "/People?limit=10");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
-
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- try {
- jObject = new JSONObject(str.toString());
- jArray = jObject.getJSONArray("People");
- assertEquals(jArray.length(), 10);
- } catch (JSONException e) {
- fail(" Rest Request ::" + currentOperation + " :: should not have thrown JSONException ");
- }
- }
-
- // 5. Get keys - List all keys in region
- {
-
- HttpGet get = new HttpGet(restEndpoint + "/People/keys");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
-
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- try {
- jObject = new JSONObject(str.toString());
- jArray = jObject.getJSONArray("keys");
- assertEquals(jArray.length(), 16);
- } catch (JSONException e) {
- fail(" Rest Request ::" + currentOperation + " :: should not have thrown JSONException ");
- }
- }
-
- // 6. Get data for specific keys
- {
-
- HttpGet get = new HttpGet(restEndpoint + "/People/1,3,5,7,9,11");
- get.addHeader("Content-Type", "application/json");
- get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
-
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- StringBuffer str = new StringBuffer();
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
-
- try {
- jObject = new JSONObject(str.toString());
- jArray = jObject.getJSONArray("People");
- assertEquals(jArray.length(), 6);
-
- } catch (JSONException e) {
- fail(" Rest Request ::" + currentOperation + " :: should not have thrown JSONException ");
- }
- }
- } catch (Exception e) {
- throw new RuntimeException("unexpected exception", e);
+
+ // 1. Get on key="1" and validate result.
+
+ currentOperation = "GET on key 1";
+
+ HttpGet get = new HttpGet(restEndpoint + "/People/1");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpclient.execute(get);
+
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ StringBuilder str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
+ }
+
+ jObject = new JSONObject(str.toString());
+
+ assertEquals(jObject.get("id"), 101);
+ assertEquals(jObject.get("firstName"), "Mithali");
+ assertEquals(jObject.get("middleName"), "Dorai");
+ assertEquals(jObject.get("lastName"), "Raj");
+ assertEquals(jObject.get("gender"), Gender.FEMALE.name());
+
+ // 2. Get on key="16" and validate result.
+
+ currentOperation = "GET on key 16";
+
+ get = new HttpGet(restEndpoint + "/People/16");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ httpclient = HttpClients.createDefault();
+ response = httpclient.execute(get);
+
+ entity = response.getEntity();
+ content = entity.getContent();
+ reader = new BufferedReader(new InputStreamReader(content));
+ str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
+ }
+
+ jObject = new JSONObject(str.toString());
+
+ assertEquals(jObject.get("id"), 104);
+ assertEquals(jObject.get("firstName"), "Shila");
+ assertEquals(jObject.get("middleName"), "kumari");
+ assertEquals(jObject.get("lastName"), "Dixit");
+ assertEquals(jObject.get("gender"), Gender.FEMALE.name());
+
+ // 3. Get all (getAll) entries in Region
+
+ get = new HttpGet(restEndpoint + "/People");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ httpclient = HttpClients.createDefault();
+ CloseableHttpResponse result = httpclient.execute(get);
+ assertEquals(result.getStatusLine().getStatusCode(), 200);
+ assertNotNull(result.getEntity());
+
+ entity = result.getEntity();
+ content = entity.getContent();
+ reader = new BufferedReader(new InputStreamReader(content));
+ StringBuilder sb = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ sb.append(line);
+ }
+ result.close();
+
+ jObject = new JSONObject(sb.toString());
+ jArray = jObject.getJSONArray("People");
+ assertEquals(jArray.length(), 16);
+
+ // 4. GetAll?limit=10 (10 entries) and verify results
+
+ get = new HttpGet(restEndpoint + "/People?limit=10");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ httpclient = HttpClients.createDefault();
+ response = httpclient.execute(get);
+ assertEquals(response.getStatusLine().getStatusCode(), 200);
+ assertNotNull(response.getEntity());
+
+ entity = response.getEntity();
+ content = entity.getContent();
+ reader = new BufferedReader(new InputStreamReader(content));
+ str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
+ }
+
+ jObject = new JSONObject(str.toString());
+ jArray = jObject.getJSONArray("People");
+ assertEquals(jArray.length(), 10);
+
+ // 5. Get keys - List all keys in region
+
+ get = new HttpGet(restEndpoint + "/People/keys");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ httpclient = HttpClients.createDefault();
+ response = httpclient.execute(get);
+ assertEquals(response.getStatusLine().getStatusCode(), 200);
+ assertNotNull(response.getEntity());
+
+ entity = response.getEntity();
+ content = entity.getContent();
+ reader = new BufferedReader(new InputStreamReader(content));
+ str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
+ }
+
+ jObject = new JSONObject(str.toString());
+ jArray = jObject.getJSONArray("keys");
+ assertEquals(jArray.length(), 16);
+
+ // 6. Get data for specific keys
+
+ get = new HttpGet(restEndpoint + "/People/1,3,5,7,9,11");
+ get.addHeader("Content-Type", "application/json");
+ get.addHeader("Accept", "application/json");
+ httpclient = HttpClients.createDefault();
+ response = httpclient.execute(get);
+ assertEquals(response.getStatusLine().getStatusCode(), 200);
+ assertNotNull(response.getEntity());
+
+ entity = response.getEntity();
+ content = entity.getContent();
+ reader = new BufferedReader(new InputStreamReader(content));
+ str = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ str.append(line);
}
+
+ jObject = new JSONObject(str.toString());
+ jArray = jObject.getJSONArray("People");
+ assertEquals(jArray.length(), 6);
}
- public void createRegionInClientCache() {
+ private void createRegionInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
assertNotNull(cache);
ClientRegionFactory<String, Object> crf =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<String, Object> region = crf.create(PEOPLE_REGION_NAME);
-
}
- public void createRegion() {
+ private void createRegion() {
Cache cache = GemFireCacheImpl.getInstance();
assertNotNull(cache);
@@ -751,7 +675,6 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
*/
@Test
public void testInterOpsWithReplicatedRegion() throws Exception {
-
final Host host = Host.getHost(0);
VM locator = host.getVM(0);
VM manager = host.getVM(1);
@@ -802,7 +725,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
doQueryOpsUsingRestApis(restEndpoint);
}
- private void createClientCache(final String host, final int port) throws Exception {
+ private void createClientCache(final String host, final int port) {
// Connect using the GemFire locator and create a Caching_Proxy cache
ClientCache c =
new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();
@@ -842,6 +765,6 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
server.setLoadProbe(probe);
server.start();
- return new Integer(server.getPort());
+ return server.getPort();
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/cache/CacheFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/CacheFactory.java b/geode-core/src/main/java/org/apache/geode/cache/CacheFactory.java
index 38fdac6..b4a1cc5 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/CacheFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/CacheFactory.java
@@ -201,6 +201,7 @@ public class CacheFactory {
public Cache create()
throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
synchronized (CacheFactory.class) {
+ // TODO:KIRK: need SecurityService for both DistributedSystem and create below
DistributedSystem ds = null;
if (this.dsProps.isEmpty()) {
// any ds will do
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
index c299dd0..5431432 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
@@ -694,6 +694,8 @@ public class InternalLocator extends Locator implements ConnectListener {
LocalizedStrings.InternalDistributedSystem_STARTUP_CONFIGURATIONN_0,
this.config.toLoggerString()));
+ // TODO:KIRK: need SecurityService for both DistributedSystem and startCache below
+
this.myDs = (InternalDistributedSystem) DistributedSystem.connect(connectEnv);
if (this.peerLocator) {
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
index 1404b3b..bae5a88 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
@@ -35,6 +35,8 @@ import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
import org.apache.geode.internal.logging.InternalLogWriter;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.LoggingThreadGroup;
+import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.logging.log4j.Logger;
@@ -53,17 +55,20 @@ public class Services {
final private Manager manager;
final private JoinLeave joinLeave;
- private Locator locator;
final private HealthMonitor healthMon;
final private Messenger messenger;
final private Authenticator auth;
final private ServiceConfig config;
final private DMStats stats;
final private Stopper cancelCriterion;
+ private final SecurityService securityService;
+
private volatile boolean stopping;
private volatile boolean stopped;
private volatile Exception shutdownCause;
+ private Locator locator;
+
private InternalLogWriter logWriter;
private InternalLogWriter securityLogWriter;
@@ -108,6 +113,7 @@ public class Services {
this.joinLeave = null;
this.healthMon = null;
this.messenger = null;
+ this.securityService = null;
this.auth = null;
}
@@ -120,6 +126,7 @@ public class Services {
this.joinLeave = new GMSJoinLeave();
this.healthMon = new GMSHealthMonitor();
this.messenger = new JGroupsMessenger();
+ this.securityService = SecurityServiceFactory.create(null, config);
this.auth = new GMSAuthenticator();
}
@@ -258,6 +265,10 @@ public class Services {
staticSecurityLogWriter = securityWriter;
}
+ public SecurityService getSecurityService() {
+ return this.securityService;
+ }
+
public InternalLogWriter getLogWriter() {
return this.logWriter;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticator.java
index 929ace4..3656a97 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticator.java
@@ -35,6 +35,7 @@ import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.tier.sockets.HandShake;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.internal.logging.InternalLogWriter;
+import org.apache.geode.internal.security.IntegratedSecurityService;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.security.AuthenticationFailedException;
@@ -105,13 +106,12 @@ public class GMSAuthenticator implements Authenticator {
*/
String authenticate(DistributedMember member, Properties credentials, Properties secProps)
throws AuthenticationFailedException {
- SecurityService securityService = getSecurityService();
+ SecurityService securityService = this.services.getSecurityService();
// For older systems, locator might be started without cache, so secureService may not be
- // initialized here. We need to check
- // if the passed in secProps has peer authenticator or not
+ // initialized here. We need to check if the passed in secProps has peer authenticator or not at
+ // this point
String authMethod = secProps.getProperty(SECURITY_PEER_AUTHENTICATOR);
- // at this point,
if (!securityService.isPeerSecurityRequired() && StringUtils.isBlank(authMethod)) {
return null;
}
@@ -211,35 +211,4 @@ public class GMSAuthenticator implements Authenticator {
@Override
public void emergencyClose() {}
-
- private final AtomicReference<SecurityService> securityServiceRef = new AtomicReference<>();
-
- /**
- * Terrible mess. It would be nice if we could create SecurityService BEFORE this class.
- */
- private SecurityService getSecurityService() {
- SecurityService securityService = this.securityServiceRef.get();
- if (securityService == null) {
- synchronized (this.securityServiceRef) {
- securityService = this.securityServiceRef.get();
- if (securityService == null) {
- InternalCache cache = GemFireCacheImpl.getInstance();
- if (cache != null) {
- securityService = cache.getSecurityService();
- }
- }
- if (securityService == null) {
- InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance();
- if (system != null) {
- securityService = SecurityServiceFactory.create(new CacheConfig(), system.getConfig());
- } else {
- securityService = SecurityServiceFactory.create(null, null);
- }
- }
- this.securityServiceRef.set(securityService);
- }
- }
- return securityService;
- }
-
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 3d4139b..2c69582 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -1164,17 +1164,6 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
ClusterConfigurationLoader.applyClusterPropertiesConfiguration(this, configurationResponse,
this.system.getConfig());
- // first initialize the security service using the security properties
- this.securityService.initSecurity(this.system.getConfig().getSecurityProps());
- // secondly if cacheConfig has a securityManager, use that instead
- if (this.cacheConfig.getSecurityManager() != null) {
- this.securityService.setSecurityManager(this.cacheConfig.getSecurityManager());
- }
- // if cacheConfig has a postProcessor, use that instead
- if (this.cacheConfig.getPostProcessor() != null) {
- this.securityService.setPostProcessor(this.cacheConfig.getPostProcessor());
- }
-
SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CREATE);
this.resourceAdvisor.initializationGate();
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/CustomSecurityService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/CustomSecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/CustomSecurityService.java
index e2ed059..f4b0ceb 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/CustomSecurityService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/CustomSecurityService.java
@@ -170,18 +170,18 @@ public class CustomSecurityService implements SecurityService {
@Override
public Object postProcess(final String regionPath, final Object key, final Object value,
final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
public Object postProcess(final Object principal, final String regionPath, final Object key,
final Object value, final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
public boolean isClientSecurityRequired() {
- return false;
+ return true;
}
@Override
@@ -191,7 +191,7 @@ public class CustomSecurityService implements SecurityService {
@Override
public boolean isPeerSecurityRequired() {
- return false;
+ return true;
}
@Override
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/DisabledSecurityService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/DisabledSecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/DisabledSecurityService.java
index b6a02b4..407bef1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/DisabledSecurityService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/DisabledSecurityService.java
@@ -173,13 +173,13 @@ public class DisabledSecurityService implements SecurityService {
@Override
public Object postProcess(final String regionPath, final Object key, final Object value,
final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
public Object postProcess(final Object principal, final String regionPath, final Object key,
final Object value, final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/EnabledSecurityService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/EnabledSecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/EnabledSecurityService.java
index 7af53ea..77b3fc2 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/EnabledSecurityService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/EnabledSecurityService.java
@@ -77,7 +77,8 @@ public class EnabledSecurityService implements SecurityService {
@Override
public void initSecurity(final Properties securityProps) {
- // nothing
+ this.securityManager.init(securityProps);
+ this.postProcessor.init(securityProps);
}
@Override
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/LegacySecurityService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/LegacySecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/LegacySecurityService.java
index 22bc348..a74ce01 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/LegacySecurityService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/LegacySecurityService.java
@@ -183,13 +183,13 @@ public class LegacySecurityService implements SecurityService {
@Override
public Object postProcess(final String regionPath, final Object key, final Object value,
final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
public Object postProcess(final Object principal, final String regionPath, final Object key,
final Object value, final boolean valueIsSerialized) {
- return null;
+ return value;
}
@Override
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/SecurityService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityService.java
index 6b1c4a6..65c4daf 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityService.java
@@ -30,11 +30,11 @@ import java.util.concurrent.Callable;
public interface SecurityService {
- void initSecurity(Properties securityProps); // TODO:KIRK
+ void initSecurity(Properties securityProps);
- void setSecurityManager(SecurityManager securityManager); // TODO:KIRK
+ void setSecurityManager(SecurityManager securityManager); // TODO:KIRK: delete
- void setPostProcessor(PostProcessor postProcessor); // TODO:KIRK
+ void setPostProcessor(PostProcessor postProcessor); // TODO:KIRK: delete
ThreadState bindSubject(Subject subject);
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceFactory.java b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceFactory.java
index e8c273a..6013286 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceFactory.java
@@ -25,6 +25,8 @@ import org.apache.geode.internal.cache.CacheConfig;
import org.apache.geode.internal.security.shiro.ConfigInitialization;
import org.apache.geode.security.PostProcessor;
import org.apache.geode.security.SecurityManager;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.UnavailableSecurityManagerException;
public class SecurityServiceFactory {
@@ -41,7 +43,7 @@ public class SecurityServiceFactory {
getPostProcessor(getPostProcessorFromConfig(cacheConfig), securityConfig);
SecurityService securityService = create(securityConfig, securityManager, postProcessor);
- // securityService.initSecurity(distributionConfig.getSecurityProps());
+ securityService.initSecurity(distributionConfig.getSecurityProps());
return securityService;
}
@@ -50,15 +52,17 @@ public class SecurityServiceFactory {
SecurityServiceType type = determineType(securityConfig, securityManager);
switch (type) {
case CUSTOM:
- String shiroConfig = securityConfig.getProperty(SECURITY_SHIRO_INIT);
- ConfigInitialization configInitialization = new ConfigInitialization(shiroConfig);
- configInitialization.initialize();
+ String shiroConfig = getProperty(securityConfig, SECURITY_SHIRO_INIT);
+ if (StringUtils.isNotBlank(shiroConfig)) {
+ ConfigInitialization configInitialization = new ConfigInitialization(shiroConfig);
+ configInitialization.initialize();
+ }
return new CustomSecurityService();
case ENABLED:
return new EnabledSecurityService(securityManager, postProcessor);
case LEGACY:
- String clientAuthenticator = securityConfig.getProperty(SECURITY_CLIENT_AUTHENTICATOR);
- String peerAuthenticator = securityConfig.getProperty(SECURITY_PEER_AUTHENTICATOR);
+ String clientAuthenticator = getProperty(securityConfig, SECURITY_CLIENT_AUTHENTICATOR);
+ String peerAuthenticator = getProperty(securityConfig, SECURITY_PEER_AUTHENTICATOR);
return new LegacySecurityService(clientAuthenticator, peerAuthenticator);
default:
return new DisabledSecurityService();
@@ -67,7 +71,7 @@ public class SecurityServiceFactory {
static SecurityServiceType determineType(Properties securityConfig,
SecurityManager securityManager) {
- boolean hasShiroConfig = securityConfig.getProperty(SECURITY_SHIRO_INIT) != null;
+ boolean hasShiroConfig = hasProperty(securityConfig, SECURITY_SHIRO_INIT);
if (hasShiroConfig) {
return SecurityServiceType.CUSTOM;
}
@@ -77,13 +81,17 @@ public class SecurityServiceFactory {
return SecurityServiceType.ENABLED;
}
- boolean hasClientAuthenticator =
- securityConfig.getProperty(SECURITY_CLIENT_AUTHENTICATOR) != null;
- boolean hasPeerAuthenticator = securityConfig.getProperty(SECURITY_PEER_AUTHENTICATOR) != null;
+ boolean hasClientAuthenticator = hasProperty(securityConfig, SECURITY_CLIENT_AUTHENTICATOR);
+ boolean hasPeerAuthenticator = hasProperty(securityConfig, SECURITY_PEER_AUTHENTICATOR);
if (hasClientAuthenticator || hasPeerAuthenticator) {
return SecurityServiceType.LEGACY;
}
+ boolean isShiroInUse = isShiroInUse();
+ if (isShiroInUse) {
+ return SecurityServiceType.CUSTOM;
+ }
+
return SecurityServiceType.DISABLED;
}
@@ -93,11 +101,10 @@ public class SecurityServiceFactory {
return securityManager;
}
- String securityManagerConfig = securityConfig.getProperty(SECURITY_MANAGER);
+ String securityManagerConfig = getProperty(securityConfig, SECURITY_MANAGER);
if (StringUtils.isNotBlank(securityManagerConfig)) {
securityManager = SecurityService.getObjectOfTypeFromClassName(securityManagerConfig,
SecurityManager.class);
- securityManager.init(securityConfig);
}
return securityManager;
@@ -108,16 +115,23 @@ public class SecurityServiceFactory {
return postProcessor;
}
- String postProcessorConfig = securityConfig.getProperty(SECURITY_POST_PROCESSOR);
+ String postProcessorConfig = getProperty(securityConfig, SECURITY_POST_PROCESSOR);
if (StringUtils.isNotBlank(postProcessorConfig)) {
postProcessor =
SecurityService.getObjectOfTypeFromClassName(postProcessorConfig, PostProcessor.class);
- postProcessor.init(securityConfig);
}
return postProcessor;
}
+ public static boolean isShiroInUse() {
+ try {
+ return SecurityUtils.getSecurityManager() != null;
+ } catch (UnavailableSecurityManagerException ignore) {
+ return false;
+ }
+ }
+
private static Properties getSecurityConfig(DistributionConfig distributionConfig) {
if (distributionConfig == null) {
return new Properties();
@@ -139,4 +153,15 @@ public class SecurityServiceFactory {
return cacheConfig.getPostProcessor();
}
+ private static boolean hasProperty(Properties securityConfig, String key) {
+ return securityConfig != null && getProperty(securityConfig, key) != null;
+ }
+
+ private static String getProperty(Properties securityConfig, String key) {
+ if (securityConfig == null) {
+ return null;
+ }
+ return securityConfig.getProperty(key);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceType.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceType.java b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceType.java
index 36fdcbf..8ae76d2 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceType.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/SecurityServiceType.java
@@ -22,5 +22,7 @@ public enum SecurityServiceType {
/** Legacy Security is Enabled */
LEGACY,
/** Shiro Config is specified */
- CUSTOM
+ CUSTOM,
+ /** Shiro is already configured with SecurityManager */
+ EXTERNAL
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
index f17b40b..e8c4e73 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
@@ -65,18 +65,19 @@ public abstract class AbstractGMSAuthenticatorTestCase {
clearStatics();
MockitoAnnotations.initMocks(this);
- props = new Properties();
- securityProps = new Properties();
-
- when(securityService.isIntegratedSecurity()).thenReturn(isIntegratedSecurity());
- when(securityService.isPeerSecurityRequired()).thenReturn(true);
- when(securityService.login(securityProps)).thenReturn(subject);
- when(distributionConfig.getSecurityProps()).thenReturn(securityProps);
- when(serviceConfig.getDistributionConfig()).thenReturn(distributionConfig);
- when(services.getSecurityLogWriter()).thenReturn(mock(InternalLogWriter.class));
- when(services.getConfig()).thenReturn(serviceConfig);
-
- authenticator.init(services);
+ this.props = new Properties();
+ this.securityProps = new Properties();
+
+ when(this.securityService.isIntegratedSecurity()).thenReturn(isIntegratedSecurity());
+ when(this.securityService.isPeerSecurityRequired()).thenReturn(true);
+ when(this.securityService.login(this.securityProps)).thenReturn(this.subject);
+ when(this.distributionConfig.getSecurityProps()).thenReturn(this.securityProps);
+ when(this.serviceConfig.getDistributionConfig()).thenReturn(this.distributionConfig);
+ when(this.services.getSecurityLogWriter()).thenReturn(mock(InternalLogWriter.class));
+ when(this.services.getConfig()).thenReturn(this.serviceConfig);
+ when(this.services.getSecurityService()).thenReturn(this.securityService);
+
+ this.authenticator.init(this.services);
}
protected abstract boolean isIntegratedSecurity();
@@ -135,11 +136,11 @@ public abstract class AbstractGMSAuthenticatorTestCase {
@Override
public void close() {
- closed = true;
+ this.closed = true;
}
public boolean isClosed() {
- return closed;
+ return this.closed;
}
public static int getCreateCount() {
@@ -284,11 +285,11 @@ public abstract class AbstractGMSAuthenticatorTestCase {
@Override
public void close() {
- closed = true;
+ this.closed = true;
}
public boolean isClosed() {
- return closed;
+ return this.closed;
}
public static int getCreateCount() {
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
index b9f6429..96a9a5f 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
@@ -38,26 +38,28 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void nullAuthenticatorShouldReturnNull() throws Exception {
- assertThat(securityProps).doesNotContainKey(SECURITY_PEER_AUTHENTICATOR);
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ assertThat(this.securityProps).doesNotContainKey(SECURITY_PEER_AUTHENTICATOR);
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
// assertThat(result).isNull(); NOTE: old security used to return null
assertThat(result).contains("Security check failed");
}
@Test
public void emptyAuthenticatorShouldReturnNull() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ this.securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
// assertThat(result).isNull(); NOTE: old security used to return null
assertThat(result).contains("Security check failed");
}
@Test
public void shouldGetSecurityPropsFromDistributionConfig() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
- securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "dummy2");
+ this.securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
+ this.securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "dummy2");
- Properties secProps = authenticator.getSecurityProps();
+ Properties secProps = this.authenticator.getSecurityProps();
assertThat(secProps.size()).isEqualTo(2);
assertThat(secProps.getProperty(SECURITY_PEER_AUTH_INIT)).isEqualTo("dummy1");
@@ -66,73 +68,74 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void usesPeerAuthInitToGetCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
SpyAuthInit auth = new SpyAuthInit();
assertThat(auth.isClosed()).isFalse();
SpyAuthInit.setAuthInitialize(auth);
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
- assertThat(credentials).isEqualTo(props);
+ assertThat(credentials).isEqualTo(this.props);
assertThat(auth.isClosed()).isTrue();
assertThat(SpyAuthInit.getCreateCount()).isEqualTo(1);
}
@Test
public void getCredentialsShouldReturnNullIfNoPeerAuthInit() throws Exception {
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldReturnNullIfEmptyPeerAuthInit() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, "");
- Properties credentials = authenticator.getCredentials(member, props);
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, "");
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitDoesNotExist() throws Exception {
String authInit = getClass().getName() + "$NotExistAuth.create";
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitCreateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitCreateReturnsNull.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsAndInitThrow() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsAndInitThrow.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("expected init error");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsThrows.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("expected get credential error");
}
@Test
public void authenticateShouldReturnNullIfSuccessful() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, SpyAuthenticator.class.getName() + ".create");
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ SpyAuthenticator.class.getName() + ".create");
SpyAuthenticator auth = new SpyAuthenticator();
assertThat(auth.isClosed()).isFalse();
SpyAuthenticator.setAuthenticator(auth);
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
assertThat(auth.isClosed()).isTrue();
@@ -141,15 +144,15 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void authenticateShouldReturnNullIfPeerAuthenticatorIsNull() throws Exception {
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
// assertThat(result).isNull(); // NOTE: old security used to return null
assertThat(result).contains("Security check failed. Instance could not be obtained from null");
}
@Test
public void authenticateShouldReturnNullIfPeerAuthenticatorIsEmpty() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
// assertThat(result).isNull(); // NOTE: old security used to return null
assertThat(result).contains("Security check failed. Instance could not be obtained from");
}
@@ -157,40 +160,41 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void authenticateShouldReturnFailureMessageIfPeerAuthenticatorDoesNotExist()
throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, getClass().getName() + "$NotExistAuth.create");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ getClass().getName() + "$NotExistAuth.create");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. Instance could not be obtained from");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorReturnsNulls.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. Instance could not be obtained");
}
@Test
public void authenticateShouldReturnFailureMessageIfNullCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorReturnsNulls.class.getName() + ".create");
- String result = authenticator.authenticate(member, null, props);
+ String result = this.authenticator.authenticate(this.member, null, this.props);
assertThat(result).startsWith("Failed to find credentials from");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateInitThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorInitThrows.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. expected init error");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorAuthenticateThrows.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. expected authenticate error");
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/21b1e19e/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
index 0cb6994..01ebc81 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
@@ -40,24 +40,26 @@ public class GMSAuthenticatorWithSecurityManagerTest extends AbstractGMSAuthenti
@Test
public void nullManagerShouldReturnNull() throws Exception {
- assertThat(securityProps).doesNotContainKey(SECURITY_MANAGER);
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ assertThat(this.securityProps).doesNotContainKey(SECURITY_MANAGER);
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
assertThat(result).isNull();
}
@Test
public void emptyAuthenticatorShouldReturnNull() throws Exception {
- securityProps.setProperty(SECURITY_MANAGER, "");
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ this.securityProps.setProperty(SECURITY_MANAGER, "");
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
assertThat(result).isNull();
}
@Test
public void shouldGetSecurityPropsFromDistributionConfig() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
- securityProps.setProperty(SECURITY_MANAGER, "dummy2");
+ this.securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
+ this.securityProps.setProperty(SECURITY_MANAGER, "dummy2");
- Properties secProps = authenticator.getSecurityProps();
+ Properties secProps = this.authenticator.getSecurityProps();
assertThat(secProps.size()).isEqualTo(2);
assertThat(secProps.getProperty(SECURITY_PEER_AUTH_INIT)).isEqualTo("dummy1");
@@ -66,91 +68,91 @@ public class GMSAuthenticatorWithSecurityManagerTest extends AbstractGMSAuthenti
@Test
public void usesPeerAuthInitToGetCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
- props.setProperty(SECURITY_MANAGER, "dummy");
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
SpyAuthInit auth = new SpyAuthInit();
assertThat(auth.isClosed()).isFalse();
SpyAuthInit.setAuthInitialize(auth);
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
- assertThat(credentials).isEqualTo(props);
+ assertThat(credentials).isEqualTo(this.props);
assertThat(auth.isClosed()).isTrue();
assertThat(SpyAuthInit.getCreateCount() == 1).isTrue();
}
@Test
public void getCredentialsShouldReturnNullIfNoPeerAuthInit() throws Exception {
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldReturnNullIfEmptyPeerAuthInit() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, "");
- Properties credentials = authenticator.getCredentials(member, props);
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, "");
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitDoesNotExist() throws Exception {
String authInit = getClass().getName() + "$NotExistAuth.create";
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitCreateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitCreateReturnsNull.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsAndInitThrow() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsAndInitThrow.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessage("expected init error");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsThrows.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessage("expected get credential error");
}
@Test
public void authenticateShouldReturnNullIfSuccessful() throws Exception {
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
}
@Test
public void authenticateShouldReturnNullIfNoSecurityManager() throws Exception {
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
}
@Test
public void authenticateShouldReturnFailureMessageIfLoginThrows() throws Exception {
- when(securityService.login(any(Properties.class)))
+ when(this.securityService.login(any(Properties.class)))
.thenThrow(new GemFireSecurityException("dummy"));
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. dummy");
}
@Test
public void authenticateShouldReturnFailureMessageIfNullCredentials() throws Exception {
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, null, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, null, this.props);
assertThat(result).startsWith("Failed to find credentials from");
}