You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2016/03/10 23:19:27 UTC
incubator-geode git commit: GEODE-17: Formatting changes
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-17-2 a84def5fe -> cdc49fec9
GEODE-17: Formatting changes
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/cdc49fec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/cdc49fec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/cdc49fec
Branch: refs/heads/feature/GEODE-17-2
Commit: cdc49fec94ba40e5558c74b9e74209280e0c3b0d
Parents: a84def5
Author: Jens Deppe <jd...@pivotal.io>
Authored: Thu Mar 10 14:19:21 2016 -0800
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Thu Mar 10 14:19:21 2016 -0800
----------------------------------------------------------------------
...rDistributedSystemMXBeanIntegrationTest.java | 20 +-
...erationForRegionCommandsIntegrationTest.java | 21 +-
.../CacheServerMBeanSecurityJUnitTest.java | 23 +-
.../security/JMXConnectionConfiguration.java | 1 +
.../internal/security/JSONAuthorization.java | 282 +++++++++----------
...JSONAuthorizationDetailsIntegrationTest.java | 6 +-
.../JsonAuthorizationMBeanServerStartRule.java | 2 +-
.../security/MBeanServerConnectionRule.java | 19 +-
.../security/MemberMBeanSecurityJUnitTest.java | 5 +-
9 files changed, 190 insertions(+), 189 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForDistributedSystemMXBeanIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForDistributedSystemMXBeanIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForDistributedSystemMXBeanIntegrationTest.java
index 320a5d9..871b74a 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForDistributedSystemMXBeanIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForDistributedSystemMXBeanIntegrationTest.java
@@ -16,16 +16,14 @@
*/
package com.gemstone.gemfire.management.internal.security;
-import static org.junit.Assert.*;
-
-import javax.management.remote.JMXPrincipal;
-
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-import com.gemstone.gemfire.util.test.TestUtil;
+import javax.management.remote.JMXPrincipal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Tests <code>JSONAuthorization.authorizeOperation(...)</code> for <code>DistributedSystemMXBean</code> operations.
@@ -34,16 +32,16 @@ import com.gemstone.gemfire.util.test.TestUtil;
public class AuthorizeOperationForDistributedSystemMXBeanIntegrationTest {
@Test
- public void returnsFalseForUnauthorizedUser() throws Exception {
+ public void returnsFalseForUnauthorizedUser() throws Exception {
JSONAuthorization authorization = new JSONAuthorization("auth1.json");
authorization.init(new JMXPrincipal("tushark"), null, null);
-
+
ResourceOperationContext context = new ResourceOperationContext(null, "QUERY");
boolean result = authorization.authorizeOperation(null, context);
assertTrue(result);
-
+
context = new ResourceOperationContext(null, "MANAGE");
- result = authorization.authorizeOperation(null,context);
+ result = authorization.authorizeOperation(null, context);
assertFalse(result);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
index 71ef824..61bf767 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
@@ -37,7 +37,9 @@ import java.lang.management.ManagementFactory;
import java.util.Properties;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Tests <code>JSONAuthorization.authorizeOperation(...)</code> for Region commands.
@@ -45,17 +47,17 @@ import static org.junit.Assert.*;
@Category(IntegrationTest.class)
@SuppressWarnings("deprecation")
public class AuthorizeOperationForRegionCommandsIntegrationTest {
-
+
private GemFireCacheImpl cache;
private DistributedSystem ds;
private int jmxManagerPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
@Rule
public TestName testName = new TestName();
-
+
@Rule
public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
-
+
@Before
public void setUp() {
Properties properties = new Properties();
@@ -67,7 +69,8 @@ public class AuthorizeOperationForRegionCommandsIntegrationTest {
properties.put(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(this.jmxManagerPort));
properties.put(DistributionConfig.HTTP_SERVICE_PORT_NAME, "0");
properties.put(DistributionConfig.SECURITY_CLIENT_ACCESSOR_NAME, JSONAuthorization.class.getName() + ".create");
- properties.put(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, JSONAuthorization.class.getName() + ".create");
+ properties.put(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME,
+ JSONAuthorization.class.getName() + ".create");
this.ds = DistributedSystem.connect(properties);
this.cache = (GemFireCacheImpl) CacheFactory.create(ds);
@@ -84,14 +87,14 @@ public class AuthorizeOperationForRegionCommandsIntegrationTest {
ds = null;
}
}
-
+
@Test
public void testAuthorizeOperationWithRegionOperations() throws Exception {
JSONAuthorization authorization = new JSONAuthorization("auth3.json");
authorization.init(new JMXPrincipal("tushark"), null, null);
-
+
checkAccessControlMBean();
-
+
CLIOperationContext cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
boolean result = authorization.authorizeOperation(null, cliContext);
assertTrue("Operation not authorized", result);
@@ -115,6 +118,6 @@ public class AuthorizeOperationForRegionCommandsIntegrationTest {
Set<ObjectName> names = platformMBeanServer.queryNames(name, null);
assertFalse(names.isEmpty());
assertEquals(1, names.size());
- assertEquals(name,names.iterator().next());
+ assertEquals(name, names.iterator().next());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/CacheServerMBeanSecurityJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/CacheServerMBeanSecurityJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/CacheServerMBeanSecurityJUnitTest.java
index 077ddac..d233d55 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/CacheServerMBeanSecurityJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/CacheServerMBeanSecurityJUnitTest.java
@@ -43,7 +43,8 @@ public class CacheServerMBeanSecurityJUnitTest {
private MBeanServerConnection con;
@ClassRule
- public static JsonAuthorizationMBeanServerStartRule serverRule = new JsonAuthorizationMBeanServerStartRule(jmxManagerPort, "cacheServer.json");
+ public static JsonAuthorizationMBeanServerStartRule serverRule = new JsonAuthorizationMBeanServerStartRule(
+ jmxManagerPort, "cacheServer.json");
@Rule
public MBeanServerConnectionRule connectionRule = new MBeanServerConnectionRule(jmxManagerPort);
@@ -51,7 +52,8 @@ public class CacheServerMBeanSecurityJUnitTest {
@Before
public void setUp() throws Exception {
//assertThat(cache.getCacheServers()).hasSize(1);
- cacheServerMXBean = (CacheServerMXBean)connectionRule.getProxyMBean(CacheServerMXBean.class, "GemFire:service=CacheServer,*");
+ cacheServerMXBean = (CacheServerMXBean) connectionRule.getProxyMBean(CacheServerMXBean.class,
+ "GemFire:service=CacheServer,*");
con = connectionRule.getMBeanServerConnection();
}
@@ -60,14 +62,12 @@ public class CacheServerMBeanSecurityJUnitTest {
*/
@Test
@JMXConnectionConfiguration(user = "superuser", password = "1234567")
- public void testNoAccessWithWhoever() throws Exception{
- assertThatThrownBy(
- () -> con.createMBean("FakeClassName", new ObjectName("GemFire", "name", "foo"))
- ).isInstanceOf(SecurityException.class);
-
- assertThatThrownBy(
- () -> con.unregisterMBean(new ObjectName("GemFire", "name", "foo"))
- ).isInstanceOf(SecurityException.class);
+ public void testNoAccessWithWhoever() throws Exception {
+ assertThatThrownBy(() -> con.createMBean("FakeClassName", new ObjectName("GemFire", "name", "foo")))
+ .isInstanceOf(SecurityException.class);
+
+ assertThatThrownBy(() -> con.unregisterMBean(new ObjectName("GemFire", "name", "foo")))
+ .isInstanceOf(SecurityException.class);
}
@@ -111,7 +111,8 @@ public class CacheServerMBeanSecurityJUnitTest {
@Test
@JMXConnectionConfiguration(user = "stranger", password = "1234567")
public void testQueryBean() throws MalformedObjectNameException, IOException {
- Set<ObjectInstance> objects = con.queryMBeans(ObjectName.getInstance(ResourceConstants.OBJECT_NAME_ACCESSCONTROL), null);
+ Set<ObjectInstance> objects = con.queryMBeans(ObjectName.getInstance(ResourceConstants.OBJECT_NAME_ACCESSCONTROL),
+ null);
assertThat(objects.size()).isEqualTo(0); // no AccessControlMBean in the query result
objects = con.queryMBeans(ObjectName.getInstance("GemFire:service=CacheServer,*"), null);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JMXConnectionConfiguration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JMXConnectionConfiguration.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JMXConnectionConfiguration.java
index d61a7c5..9dca55e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JMXConnectionConfiguration.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JMXConnectionConfiguration.java
@@ -29,5 +29,6 @@ import java.lang.annotation.Target;
@Target({ElementType.METHOD})
public @interface JMXConnectionConfiguration {
String user();
+
String password();
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
index 98c02f3..4b8245c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
@@ -44,47 +44,47 @@ import java.util.Set;
public class JSONAuthorization implements AccessControl, Authenticator {
- public static class Role{
- String[] permissions;
- String name;
- String regionName;
- String serverGroup;
- }
+ public static class Role {
+ String[] permissions;
+ String name;
+ String regionName;
+ String serverGroup;
+ }
- public static class User{
- String name;
- Role[] roles;
- String pwd;
- }
+ public static class User {
+ String name;
+ Role[] roles;
+ String pwd;
+ }
- private static Map<String,User> acl = null;
+ private static Map<String, User> acl = null;
- public static JSONAuthorization create() throws IOException, JSONException {
- return new JSONAuthorization();
- }
+ public static JSONAuthorization create() throws IOException, JSONException {
+ return new JSONAuthorization();
+ }
public JSONAuthorization() {
}
- public JSONAuthorization(String jsonFileName) throws IOException, JSONException{
- setUpWithJsonFile(jsonFileName);
- }
+ public JSONAuthorization(String jsonFileName) throws IOException, JSONException {
+ setUpWithJsonFile(jsonFileName);
+ }
- public static void setUpWithJsonFile(String jsonFileName) throws IOException, JSONException {
- String json = readFile(TestUtil.getResourcePath(JSONAuthorization.class, jsonFileName));
- readSecurityDescriptor(json);
- }
+ public static void setUpWithJsonFile(String jsonFileName) throws IOException, JSONException {
+ String json = readFile(TestUtil.getResourcePath(JSONAuthorization.class, jsonFileName));
+ readSecurityDescriptor(json);
+ }
- private static void readSecurityDescriptor(String json) throws IOException, JSONException {
- JSONObject jsonBean = new JSONObject(json);
- acl = new HashMap<String,User>();
- Map<String,Role> roleMap = readRoles(jsonBean);
- readUsers(acl,jsonBean,roleMap);
- }
+ private static void readSecurityDescriptor(String json) throws IOException, JSONException {
+ JSONObject jsonBean = new JSONObject(json);
+ acl = new HashMap<String, User>();
+ Map<String, Role> roleMap = readRoles(jsonBean);
+ readUsers(acl, jsonBean, roleMap);
+ }
- public static Set<OperationCode> getAuthorizedOps(User user, ResourceOperationContext context) {
+ public static Set<OperationCode> getAuthorizedOps(User user, ResourceOperationContext context) {
Set<OperationCode> codeList = new HashSet<OperationCode>();
- for(Role role : user.roles) {
+ for (Role role : user.roles) {
for (String perm : role.permissions) {
OperationCode code = OperationCode.valueOf(perm);
if (role.regionName == null && role.serverGroup == null) {
@@ -97,7 +97,8 @@ public class JSONAuthorization implements AccessControl, Authenticator {
if (region != null && region.equals(role.regionName)) {
addPermissions(code, codeList);
} else {
- LogService.getLogger().info("Not adding permission " + code + " since region=" + region + " does not match");
+ LogService.getLogger()
+ .info("Not adding permission " + code + " since region=" + region + " does not match");
}
}
}
@@ -115,110 +116,106 @@ public class JSONAuthorization implements AccessControl, Authenticator {
codeList.add(code);
}
- private static void readUsers(Map<String, User> acl, JSONObject jsonBean,
- Map<String, Role> roleMap) throws JSONException {
- JSONArray array = jsonBean.getJSONArray("users");
- for(int i=0;i<array.length();i++){
- JSONObject obj = array.getJSONObject(i);
- User user = new User();
- user.name = obj.getString("name");
- if(obj.has("password")) {
+ private static void readUsers(Map<String, User> acl, JSONObject jsonBean,
+ Map<String, Role> roleMap) throws JSONException {
+ JSONArray array = jsonBean.getJSONArray("users");
+ for (int i = 0; i < array.length(); i++) {
+ JSONObject obj = array.getJSONObject(i);
+ User user = new User();
+ user.name = obj.getString("name");
+ if (obj.has("password")) {
user.pwd = obj.getString("password");
} else {
user.pwd = user.name;
}
- JSONArray ops = obj.getJSONArray("roles");
- user.roles = new Role[ops.length()];
- for(int j=0;j<ops.length();j++){
- String roleName = ops.getString(j);
- user.roles[j] = roleMap.get(roleName);
- if(user.roles[j]==null){
- throw new RuntimeException("Role not present " + roleName);
- }
- }
- acl.put(user.name, user);
- }
- }
-
- private static Map<String, Role> readRoles(JSONObject jsonBean) throws JSONException {
- Map<String,Role> roleMap = new HashMap<String,Role>();
- JSONArray array = jsonBean.getJSONArray("roles");
- for(int i=0;i<array.length();i++){
- JSONObject obj = array.getJSONObject(i);
- Role role = new Role();
- role.name = obj.getString("name");
-
- if(obj.has("operationsAllowed")){
- JSONArray ops = obj.getJSONArray("operationsAllowed");
- role.permissions = new String[ops.length()];
- for(int j=0;j<ops.length();j++){
- role.permissions[j] = ops.getString(j);
- }
- }else {
- if (!obj.has("inherit"))
- throw new RuntimeException(
- "Role "
- + role.name
- + " does not have any permission neither it inherits any parent role");
- }
-
- roleMap.put(role.name,role);
-
- if(obj.has("region")){
- role.regionName = obj.getString("region");
- }
-
- if(obj.has("serverGroup")){
- role.serverGroup = obj.getString("serverGroup");
- }
- }
-
- for(int i=0;i<array.length();i++){
- JSONObject obj = array.getJSONObject(i);
- String name = obj.getString("name");
- Role role = roleMap.get(name);
- if (role == null) {
- throw new RuntimeException("Role not present "
- + role);
- }
- if(obj.has("inherit")){
- JSONArray parentRoles = obj.getJSONArray("inherit");
- for (int m = 0; m < parentRoles.length(); m++) {
- String parentRoleName = parentRoles.getString(m);
- Role parentRole = roleMap.get(parentRoleName);
- if (parentRole == null) {
- throw new RuntimeException("Role not present "
- + parentRoleName);
- }
- int oldLenth=0;
- if(role.permissions!=null)
- oldLenth = role.permissions.length;
- int newLength = oldLenth + parentRole.permissions.length;
- String[] str = new String[newLength];
- int k = 0;
- if(role.permissions!=null) {
- for (; k < role.permissions.length; k++) {
- str[k] = role.permissions[k];
- }
- }
-
- for (int l = 0; l < parentRole.permissions.length; l++) {
- str[k + l] = parentRole.permissions[l];
- }
- role.permissions = str;
- }
- }
-
- }
- return roleMap;
- }
-
- public static Map<String, User> getAcl() {
- return acl;
- }
-
- private Principal principal=null;
+ JSONArray ops = obj.getJSONArray("roles");
+ user.roles = new Role[ops.length()];
+ for (int j = 0; j < ops.length(); j++) {
+ String roleName = ops.getString(j);
+ user.roles[j] = roleMap.get(roleName);
+ if (user.roles[j] == null) {
+ throw new RuntimeException("Role not present " + roleName);
+ }
+ }
+ acl.put(user.name, user);
+ }
+ }
+
+ private static Map<String, Role> readRoles(JSONObject jsonBean) throws JSONException {
+ Map<String, Role> roleMap = new HashMap<String, Role>();
+ JSONArray array = jsonBean.getJSONArray("roles");
+ for (int i = 0; i < array.length(); i++) {
+ JSONObject obj = array.getJSONObject(i);
+ Role role = new Role();
+ role.name = obj.getString("name");
+
+ if (obj.has("operationsAllowed")) {
+ JSONArray ops = obj.getJSONArray("operationsAllowed");
+ role.permissions = new String[ops.length()];
+ for (int j = 0; j < ops.length(); j++) {
+ role.permissions[j] = ops.getString(j);
+ }
+ } else {
+ if (!obj.has("inherit")) {
+ throw new RuntimeException(
+ "Role " + role.name + " does not have any permission neither it inherits any parent role");
+ }
+ }
+
+ roleMap.put(role.name, role);
+
+ if (obj.has("region")) {
+ role.regionName = obj.getString("region");
+ }
+
+ if (obj.has("serverGroup")) {
+ role.serverGroup = obj.getString("serverGroup");
+ }
+ }
+
+ for (int i = 0; i < array.length(); i++) {
+ JSONObject obj = array.getJSONObject(i);
+ String name = obj.getString("name");
+ Role role = roleMap.get(name);
+ if (role == null) {
+ throw new RuntimeException("Role not present " + role);
+ }
+ if (obj.has("inherit")) {
+ JSONArray parentRoles = obj.getJSONArray("inherit");
+ for (int m = 0; m < parentRoles.length(); m++) {
+ String parentRoleName = parentRoles.getString(m);
+ Role parentRole = roleMap.get(parentRoleName);
+ if (parentRole == null) {
+ throw new RuntimeException("Role not present " + parentRoleName);
+ }
+ int oldLenth = 0;
+ if (role.permissions != null) oldLenth = role.permissions.length;
+ int newLength = oldLenth + parentRole.permissions.length;
+ String[] str = new String[newLength];
+ int k = 0;
+ if (role.permissions != null) {
+ for (; k < role.permissions.length; k++) {
+ str[k] = role.permissions[k];
+ }
+ }
+
+ for (int l = 0; l < parentRole.permissions.length; l++) {
+ str[k + l] = parentRole.permissions[l];
+ }
+ role.permissions = str;
+ }
+ }
+
+ }
+ return roleMap;
+ }
+
+ public static Map<String, User> getAcl() {
+ return acl;
+ }
+
+ private Principal principal = null;
@Override
public void close() {
@@ -228,27 +225,25 @@ public class JSONAuthorization implements AccessControl, Authenticator {
@Override
public boolean authorizeOperation(String arg0, OperationContext context) {
- if(principal!=null) {
+ if (principal != null) {
User user = acl.get(principal.getName());
- if(user!=null) {
+ if (user != null) {
LogService.getLogger().info("Context received " + context);
- ResourceOperationContext ctx = (ResourceOperationContext)context;
+ ResourceOperationContext ctx = (ResourceOperationContext) context;
LogService.getLogger().info("Checking for code " + ctx.getOperationCode());
//TODO : This is for un-annotated commands
- if(ctx.getOperationCode()==null)
- return true;
+ if (ctx.getOperationCode() == null) return true;
boolean found = false;
- for(OperationCode code : getAuthorizedOps(user, (ResourceOperationContext) context)) {
- if(ctx.getOperationCode().equals(code)){
- found =true;
+ for (OperationCode code : getAuthorizedOps(user, (ResourceOperationContext) context)) {
+ if (ctx.getOperationCode().equals(code)) {
+ found = true;
LogService.getLogger().info("found code " + code.toString());
break;
}
}
- if(found)
- return true;
+ if (found) return true;
LogService.getLogger().info("Did not find code " + ctx.getOperationCode());
return false;
}
@@ -266,10 +261,9 @@ public class JSONAuthorization implements AccessControl, Authenticator {
String user = props.getProperty(ResourceConstants.USER_NAME);
String pwd = props.getProperty(ResourceConstants.PASSWORD);
User userObj = acl.get(user);
- if(userObj==null)
- throw new AuthenticationFailedException("Wrong username/password");
- LogService.getLogger().info("User="+user + " pwd="+pwd);
- if (user!=null && !userObj.pwd.equals(pwd) && !"".equals(user))
+ if (userObj == null) throw new AuthenticationFailedException("Wrong username/password");
+ LogService.getLogger().info("User=" + user + " pwd=" + pwd);
+ if (user != null && !userObj.pwd.equals(pwd) && !"".equals(user))
throw new AuthenticationFailedException("Wrong username/password");
LogService.getLogger().info("Authentication successful!! for " + user);
return new JMXPrincipal(user);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
index 955e64b..5e89948 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
@@ -55,7 +55,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
public void testUserAndRoleRegionServerGroup() throws Exception {
new JSONAuthorization("testUserAndRoleRegionServerGroup.json");
Map<String, User> acl = JSONAuthorization.getAcl();
-
+
assertNotNull(acl);
assertEquals(1, acl.size());
User user = acl.get("tushark");
@@ -74,7 +74,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
public void testUserMultipleRole() throws Exception {
new JSONAuthorization("testUserMultipleRole.json");
Map<String, User> acl = JSONAuthorization.getAcl();
-
+
assertNotNull(acl);
assertEquals(1, acl.size());
User user = acl.get("tushark");
@@ -107,7 +107,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
public void testInheritRole() throws Exception {
new JSONAuthorization("testInheritRole.json");
Map<String, User> acl = JSONAuthorization.getAcl();
-
+
assertNotNull(acl);
assertEquals(3, acl.size());
User user = acl.get("tushark");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JsonAuthorizationMBeanServerStartRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JsonAuthorizationMBeanServerStartRule.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JsonAuthorizationMBeanServerStartRule.java
index 2ac3fa1..933b27c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JsonAuthorizationMBeanServerStartRule.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JsonAuthorizationMBeanServerStartRule.java
@@ -28,7 +28,7 @@ public class JsonAuthorizationMBeanServerStartRule extends ExternalResource {
private int jmxManagerPort;
private String jsonFile;
- public JsonAuthorizationMBeanServerStartRule(int jmxManagerPort, String jsonFile){
+ public JsonAuthorizationMBeanServerStartRule(int jmxManagerPort, String jsonFile) {
this.jmxManagerPort = jmxManagerPort;
this.jsonFile = jsonFile;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MBeanServerConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MBeanServerConnectionRule.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MBeanServerConnectionRule.java
index 68ad261..ed4661c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MBeanServerConnectionRule.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MBeanServerConnectionRule.java
@@ -37,7 +37,6 @@ import java.util.Set;
/**
* Class which eases the creation of MBeans for security testing. When combined with {@link JMXConnectionConfiguration}
* it allows for the creation of per-test connections with different user/password combinations.
- *
*/
public class MBeanServerConnectionRule extends DescribedExternalResource {
@@ -48,6 +47,7 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
/**
* Rule constructor
+ *
* @param port The JMX server port to connect to
*/
public MBeanServerConnectionRule(int port) {
@@ -56,29 +56,32 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
/**
* Retrieve a new proxy MBean
+ *
* @return A new proxy MBean of the same type with which the class was constructed
*/
public Object getProxyMBean(Class proxyClass, String beanQueryName) throws MalformedObjectNameException, IOException {
ObjectName name = null;
QueryExp query = null;
- if(proxyClass != null){
+ if (proxyClass != null) {
query = Query.isInstanceOf(Query.value(proxyClass.getName()));
}
- if(beanQueryName != null){
+ if (beanQueryName != null) {
name = ObjectName.getInstance(beanQueryName);
}
Set<ObjectInstance> beans = con.queryMBeans(name, query);
- if(beans.size() != 1){
- throw new RuntimeException("failed to find only one instance of "+proxyClass.getName()+" with name "+beanQueryName);
+ if (beans.size() != 1) {
+ throw new RuntimeException(
+ "failed to find only one instance of " + proxyClass.getName() + " with name " + beanQueryName);
}
- return JMX.newMXBeanProxy(con, ((ObjectInstance)beans.toArray()[0]).getObjectName(), proxyClass);
+ return JMX.newMXBeanProxy(con, ((ObjectInstance) beans.toArray()[0]).getObjectName(), proxyClass);
}
/**
* Retrieve a new proxy MBean
+ *
* @return A new proxy MBean of the same type with which the class was constructed
*/
public Object getProxyMBean(Class proxyClass) throws MalformedObjectNameException, IOException {
@@ -97,10 +100,10 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
protected void before(Description description) throws Throwable {
JMXConnectionConfiguration config = description.getAnnotation(JMXConnectionConfiguration.class);
Map<String, String[]> env = new HashMap<>();
- if(config!=null) {
+ if (config != null) {
String user = config.user();
String password = config.password();
- env.put(JMXConnector.CREDENTIALS, new String[] { user, password });
+ env.put(JMXConnector.CREDENTIALS, new String[]{user, password});
}
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + jmxServerPort + "/jmxrmi");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdc49fec/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MemberMBeanSecurityJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MemberMBeanSecurityJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MemberMBeanSecurityJUnitTest.java
index 4494acd..2882fcb 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MemberMBeanSecurityJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/MemberMBeanSecurityJUnitTest.java
@@ -37,14 +37,15 @@ public class MemberMBeanSecurityJUnitTest {
private MBeanServerConnection con;
@ClassRule
- public static JsonAuthorizationMBeanServerStartRule serverRule = new JsonAuthorizationMBeanServerStartRule(jmxManagerPort, "cacheServer.json");
+ public static JsonAuthorizationMBeanServerStartRule serverRule = new JsonAuthorizationMBeanServerStartRule(
+ jmxManagerPort, "cacheServer.json");
@Rule
public MBeanServerConnectionRule connectionRule = new MBeanServerConnectionRule(jmxManagerPort);
@Before
public void setUp() throws Exception {
- bean = (MemberMXBean)connectionRule.getProxyMBean(MemberMXBean.class);
+ bean = (MemberMXBean) connectionRule.getProxyMBean(MemberMXBean.class);
con = connectionRule.getMBeanServerConnection();
}