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/08 20:59:46 UTC
geode git commit: Fixup from feedback and extract utility methods
Repository: geode
Updated Branches:
refs/heads/feature/GEODE-2632-21 ae3f047b3 -> afa21b003
Fixup from feedback and extract utility methods
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/afa21b00
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/afa21b00
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/afa21b00
Branch: refs/heads/feature/GEODE-2632-21
Commit: afa21b003594cb8693411019341431697bf6e20c
Parents: ae3f047
Author: Kirk Lund <kl...@apache.org>
Authored: Thu Jun 8 13:59:24 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Jun 8 13:59:24 2017 -0700
----------------------------------------------------------------------
.../RestAPIsAndInterOpsDUnitTest.java | 259 +++++++------------
.../membership/gms/auth/GMSAuthenticator.java | 3 +-
.../apache/geode/internal/ClassLoadUtil.java | 75 ++----
.../internal/cache/tier/sockets/HandShake.java | 7 +-
.../command/UpdateClientNotification.java | 56 ++--
.../internal/security/CallbackInstantiator.java | 89 +++++++
.../geode/internal/security/Credentials.java | 36 +++
.../security/CustomSecurityService.java | 10 -
.../security/DisabledSecurityService.java | 10 -
.../security/EnabledSecurityService.java | 10 -
.../security/LegacySecurityService.java | 15 --
.../internal/security/SecurityService.java | 87 -------
.../security/SecurityServiceFactory.java | 14 +-
.../security/shiro/CustomAuthRealm.java | 7 +-
.../security/CallbackInstantiatorTest.java | 97 +++++++
.../internal/security/SecurityServiceTest.java | 134 ++--------
16 files changed, 393 insertions(+), 516 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 a5a71d2..b127884 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
@@ -22,11 +22,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_S
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 static org.assertj.core.api.Assertions.assertThat;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
@@ -106,15 +102,6 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
private static final String QUERY_ARGS =
"[" + "{" + "\"@type\": \"string\"," + "\"@value\": \"Patel\"" + "}" + "]";
- 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\" :" + "{"
- + "\"@type\": \"org.apache.geode.rest.internal.web.controllers.Person\"," + "\"id\": 1101,"
- + " \"firstName\": \"Virat\"," + " \"middleName\": \"Premkumar\","
- + " \"lastName\": \"Kohli\"," + " \"birthDate\": \"08/11/1988\"," + "\"gender\": \"MALE\""
- + "}" + "}";
-
private static final String PERSON_AS_JSON_REPLACE =
"{" + "\"@type\": \"org.apache.geode.rest.internal.web.controllers.Person\"," + "\"id\": 501,"
+ " \"firstName\": \"Barack\"," + " \"middleName\": \"Hussein\","
@@ -170,10 +157,9 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
// create Cache of given VM and start HTTP service with REST APIs service
startBridgeServer(hostName, serverPort, groups, locators, regions, probe);
- return "http://" + hostName + ":" + serverPort + urlContext + "/v1";
+ return "http://" + hostName + ":" + serverPort + this.urlContext + "/v1";
}
- @SuppressWarnings("deprecation")
private int startBridgeServer(String hostName, int restServicerPort, final String[] groups,
final String locators, final String[] regions, final ServerLoadProbe probe)
throws IOException {
@@ -209,7 +195,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
private void doPutsInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
- assertNotNull(cache);
+ assertThat(cache).isNotNull();
Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);
// put person object
@@ -273,44 +259,40 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
}
private void doQueryOpsUsingRestApis(String restEndpoint) throws IOException {
- String currentQueryOp = null;
-
// 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());
+ assertThat(createNamedQueryResponse.getStatusLine().getStatusCode()).isEqualTo(201);
+ assertThat(createNamedQueryResponse.getEntity()).isNotNull();
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());
+ assertThat(createNamedQueryResponse.getStatusLine().getStatusCode()).isEqualTo(201);
+ assertThat(createNamedQueryResponse.getEntity()).isNotNull();
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());
+ assertThat(createNamedQueryResponse.getStatusLine().getStatusCode()).isEqualTo(201);
+ assertThat(createNamedQueryResponse.getEntity()).isNotNull();
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());
+ assertThat(listAllQueriesResponse.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(listAllQueriesResponse.getEntity()).isNotNull();
HttpEntity entity = listAllQueriesResponse.getEntity();
InputStream content = entity.getContent();
@@ -327,14 +309,13 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
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")));
+ assertThat(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");
@@ -343,85 +324,64 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
post.setEntity(entity);
CloseableHttpResponse runNamedQueryResponse = httpclient.execute(post);
- assertEquals(200, runNamedQueryResponse.getStatusLine().getStatusCode());
- assertNotNull(runNamedQueryResponse.getEntity());
+ assertThat(runNamedQueryResponse.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(runNamedQueryResponse.getEntity()).isNotNull();
}
private void verifyUpdatesInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
- assertNotNull(cache);
+ assertThat(cache).isNotNull();
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");
- // 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
- // issue
- // CAS functionality is not working in following test case
- // step-1: Java client, Region.put("K", A);
- // Step-2: Rest CAS request for key "K" with data "@old" = A. CAS is failing as existing
- // PdxInstance in cache and
- // PdxInstance generated from JSON (CAS request) does not match as their value's type are
- // getting changed
- /*
- * //verify update on key "1" { Object obj = region.get("1"); if (obj instanceof PdxInstance) {
- * PdxInstance pi = (PdxInstance)obj; Person p1 = (Person)pi.getObject();
- * System.out.println("Nilkanth1 : verifyUpdatesInClientCache() : GET ON KEY=1" +
- * p1.toString()); }else {
- * System.out.println("Nilkanth1 : verifyUpdatesInClientCache() GET ON KEY=1 returned OBJECT: "
- * + obj.toString()); } }
- */
+ assertThat(value).isInstanceOf(PdxInstance.class);
+
+ PdxInstance pi3 = (PdxInstance) value;
+ Person actualPerson = (Person) pi3.getObject();
+ assertThat(actualPerson.getId()).isEqualTo(expectedPerson.getId());
+ assertThat(actualPerson.getFirstName()).isEqualTo(expectedPerson.getFirstName());
+ assertThat(actualPerson.getMiddleName()).isEqualTo(expectedPerson.getMiddleName());
+ assertThat(actualPerson.getLastName()).isEqualTo(expectedPerson.getLastName());
+ assertThat(actualPerson.getBirthDate()).isEqualTo(expectedPerson.getBirthDate());
+ assertThat(actualPerson.getGender()).isEqualTo(expectedPerson.getGender());
// verify update on key "2"
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 ");
- }
+
+ assertThat(value).isInstanceOf(PdxInstance.class);
+
+ pi3 = (PdxInstance) value;
+ actualPerson = (Person) pi3.getObject();
+ assertThat(actualPerson.getId()).isEqualTo(expectedPerson.getId());
+ assertThat(actualPerson.getFirstName()).isEqualTo(expectedPerson.getFirstName());
+ assertThat(actualPerson.getMiddleName()).isEqualTo(expectedPerson.getMiddleName());
+ assertThat(actualPerson.getLastName()).isEqualTo(expectedPerson.getLastName());
+ assertThat(actualPerson.getBirthDate()).isEqualTo(expectedPerson.getBirthDate());
+ assertThat(actualPerson.getGender()).isEqualTo(expectedPerson.getGender());
// verify Deleted key "13"
Object obj = region.get("13");
- assertEquals(obj, null);
+ assertThat(obj).isNull();
obj = region.get("14");
- assertEquals(obj, null);
+ assertThat(obj).isNull();
obj = region.get("15");
- assertEquals(obj, null);
+ assertThat(obj).isNull();
obj = region.get("16");
- assertEquals(obj, null);
+ assertThat(obj).isNull();
}
private void doUpdatesUsingRestApis(String restEndpoint) throws IOException {
- // UPdate keys using REST calls
+ // Update keys using REST calls
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPut put = new HttpPut(restEndpoint + "/People/3,4,5,6,7,8,9,10,11,12");
@@ -430,6 +390,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
StringEntity entity = new StringEntity(PERSON_LIST_AS_JSON);
put.setEntity(entity);
CloseableHttpResponse result = httpclient.execute(put);
+ assertThat(result).isNotNull();
// Delete Single keys
@@ -438,6 +399,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
delete.addHeader("Content-Type", "application/json");
delete.addHeader("Accept", "application/json");
result = httpclient.execute(delete);
+ assertThat(result).isNotNull();
// Delete set of keys
@@ -446,28 +408,12 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
delete.addHeader("Content-Type", "application/json");
delete.addHeader("Accept", "application/json");
result = httpclient.execute(delete);
+ assertThat(result).isNotNull();
// 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 +
- * "/People/1?op=cas", HttpMethod.PUT, entity, String.class); } } catch
- * (HttpClientErrorException e) {
- *
- * fail("Caught HttpClientErrorException while doing put with op=cas"); }catch
- * (HttpServerErrorException se) {
- * fail("Caught HttpServerErrorException while doing put with op=cas"); }
- */
-
// 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);
- */
-
httpclient = HttpClients.createDefault();
put = new HttpPut(restEndpoint + "/People/2?op=replace");
put.addHeader("Content-Type", "application/json");
@@ -475,6 +421,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
entity = new StringEntity(PERSON_AS_JSON_REPLACE);
put.setEntity(entity);
result = httpclient.execute(put);
+ assertThat(result).isNotNull();
}
private void fetchRestServerEndpoints(String restEndpoint) throws IOException {
@@ -482,39 +429,29 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
get.addHeader("Content-Type", "application/json");
get.addHeader("Accept", "application/json");
CloseableHttpClient httpclient = HttpClients.createDefault();
- CloseableHttpResponse response;
- response = httpclient.execute(get);
+ 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();
+ StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- // validate the satus code
- assertEquals(response.getStatusLine().getStatusCode(), 200);
+ // validate the status code
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
- if (response.getStatusLine().getStatusCode() == 200) {
- JSONArray jsonArray = new JSONArray(str.toString());
+ JSONArray jsonArray = new JSONArray(sb.toString());
- // verify total number of REST service endpoints in DS
- assertEquals(jsonArray.length(), 2);
- }
+ // verify total number of REST service endpoints in DS
+ assertThat(jsonArray.length()).isEqualTo(2);
}
private void doGetsUsingRestApis(String restEndpoint) throws IOException {
- // HttpHeaders headers = setAcceptAndContentTypeHeaders();
- String currentOperation = null;
- JSONObject jObject;
- JSONArray jArray;
-
// 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");
@@ -525,23 +462,21 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
- StringBuilder str = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- jObject = new JSONObject(str.toString());
+ JSONObject jObject = new JSONObject(sb.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());
+ assertThat(jObject.get("id")).isEqualTo(101);
+ assertThat(jObject.get("firstName")).isEqualTo("Mithali");
+ assertThat(jObject.get("middleName")).isEqualTo("Dorai");
+ assertThat(jObject.get("lastName")).isEqualTo("Raj");
+ assertThat(jObject.get("gender")).isEqualTo(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");
@@ -551,18 +486,18 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
entity = response.getEntity();
content = entity.getContent();
reader = new BufferedReader(new InputStreamReader(content));
- str = new StringBuilder();
+ sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- jObject = new JSONObject(str.toString());
+ jObject = new JSONObject(sb.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());
+ assertThat(jObject.get("id")).isEqualTo(104);
+ assertThat(jObject.get("firstName")).isEqualTo("Shila");
+ assertThat(jObject.get("middleName")).isEqualTo("kumari");
+ assertThat(jObject.get("lastName")).isEqualTo("Dixit");
+ assertThat(jObject.get("gender")).isEqualTo(Gender.FEMALE.name());
// 3. Get all (getAll) entries in Region
@@ -571,21 +506,21 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
get.addHeader("Accept", "application/json");
httpclient = HttpClients.createDefault();
CloseableHttpResponse result = httpclient.execute(get);
- assertEquals(result.getStatusLine().getStatusCode(), 200);
- assertNotNull(result.getEntity());
+ assertThat(result.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(result.getEntity()).isNotNull();
entity = result.getEntity();
content = entity.getContent();
reader = new BufferedReader(new InputStreamReader(content));
- StringBuilder sb = new 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);
+ JSONArray jArray = jObject.getJSONArray("People");
+ assertThat(jArray.length()).isEqualTo(16);
// 4. GetAll?limit=10 (10 entries) and verify results
@@ -594,20 +529,20 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
get.addHeader("Accept", "application/json");
httpclient = HttpClients.createDefault();
response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(response.getEntity()).isNotNull();
entity = response.getEntity();
content = entity.getContent();
reader = new BufferedReader(new InputStreamReader(content));
- str = new StringBuilder();
+ sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- jObject = new JSONObject(str.toString());
+ jObject = new JSONObject(sb.toString());
jArray = jObject.getJSONArray("People");
- assertEquals(jArray.length(), 10);
+ assertThat(jArray.length()).isEqualTo(10);
// 5. Get keys - List all keys in region
@@ -616,20 +551,20 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
get.addHeader("Accept", "application/json");
httpclient = HttpClients.createDefault();
response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(response.getEntity()).isNotNull();
entity = response.getEntity();
content = entity.getContent();
reader = new BufferedReader(new InputStreamReader(content));
- str = new StringBuilder();
+ sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- jObject = new JSONObject(str.toString());
+ jObject = new JSONObject(sb.toString());
jArray = jObject.getJSONArray("keys");
- assertEquals(jArray.length(), 16);
+ assertThat(jArray.length()).isEqualTo(16);
// 6. Get data for specific keys
@@ -638,25 +573,25 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
get.addHeader("Accept", "application/json");
httpclient = HttpClients.createDefault();
response = httpclient.execute(get);
- assertEquals(response.getStatusLine().getStatusCode(), 200);
- assertNotNull(response.getEntity());
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(response.getEntity()).isNotNull();
entity = response.getEntity();
content = entity.getContent();
reader = new BufferedReader(new InputStreamReader(content));
- str = new StringBuilder();
+ sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
- str.append(line);
+ sb.append(line);
}
- jObject = new JSONObject(str.toString());
+ jObject = new JSONObject(sb.toString());
jArray = jObject.getJSONArray("People");
- assertEquals(jArray.length(), 6);
+ assertThat(jArray.length()).isEqualTo(6);
}
private void createRegionInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
- assertNotNull(cache);
+ assertThat(cache).isNotNull();
ClientRegionFactory<String, Object> crf =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<String, Object> region = crf.create(PEOPLE_REGION_NAME);
@@ -664,7 +599,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
private void createRegion() {
Cache cache = GemFireCacheImpl.getInstance();
- assertNotNull(cache);
+ assertThat(cache).isNotNull();
RegionFactory<String, Object> rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region<String, Object> region = rf.create(PEOPLE_REGION_NAME);
@@ -727,10 +662,10 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
private void createClientCache(final String host, final int port) {
// Connect using the GemFire locator and create a Caching_Proxy cache
- ClientCache c =
+ ClientCache clientCache =
new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();
- c.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
+ clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
}
private int startManager(final String[] groups, final String locators, final String[] regions,
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 4f89316..f895b96 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
@@ -31,6 +31,7 @@ import org.apache.geode.distributed.internal.membership.gms.interfaces.Authentic
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.CallbackInstantiator;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.GemFireSecurityException;
@@ -142,7 +143,7 @@ public class GMSAuthenticator implements Authenticator {
String authMethod = securityProps.getProperty(SECURITY_PEER_AUTHENTICATOR);
org.apache.geode.security.Authenticator auth = null;
try {
- auth = SecurityService.getObjectOfType(authMethod,
+ auth = CallbackInstantiator.getObjectOfType(authMethod,
org.apache.geode.security.Authenticator.class);
LogWriter logWriter = this.services.getLogWriter();
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/ClassLoadUtil.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/ClassLoadUtil.java b/geode-core/src/main/java/org/apache/geode/internal/ClassLoadUtil.java
index 60d1d39..5dad332 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/ClassLoadUtil.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/ClassLoadUtil.java
@@ -21,39 +21,20 @@ import java.util.Map;
public class ClassLoadUtil {
- static Map primTypes;
- static Map wrapperTypes;
+ private static final Map<String, Class> PRIMITIVE_TYPES = primitiveTypes();
- static {
-
- if (primTypes == null) {
- Map ptMap = new HashMap();
- ptMap.put(boolean.class.getName(), boolean.class);
- ptMap.put(char.class.getName(), char.class);
- ptMap.put(byte.class.getName(), byte.class);
- ptMap.put(short.class.getName(), short.class);
- ptMap.put(int.class.getName(), int.class);
- ptMap.put(long.class.getName(), long.class);
- ptMap.put(float.class.getName(), float.class);
- ptMap.put(double.class.getName(), double.class);
- ptMap.put(void.class.getName(), void.class);
- // Do this at the end to support multiple threads without synchronizing
- primTypes = ptMap;
- }
-
- if (wrapperTypes == null) {
- Map wtMap = new HashMap();
- wtMap.put(boolean.class.getName(), Boolean.class);
- wtMap.put(char.class.getName(), Character.class);
- wtMap.put(byte.class.getName(), Byte.class);
- wtMap.put(short.class.getName(), Short.class);
- wtMap.put(int.class.getName(), Integer.class);
- wtMap.put(long.class.getName(), Long.class);
- wtMap.put(float.class.getName(), Float.class);
- wtMap.put(double.class.getName(), Double.class);
- // Do this at the end to support multiple threads without synchronizing
- wrapperTypes = wtMap;
- }
+ private static Map primitiveTypes() {
+ Map<String, Class> ptMap = new HashMap<>();
+ ptMap.put(boolean.class.getName(), boolean.class);
+ ptMap.put(char.class.getName(), char.class);
+ ptMap.put(byte.class.getName(), byte.class);
+ ptMap.put(short.class.getName(), short.class);
+ ptMap.put(int.class.getName(), int.class);
+ ptMap.put(long.class.getName(), long.class);
+ ptMap.put(float.class.getName(), float.class);
+ ptMap.put(double.class.getName(), double.class);
+ ptMap.put(void.class.getName(), void.class);
+ return ptMap;
}
/**
@@ -68,9 +49,9 @@ public class ClassLoadUtil {
}
/**
- * Resolve the method from the given qualified name.
+ * Resolve the method from the given qualified name. Only zero argument methods are supported.
*/
- public static Method methodFromName(String fullyQualifiedMethodName, Class[] parameterTypes)
+ public static Method methodFromName(String fullyQualifiedMethodName)
throws ClassNotFoundException, NoSuchMethodException, SecurityException {
int classIndex = fullyQualifiedMethodName.lastIndexOf('.');
if (classIndex <= 0) {
@@ -82,34 +63,16 @@ public class ClassLoadUtil {
throw new NoSuchMethodException(className + " cannot be one of the primitive types");
}
String methodName = fullyQualifiedMethodName.substring(classIndex + 1);
- Class result = ClassPathLoader.getLatest().forName(className);
- return result.getMethod(methodName, parameterTypes);
- }
-
- /**
- * Resolve the method from the given qualified name. Only zero argument methods are supported.
- */
- public static Method methodFromName(String fullyQualifiedMethodName)
- throws ClassNotFoundException, NoSuchMethodException, SecurityException {
- return methodFromName(fullyQualifiedMethodName, (Class[]) null);
+ Class<?> result = ClassPathLoader.getLatest().forName(className);
+ return result.getMethod(methodName);
}
/**
* If the argument className is the name of a primitive type (including "void"), return the
* primitive type class (ex, boolean.class). Otherwise, return null.
*/
- public static Class checkForPrimType(String className) {
-
- return (Class) primTypes.get(className);
- }
-
- /**
- * If the argument className is the name of a primitive type (not including "void"), return the
- * wrapper class for that type (ex, Boolean.class). Otherwise, return null.
- */
- public static Class checkForWrapperType(String className) {
-
- return (Class) wrapperTypes.get(className);
+ private static Class checkForPrimType(String className) {
+ return PRIMITIVE_TYPES.get(className);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java
index 93c2861..32735b9 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java
@@ -48,6 +48,8 @@ import org.apache.geode.internal.cache.tier.ConnectionProxy;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.internal.logging.InternalLogWriter;
import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.security.CallbackInstantiator;
+import org.apache.geode.internal.security.Credentials;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.pdx.internal.PeerTypeRegistration;
@@ -1508,12 +1510,13 @@ public class HandShake implements ClientHandShake {
Properties credentials = null;
// if no authInit, Try to extract the credentials directly from securityProps
if (StringUtils.isBlank(authInitMethod)) {
- return SecurityService.getCredentials(securityProperties);
+ return Credentials.getCredentials(securityProperties);
}
// if authInit exists
try {
- AuthInitialize auth = SecurityService.getObjectOfType(authInitMethod, AuthInitialize.class);
+ AuthInitialize auth =
+ CallbackInstantiator.getObjectOfType(authInitMethod, AuthInitialize.class);
auth.init(logWriter, securityLogWriter);
try {
credentials = auth.getCredentials(securityProperties, server, isPeer);
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/UpdateClientNotification.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/UpdateClientNotification.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/UpdateClientNotification.java
index b19c710..8e50f64 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/UpdateClientNotification.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/UpdateClientNotification.java
@@ -12,65 +12,43 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-/**
- *
- */
package org.apache.geode.internal.cache.tier.sockets.command;
-import org.apache.geode.internal.cache.tier.Command;
-import org.apache.geode.internal.cache.tier.sockets.*;
import org.apache.geode.distributed.internal.DistributionStats;
+import org.apache.geode.internal.cache.tier.Command;
+import org.apache.geode.internal.cache.tier.sockets.BaseCommand;
+import org.apache.geode.internal.cache.tier.sockets.CacheServerStats;
+import org.apache.geode.internal.cache.tier.sockets.Message;
+import org.apache.geode.internal.cache.tier.sockets.ServerConnection;
import org.apache.geode.internal.security.SecurityService;
import java.io.IOException;
-
public class UpdateClientNotification extends BaseCommand {
- private final static UpdateClientNotification singleton = new UpdateClientNotification();
+ private static final UpdateClientNotification singleton = new UpdateClientNotification();
public static Command getCommand() {
return singleton;
}
- private UpdateClientNotification() {}
+ private UpdateClientNotification() {
+ // nothing
+ }
@Override
public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection,
final SecurityService securityService, long start) throws IOException {
+
CacheServerStats stats = serverConnection.getCacheServerStats();
- {
- long oldStart = start;
- start = DistributionStats.getStatTime();
- stats.incReadUpdateClientNotificationRequestTime(start - oldStart);
- }
- try {
- // this is no longer needed the client membership id is now used
- // // Retrieve the data from the message parts
- // Part clientPortPart = msg.getPart(0);
- // int clientPort = clientPortPart.getInt();
- // if (logger.fineEnabled()) {
- // logger.fine(servConn.getName()
- // + ": Received client notification update request ("
- // + msg.getPayloadLength() + " bytes) for " + clientPort + " from "
- // + servConn.getSocketHost() + ":" + servConn.getSocketPort());
- // }
- // // Update the client socket and remote ports
- // servConn.getAcceptor().getCacheClientNotifier().registerClientPort(
- // servConn.getSocketHost(), clientPort, servConn.getSocketPort(),
- // servConn.getProxyID());
- // if (logger.fineEnabled()) {
- // logger.fine(servConn.getName()
- // + ": Processed client notification update request for "
- // + clientPort + " from " + servConn.getSocketHost() + ":"
- // + servConn.getSocketPort());
- // }
- } finally {
- long oldStart = start;
- start = DistributionStats.getStatTime();
- stats.incProcessUpdateClientNotificationTime(start - oldStart);
- }
+ long oldStart = start;
+ start = DistributionStats.getStatTime();
+ stats.incReadUpdateClientNotificationRequestTime(start - oldStart);
+
+ oldStart = start;
+ start = DistributionStats.getStatTime();
+ stats.incProcessUpdateClientNotificationTime(start - oldStart);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/security/CallbackInstantiator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/CallbackInstantiator.java b/geode-core/src/main/java/org/apache/geode/internal/security/CallbackInstantiator.java
new file mode 100644
index 0000000..3ff632d
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/CallbackInstantiator.java
@@ -0,0 +1,89 @@
+/*
+ * 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.security;
+
+import static org.apache.geode.internal.ClassLoadUtil.classFromName;
+import static org.apache.geode.internal.ClassLoadUtil.methodFromName;
+
+import org.apache.geode.security.GemFireSecurityException;
+
+import java.lang.reflect.Method;
+
+/**
+ * Utility methods for instantiating security callback objects by reflection.
+ */
+public class CallbackInstantiator {
+
+ /**
+ * this method would never return null, it either throws an exception or returns an object
+ */
+ public static <T> T getObjectOfTypeFromClassName(String className, Class<T> expectedClazz) {
+ Class actualClass;
+ try {
+ actualClass = classFromName(className);
+ } catch (Exception e) {
+ throw new GemFireSecurityException("Instance could not be obtained, " + e, e);
+ }
+
+ if (!expectedClazz.isAssignableFrom(actualClass)) {
+ throw new GemFireSecurityException(
+ "Instance could not be obtained. Expecting a " + expectedClazz.getName() + " class.");
+ }
+
+ try {
+ return (T) actualClass.newInstance();
+ } catch (Exception e) {
+ throw new GemFireSecurityException(
+ "Instance could not be obtained. Error instantiating " + actualClass.getName(), e);
+ }
+ }
+
+ /**
+ * this method would never return null, it either throws an exception or returns an object
+ */
+ private static <T> T getObjectOfTypeFromFactoryMethod(String factoryMethodName) {
+ T actualObject;
+ try {
+ Method factoryMethod = methodFromName(factoryMethodName);
+ actualObject = (T) factoryMethod.invoke(null, (Object[]) null);
+ } catch (Exception e) {
+ throw new GemFireSecurityException("Instance could not be obtained from " + factoryMethodName,
+ e);
+ }
+
+ if (actualObject == null) {
+ throw new GemFireSecurityException(
+ "Instance could not be obtained from " + factoryMethodName);
+ }
+
+ return actualObject;
+ }
+
+ /**
+ * this method would never return null, it either throws an exception or returns an object
+ *
+ * @return an object of type expectedClazz. This method would never return null. It either returns
+ * an non-null object or throws exception.
+ */
+ public static <T> T getObjectOfType(String classOrMethod, Class<T> expectedClazz) {
+ T object;
+ try {
+ object = getObjectOfTypeFromClassName(classOrMethod, expectedClazz);
+ } catch (Exception ignore) {
+ object = getObjectOfTypeFromFactoryMethod(classOrMethod);
+ }
+ return object;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/security/Credentials.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/Credentials.java b/geode-core/src/main/java/org/apache/geode/internal/security/Credentials.java
new file mode 100644
index 0000000..518af9b
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/Credentials.java
@@ -0,0 +1,36 @@
+/*
+ * 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.security;
+
+import static org.apache.geode.management.internal.security.ResourceConstants.PASSWORD;
+import static org.apache.geode.management.internal.security.ResourceConstants.USER_NAME;
+
+import java.util.Properties;
+
+/**
+ * Utility for gathering security credentials from securityProperties.
+ */
+public class Credentials {
+
+ public static Properties getCredentials(Properties securityProps) {
+ Properties credentials = null;
+ if (securityProps.containsKey(USER_NAME) && securityProps.containsKey(PASSWORD)) {
+ credentials = new Properties();
+ credentials.setProperty(USER_NAME, securityProps.getProperty(USER_NAME));
+ credentials.setProperty(PASSWORD, securityProps.getProperty(PASSWORD));
+ }
+ return credentials;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 e7e9338..c4946e7 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
@@ -64,16 +64,6 @@ public class CustomSecurityService implements SecurityService {
}
@Override
- public void setSecurityManager(final SecurityManager securityManager) {
- // nothing
- }
-
- @Override
- public void setPostProcessor(final PostProcessor postProcessor) {
- // nothing
- }
-
- @Override
public ThreadState bindSubject(final Subject subject) {
if (subject == null) {
return null;
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 c971da6..d328946 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
@@ -41,16 +41,6 @@ public class DisabledSecurityService implements SecurityService {
}
@Override
- public void setSecurityManager(final SecurityManager securityManager) {
- // nothing
- }
-
- @Override
- public void setPostProcessor(final PostProcessor postProcessor) {
- // nothing
- }
-
- @Override
public ThreadState bindSubject(final Subject subject) {
if (subject == null) {
return null;
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 bacaa8a..301c8bc 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
@@ -81,16 +81,6 @@ public class EnabledSecurityService implements SecurityService {
}
}
- @Override
- public void setSecurityManager(final SecurityManager securityManager) {
- // nothing
- }
-
- @Override
- public void setPostProcessor(final PostProcessor postProcessor) {
- // nothing
- }
-
/**
* It first looks the shiro subject in AccessControlContext since JMX will use multiple threads to
* process operations from the same client, then it looks into Shiro's thead context.
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 a74ce01..ef92bb7 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
@@ -14,14 +14,9 @@
*/
package org.apache.geode.internal.security;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-
import java.util.Properties;
import java.util.concurrent.Callable;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.config.Ini.Section;
-import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadState;
@@ -50,16 +45,6 @@ public class LegacySecurityService implements SecurityService {
}
@Override
- public void setSecurityManager(final SecurityManager securityManager) {
- // nothing
- }
-
- @Override
- public void setPostProcessor(final PostProcessor postProcessor) {
- // nothing
- }
-
- @Override
public ThreadState bindSubject(final Subject subject) {
return null;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 f0b7ffc..be81582 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
@@ -14,17 +14,13 @@
*/
package org.apache.geode.internal.security;
-import org.apache.geode.internal.ClassLoadUtil;
-import org.apache.geode.management.internal.security.ResourceConstants;
import org.apache.geode.management.internal.security.ResourceOperation;
-import org.apache.geode.security.GemFireSecurityException;
import org.apache.geode.security.PostProcessor;
import org.apache.geode.security.ResourcePermission;
import org.apache.geode.security.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadState;
-import java.lang.reflect.Method;
import java.util.Properties;
import java.util.concurrent.Callable;
@@ -32,12 +28,6 @@ public interface SecurityService {
void initSecurity(Properties securityProps);
- // TODO: delete setSecurityManager
- void setSecurityManager(SecurityManager securityManager);
-
- // TODO: delete setPostProcessor
- void setPostProcessor(PostProcessor postProcessor);
-
ThreadState bindSubject(Subject subject);
Subject getSubject();
@@ -46,7 +36,6 @@ public interface SecurityService {
void logout();
- // TODO: define Callable<type>
Callable associateWith(Callable callable);
void authorize(ResourceOperation resourceOperation);
@@ -102,80 +91,4 @@ public interface SecurityService {
PostProcessor getPostProcessor();
- /**
- * this method would never return null, it either throws an exception or returns an object
- */
- static <T> T getObjectOfTypeFromClassName(String className, Class<T> expectedClazz) {
- Class actualClass;
- try {
- actualClass = ClassLoadUtil.classFromName(className);
- } catch (Exception e) {
- throw new GemFireSecurityException("Instance could not be obtained, " + e, e);
- }
-
- if (!expectedClazz.isAssignableFrom(actualClass)) {
- throw new GemFireSecurityException(
- "Instance could not be obtained. Expecting a " + expectedClazz.getName() + " class.");
- }
-
- try {
- return (T) actualClass.newInstance();
- } catch (Exception e) {
- throw new GemFireSecurityException(
- "Instance could not be obtained. Error instantiating " + actualClass.getName(), e);
- }
- }
-
- /**
- * this method would never return null, it either throws an exception or returns an object
- *
- * TODO: expectedClazz is unused
- */
- static <T> T getObjectOfTypeFromFactoryMethod(String factoryMethodName, Class<T> expectedClazz) {
- T actualObject;
- try {
- Method factoryMethod = ClassLoadUtil.methodFromName(factoryMethodName);
- actualObject = (T) factoryMethod.invoke(null, (Object[]) null);
- } catch (Exception e) {
- throw new GemFireSecurityException("Instance could not be obtained from " + factoryMethodName,
- e);
- }
-
- if (actualObject == null) {
- throw new GemFireSecurityException(
- "Instance could not be obtained from " + factoryMethodName);
- }
-
- return actualObject;
- }
-
- /**
- * this method would never return null, it either throws an exception or returns an object
- *
- * @return an object of type expectedClazz. This method would never return null. It either returns
- * an non-null object or throws exception.
- */
- static <T> T getObjectOfType(String classOrMethod, Class<T> expectedClazz) {
- T object;
- try {
- object = getObjectOfTypeFromClassName(classOrMethod, expectedClazz);
- } catch (Exception ignore) {
- object = getObjectOfTypeFromFactoryMethod(classOrMethod, expectedClazz);
- }
- return object;
- }
-
- static Properties getCredentials(Properties securityProps) {
- Properties credentials = null;
- if (securityProps.containsKey(ResourceConstants.USER_NAME)
- && securityProps.containsKey(ResourceConstants.PASSWORD)) {
- credentials = new Properties();
- credentials.setProperty(ResourceConstants.USER_NAME,
- securityProps.getProperty(ResourceConstants.USER_NAME));
- credentials.setProperty(ResourceConstants.PASSWORD,
- securityProps.getProperty(ResourceConstants.PASSWORD));
- }
- return credentials;
- }
-
}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/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 306e25e..dffe17c 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
@@ -14,13 +14,13 @@
*/
package org.apache.geode.internal.security;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTHENTICATOR;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTHENTICATOR;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_SHIRO_INIT;
-import org.apache.commons.lang.StringUtils;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.cache.CacheConfig;
import org.apache.geode.internal.cache.GemFireCacheImpl;
@@ -75,7 +75,7 @@ public class SecurityServiceFactory {
switch (type) {
case CUSTOM:
String shiroConfig = getProperty(securityConfig, SECURITY_SHIRO_INIT);
- if (StringUtils.isNotBlank(shiroConfig)) {
+ if (isNotBlank(shiroConfig)) {
ConfigInitialization configInitialization = new ConfigInitialization(shiroConfig);
configInitialization.initialize();
}
@@ -133,8 +133,8 @@ public class SecurityServiceFactory {
}
String securityManagerConfig = getProperty(securityConfig, SECURITY_MANAGER);
- if (StringUtils.isNotBlank(securityManagerConfig)) {
- securityManager = SecurityService.getObjectOfTypeFromClassName(securityManagerConfig,
+ if (isNotBlank(securityManagerConfig)) {
+ securityManager = CallbackInstantiator.getObjectOfTypeFromClassName(securityManagerConfig,
SecurityManager.class);
}
@@ -147,9 +147,9 @@ public class SecurityServiceFactory {
}
String postProcessorConfig = getProperty(securityConfig, SECURITY_POST_PROCESSOR);
- if (StringUtils.isNotBlank(postProcessorConfig)) {
- postProcessor =
- SecurityService.getObjectOfTypeFromClassName(postProcessorConfig, PostProcessor.class);
+ if (isNotBlank(postProcessorConfig)) {
+ postProcessor = CallbackInstantiator.getObjectOfTypeFromClassName(postProcessorConfig,
+ PostProcessor.class);
}
return postProcessor;
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/main/java/org/apache/geode/internal/security/shiro/CustomAuthRealm.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/shiro/CustomAuthRealm.java b/geode-core/src/main/java/org/apache/geode/internal/security/shiro/CustomAuthRealm.java
index ff30882..51449fd 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/security/shiro/CustomAuthRealm.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/security/shiro/CustomAuthRealm.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.security.shiro;
import java.io.Serializable;
import java.util.Properties;
+import org.apache.geode.internal.security.CallbackInstantiator;
import org.apache.geode.security.ResourcePermission;
import org.apache.geode.security.SecurityManager;
import org.apache.shiro.authc.AuthenticationException;
@@ -28,8 +29,6 @@ import org.apache.shiro.authz.Permission;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
-import org.apache.geode.internal.security.SecurityService;
-
public class CustomAuthRealm extends AuthorizingRealm {
private static final String REALM_NAME = "CUSTOMAUTHREALM";
@@ -54,8 +53,8 @@ public class CustomAuthRealm extends AuthorizingRealm {
* @param securityProperties the security properties to initialize SecurityManager with
*/
public CustomAuthRealm(String authenticatorFactory, Properties securityProperties) {
- this.securityManager =
- SecurityService.getObjectOfTypeFromClassName(authenticatorFactory, SecurityManager.class);
+ this.securityManager = CallbackInstantiator.getObjectOfTypeFromClassName(authenticatorFactory,
+ SecurityManager.class);
this.securityManager.init(securityProperties);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/test/java/org/apache/geode/internal/security/CallbackInstantiatorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/security/CallbackInstantiatorTest.java b/geode-core/src/test/java/org/apache/geode/internal/security/CallbackInstantiatorTest.java
new file mode 100644
index 0000000..accad91
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/security/CallbackInstantiatorTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.security;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.geode.security.GemFireSecurityException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class CallbackInstantiatorTest {
+
+ private static final String STRING = "STRING";
+ private static final String NULL_STRING = null;
+ private static final String STRING_NON_STATIC = "STRING_NON_STATIC";
+ private static final Boolean BOOLEAN = Boolean.TRUE;
+
+ @Test
+ public void testGetObjectFromConstructor() {
+ String string = CallbackInstantiator.getObjectOfType(String.class.getName(), String.class);
+ assertThat(string).isNotNull().isEqualTo("");
+
+ CharSequence charSequence =
+ CallbackInstantiator.getObjectOfType(String.class.getName(), CharSequence.class);
+ assertThat(charSequence).isNotNull().isEqualTo("");
+
+ assertThatThrownBy(
+ () -> CallbackInstantiator.getObjectOfType("com.abc.testString", String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+
+ assertThatThrownBy(
+ () -> CallbackInstantiator.getObjectOfType(String.class.getName(), Boolean.class))
+ .isInstanceOf(GemFireSecurityException.class);
+
+ assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType("", String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+
+ assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType(null, String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+
+ assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType(" ", String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+ }
+
+ @Test
+ public void testGetObjectFromFactoryMethod() {
+ String string = CallbackInstantiator.getObjectOfType(Factories.class.getName() + ".getString",
+ String.class);
+ assertThat(string).isNotNull().isEqualTo(STRING);
+
+ CharSequence charSequence = CallbackInstantiator
+ .getObjectOfType(Factories.class.getName() + ".getString", String.class);
+ assertThat(charSequence).isNotNull().isEqualTo(STRING);
+
+ assertThatThrownBy(() -> CallbackInstantiator
+ .getObjectOfType(Factories.class.getName() + ".getStringNonStatic", String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+
+ assertThatThrownBy(() -> CallbackInstantiator
+ .getObjectOfType(Factories.class.getName() + ".getNullString", String.class))
+ .isInstanceOf(GemFireSecurityException.class);
+ }
+
+ private static class Factories {
+
+ public static String getString() {
+ return STRING;
+ }
+
+ public static String getNullString() {
+ return NULL_STRING;
+ }
+
+ public String getStringNonStatic() {
+ return STRING_NON_STATIC;
+ }
+
+ public static Boolean getBoolean() {
+ return BOOLEAN;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/afa21b00/geode-core/src/test/java/org/apache/geode/internal/security/SecurityServiceTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/security/SecurityServiceTest.java b/geode-core/src/test/java/org/apache/geode/internal/security/SecurityServiceTest.java
index 0c28496..46a9f1a 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/security/SecurityServiceTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/security/SecurityServiceTest.java
@@ -18,15 +18,11 @@ import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIE
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTHENTICATOR;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_SHIRO_INIT;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.security.GemFireSecurityException;
import org.apache.geode.security.TestSecurityManager;
import org.apache.geode.test.junit.categories.UnitTest;
import org.apache.shiro.SecurityUtils;
@@ -60,55 +56,11 @@ public class SecurityServiceTest {
}
@Test
- public void testGetObjectFromConstructor() {
- String string = SecurityService.getObjectOfType(String.class.getName(), String.class);
- assertNotNull(string);
-
- CharSequence charSequence =
- SecurityService.getObjectOfType(String.class.getName(), CharSequence.class);
- assertNotNull(charSequence);
-
- assertThatThrownBy(() -> SecurityService.getObjectOfType("com.abc.testString", String.class))
- .isInstanceOf(GemFireSecurityException.class);
-
- assertThatThrownBy(() -> SecurityService.getObjectOfType(String.class.getName(), Boolean.class))
- .isInstanceOf(GemFireSecurityException.class);
-
- assertThatThrownBy(() -> SecurityService.getObjectOfType("", String.class))
- .isInstanceOf(GemFireSecurityException.class);
-
- assertThatThrownBy(() -> SecurityService.getObjectOfType(null, String.class))
- .isInstanceOf(GemFireSecurityException.class);
-
- assertThatThrownBy(() -> SecurityService.getObjectOfType(" ", String.class))
- .isInstanceOf(GemFireSecurityException.class);
- }
-
- @Test
- public void testGetObjectFromFactoryMethod() {
- String string =
- SecurityService.getObjectOfType(Factories.class.getName() + ".getString", String.class);
- assertNotNull(string);
-
- CharSequence charSequence =
- SecurityService.getObjectOfType(Factories.class.getName() + ".getString", String.class);
- assertNotNull(charSequence);
-
- assertThatThrownBy(() -> SecurityService
- .getObjectOfType(Factories.class.getName() + ".getStringNonStatic", String.class))
- .isInstanceOf(GemFireSecurityException.class);
-
- assertThatThrownBy(() -> SecurityService
- .getObjectOfType(Factories.class.getName() + ".getNullString", String.class))
- .isInstanceOf(GemFireSecurityException.class);
- }
-
- @Test
public void testInitialSecurityFlags() {
// initial state of SecurityService
- assertFalse(this.securityService.isIntegratedSecurity());
- assertFalse(this.securityService.isClientSecurityRequired());
- assertFalse(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isFalse();
+ assertThat(this.securityService.isClientSecurityRequired()).isFalse();
+ assertThat(this.securityService.isPeerSecurityRequired()).isFalse();
}
@Test
@@ -119,9 +71,9 @@ public class SecurityServiceTest {
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertTrue(this.securityService.isIntegratedSecurity());
- assertTrue(this.securityService.isClientSecurityRequired());
- assertTrue(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isTrue();
+ assertThat(this.securityService.isClientSecurityRequired()).isTrue();
+ assertThat(this.securityService.isPeerSecurityRequired()).isTrue();
}
@Test
@@ -129,9 +81,9 @@ public class SecurityServiceTest {
this.properties.setProperty(SECURITY_CLIENT_AUTHENTICATOR, "org.abc.test");
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertFalse(this.securityService.isIntegratedSecurity());
- assertTrue(this.securityService.isClientSecurityRequired());
- assertFalse(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isFalse();
+ assertThat(this.securityService.isClientSecurityRequired()).isTrue();
+ assertThat(this.securityService.isPeerSecurityRequired()).isFalse();
}
@Test
@@ -139,9 +91,9 @@ public class SecurityServiceTest {
this.properties.setProperty(SECURITY_PEER_AUTHENTICATOR, "org.abc.test");
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertFalse(this.securityService.isIntegratedSecurity());
- assertFalse(this.securityService.isClientSecurityRequired());
- assertTrue(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isFalse();
+ assertThat(this.securityService.isClientSecurityRequired()).isFalse();
+ assertThat(this.securityService.isPeerSecurityRequired()).isTrue();
}
@Test
@@ -151,9 +103,9 @@ public class SecurityServiceTest {
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertFalse(this.securityService.isIntegratedSecurity());
- assertTrue(this.securityService.isClientSecurityRequired());
- assertTrue(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isFalse();
+ assertThat(this.securityService.isClientSecurityRequired()).isTrue();
+ assertThat(this.securityService.isPeerSecurityRequired()).isTrue();
}
@Test
@@ -162,14 +114,14 @@ public class SecurityServiceTest {
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertTrue(this.securityService.isIntegratedSecurity());
- assertTrue(this.securityService.isClientSecurityRequired());
- assertTrue(this.securityService.isPeerSecurityRequired());
+ assertThat(this.securityService.isIntegratedSecurity()).isTrue();
+ assertThat(this.securityService.isClientSecurityRequired()).isTrue();
+ assertThat(this.securityService.isPeerSecurityRequired()).isTrue();
}
@Test
public void testNoInit() {
- assertFalse(this.securityService.isIntegratedSecurity());
+ assertThat(this.securityService.isIntegratedSecurity()).isFalse();
}
@Test
@@ -177,51 +129,7 @@ public class SecurityServiceTest {
SecurityUtils.setSecurityManager(new DefaultSecurityManager());
this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- assertTrue(this.securityService.isIntegratedSecurity());
+ assertThat(this.securityService.isIntegratedSecurity()).isTrue();
}
- // @Test
- // public void testSetSecurityManager() {
- // // initially
- // assertFalse(this.securityService.isIntegratedSecurity());
- //
- // // init with client authenticator
- // this.properties.setProperty(SECURITY_CLIENT_AUTHENTICATOR, "org.abc.test");
- // this.securityService = SecurityServiceFactory.create(null, this.distributionConfig);
- //
- // assertFalse(this.securityService.isIntegratedSecurity());
- // assertTrue(this.securityService.isClientSecurityRequired());
- // assertFalse(this.securityService.isPeerSecurityRequired());
- //
- // // set a security manager
- // this.securityService.setSecurityManager(new SimpleTestSecurityManager());
- // assertTrue(this.securityService.isIntegratedSecurity());
- // assertTrue(this.securityService.isClientSecurityRequired());
- // assertTrue(this.securityService.isPeerSecurityRequired());
- // assertFalse(this.securityService.needPostProcess());
- //
- // // set a post processor
- // this.securityService.setPostProcessor(new TestPostProcessor());
- // assertTrue(this.securityService.isIntegratedSecurity());
- // assertTrue(this.securityService.needPostProcess());
- // }
-
- private static class Factories {
-
- public static String getString() {
- return new String();
- }
-
- public static String getNullString() {
- return null;
- }
-
- public String getStringNonStatic() {
- return new String();
- }
-
- public static Boolean getBoolean() {
- return Boolean.TRUE;
- }
- }
}