geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tush...@apache.org
Subject [53/79] incubator-geode git commit: Fix test : testAuthenticationUsingPropertiesBag Remvoed JSON template code from product
Date Tue, 03 Nov 2015 11:26:15 GMT
Fix test : testAuthenticationUsingPropertiesBag
Remvoed JSON template code from product


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/73be5635
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/73be5635
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/73be5635

Branch: refs/heads/feature/GEODE-17
Commit: 73be56354207d7e2bc1640fd76d7724b81a70bd6
Parents: 1393ad2
Author: Tushar Khairnar <tkhairnar@pivotal.io>
Authored: Thu Aug 27 13:10:17 2015 +0530
Committer: tushark <tushark@apache.org>
Committed: Tue Nov 3 16:52:43 2015 +0530

----------------------------------------------------------------------
 .../internal/security/JSONAuthorization.java    | 292 -------------------
 .../internal/security/JSONAuthCodeTest.java     | 184 ------------
 .../security/JSONAuthorizationTest.java         | 152 ----------
 .../security/ResourceOperationJUnit.java        |   7 +-
 4 files changed, 4 insertions(+), 631 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73be5635/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
deleted file mode 100644
index 5455818..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
+++ /dev/null
@@ -1,292 +0,0 @@
-package com.gemstone.gemfire.management.internal.security;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.security.Principal;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.management.remote.JMXPrincipal;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import com.gemstone.gemfire.GemFireConfigException;
-import com.gemstone.gemfire.LogWriter;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.operations.OperationContext;
-import com.gemstone.gemfire.distributed.DistributedMember;
-import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.management.internal.security.ResourceOperationContext.ResourceOperationCode;
-import com.gemstone.gemfire.security.AccessControl;
-import com.gemstone.gemfire.security.AuthenticationFailedException;
-import com.gemstone.gemfire.security.Authenticator;
-import com.gemstone.gemfire.security.NotAuthorizedException;
-
-public class JSONAuthorization implements AccessControl, Authenticator {
-	
-	public static class Role{
-		String[] permissions;
-		String name;
-		String regionName;
-		String serverGroup;		
-	}
-	
-	public static class User{
-		String name;
-		Role[] roles;
-		String pwd;
-	}
-	
-	private static Map<String,User> acl = null;
-	
-	public static JSONAuthorization create() throws IOException, JSONException {
-	  if(acl==null){
-	    readSecurityDescriptor(readDefault());
-	  }
-	  return new JSONAuthorization();
-	}
-	
-  public JSONAuthorization() {
-    if (acl == null) {
-      try {
-        readSecurityDescriptor(readDefault());
-      } catch (IOException e) {
-        throw new GemFireConfigException("Error creating JSONAuth", e);
-      } catch (JSONException e) {
-        throw new GemFireConfigException("Error creating JSONAuth", e);
-      }
-    }
-  }
-	
-	public static Set<ResourceOperationCode> getAuthorizedOps(User user, ResourceOperationContext
context) {
-    Set<ResourceOperationCode> codeList = new HashSet<ResourceOperationCode>();
-    for(Role role : user.roles) {
-      for (String perm : role.permissions) {
-        ResourceOperationCode code = ResourceOperationCode.parse(perm);
-        if (role.regionName == null && role.serverGroup == null) {
-          addPermissions(code, codeList);
-        } else if (role.regionName != null) {
-          LogService.getLogger().info("This role requires region=" + role.regionName);
-          if (context instanceof CLIOperationContext) {
-            CLIOperationContext cliContext = (CLIOperationContext) context;
-            String region = cliContext.getCommandOptions().get("region");
-            if (region != null && region.equals(role.regionName)) {
-              addPermissions(code, codeList);
-            } else {
-              LogService.getLogger().info("Not adding permission " + code + " since region="
+ region + " does not match");
-            }
-          }
-        }
-        // Same to be implemented for ServerGroup
-      }
-    }
-    LogService.getLogger().info("Final set of permisions " + codeList);
-    return codeList;
-  }
-	
-	private static void addPermissions(ResourceOperationCode code, Set<ResourceOperationCode>
codeList) {
-	  if(code!=null) {
-      if(code.getChildren()==null)
-        codeList.add(code);
-      else {
-        for(ResourceOperationCode c : code.getChildren()){
-          codeList.add(c);
-        }
-      }
-    }    
-  }
-
-  private static String readDefault() throws IOException, JSONException {
-	  String str = System.getProperty(ResourceConstants.RESORUCE_SEC_DESCRIPTOR, ResourceConstants.RESORUCE_DEFAULT_SEC_DESCRIPTOR);
-		File file = new File(str);
-		FileReader reader = new FileReader(file);
-		char[] buffer = new char[(int) file.length()];
-		reader.read(buffer);
-		String json = new String(buffer);
-		reader.close();
-		return json;
-	}
-
-	public JSONAuthorization(String json) throws IOException, JSONException{
-		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 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;
-
-  @Override
-  public void close() {
-    
-  }
-
-  @Override
-  public boolean authorizeOperation(String arg0, OperationContext context) {
-    
-    if(principal!=null) {
-      User user = acl.get(principal.getName());
-      if(user!=null) {
-        LogService.getLogger().info("Context received " + context);
-        ResourceOperationContext ctx = (ResourceOperationContext)context;
-        LogService.getLogger().info("Checking for code " + ctx.getResourceOperationCode());
-        
-        //TODO : This is for un-annotated commands
-        if(ctx.getResourceOperationCode()==null)
-          return true;        
-        
-        boolean found = false;
-        for(ResourceOperationCode code : getAuthorizedOps(user, (ResourceOperationContext)
context)) {
-          if(ctx.getResourceOperationCode().equals(code)){
-            found =true;
-            LogService.getLogger().info("found code " + code.toString());
-            break;
-          }             
-        }
-        if(found)
-          return true;
-        LogService.getLogger().info("Did not find code " + ctx.getResourceOperationCode());
-        return false;        
-      }
-    } 
-    return false;
-  }
-
-  @Override
-  public void init(Principal principal, DistributedMember arg1, Cache arg2) throws NotAuthorizedException
{
-    this.principal = principal;    
-  }
-
-  @Override
-  public Principal authenticate(Properties props, DistributedMember arg1) throws AuthenticationFailedException
{
-    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))
-      throw new AuthenticationFailedException("Wrong username/password");
-    LogService.getLogger().info("Authentication successful!! for " + user);
-    return new JMXPrincipal(user);    
-  }
-
-  @Override
-  public void init(Properties arg0, LogWriter arg1, LogWriter arg2) throws AuthenticationFailedException
{   
-    
-  }	
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73be5635/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
deleted file mode 100644
index fa9a292..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package com.gemstone.gemfire.management.internal.security;
-
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.remote.JMXPrincipal;
-
-import junit.framework.TestCase;
-
-import org.json.JSONException;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
-import com.gemstone.gemfire.util.test.TestUtil;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-@Category(IntegrationTest.class)
-public class JSONAuthCodeTest extends TestCase {
-  
-  /*private String readFile(String name) throws IOException, JSONException {
-    File file = new File(name);
-    FileReader reader = new FileReader(file);
-    char[] buffer = new char[(int) file.length()];
-    reader.read(buffer);
-    String json = new String(buffer);
-    reader.close();
-    return json;
-  }*/
-  
-  public void testSimpleUserAndRole() throws IOException, JSONException {    
-    System.setProperty("resource.secDescriptor", TestUtil.getResourcePath(getClass(), "auth1.json"));

-    JSONAuthorization authorization = JSONAuthorization.create();        
-    authorization.init(new JMXPrincipal("tushark"), null, null);
-    
-    try {
-      JMXOperationContext context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(),
"queryData");
-      boolean result = authorization.authorizeOperation(null, context);
-      //assertTrue(result);
-      
-      context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "changeAlertLevel");
-      result = authorization.authorizeOperation(null,context);
-      assertFalse(result);
-      
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally{
-      System.clearProperty("resource.secDescriptor");
-    }
-        
-  }
-  
-  public void testInheritRole() {
-    
-  }
-  
-  /*
-  public void testUserMultipleRole() throws IOException, JSONException {
-    System.setProperty("resource.secDescriptor", JSONAuthorizationTest.filePathPrefix + "auth2.json");

-    JSONAuthorization authorization = JSONAuthorization.create();    
-    //AccessControl acc = (AccessControl)authorization;
-    
-    //check authentication
-    Properties props = new Properties();
-    props.setProperty(ManagementInterceptor.USER_NAME, "tushark");
-    props.setProperty(ManagementInterceptor.PASSWORD, "1234567");
-    try{
-      Principal pl = authorization.authenticate(props, null);
-      assertNotNull(pl);
-    }catch(AuthenticationFailedException fe) {
-      fail(fe.getMessage());
-    }
-    
-    authorization.init(new JMXPrincipal("tushark"), null, null);
-    JMXOperationContext context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(),
"queryData");
-    boolean result = authorization.authorizeOperation(null,context);
-    //assertTrue(result);
-    
-    System.setProperty("resource-auth-accessor", JSONAuthorization.class.getCanonicalName());
-    System.setProperty("resource-authenticator", JSONAuthorization.class.getCanonicalName());
-    GemFireCacheImpl cache = null;
-    DistributedSystem ds = null;
-    Properties pr = new Properties();
-    pr.put("name", "testJMXOperationContext");
-    pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
-    pr.put(DistributionConfig.JMX_MANAGER_START_NAME, "true");
-    int port = AvailablePortHelper.getRandomAvailableTCPPort();
-    pr.put(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(port));
-    pr.put(DistributionConfig.HTTP_SERVICE_PORT_NAME, "0");
-    ds = DistributedSystem.connect(pr);
-    cache = (GemFireCacheImpl) CacheFactory.create(ds);
-    
-    try {
-      CLIOperationContext cliContext = new CLIOperationContext("put --key=k1 --value=v1 --region=/region1");
-      authorization.init(new JMXPrincipal("tushark"), null, null);
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=/region1");
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-
-      context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "changeAlertLevel");
-      result = authorization.authorizeOperation(null, context);
-      assertFalse(result);
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally {
-      System.clearProperty("resource.secDescriptor");
-      cache.close();
-      ds.disconnect();
-    }
-    
-  }*/
-  
-  public void testCLIAuthForRegion() throws IOException, JSONException {
-    System.setProperty("resource.secDescriptor", TestUtil.getResourcePath(getClass(), "auth3.json"));

-    JSONAuthorization authorization = JSONAuthorization.create();       
-    authorization.init(new JMXPrincipal("tushark"), null, null);
-    
-    System.setProperty("resource-auth-accessor", JSONAuthorization.class.getCanonicalName());
-    System.setProperty("resource-authenticator", JSONAuthorization.class.getCanonicalName());
-    GemFireCacheImpl cache = null;
-    DistributedSystem ds = null;
-    Properties pr = new Properties();
-    pr.put("name", "testJMXOperationContext");
-    pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
-    pr.put(DistributionConfig.JMX_MANAGER_START_NAME, "true");
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    pr.put(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(port));
-    pr.put(DistributionConfig.HTTP_SERVICE_PORT_NAME, "0");
-    ds = DistributedSystem.connect(pr);
-    cache = (GemFireCacheImpl) CacheFactory.create(ds);
-    
-    try {
-      checkAccessControlMBean();
-      CLIOperationContext cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
-      boolean result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=secureRegion");
-      result = authorization.authorizeOperation(null, cliContext);
-      System.out.println("Result for secureRegion=" + result);
-      //assertFalse(result); //this is failing due to logic issue
-
-      authorization.init(new JMXPrincipal("avinash"), null, null);
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-      
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally {
-      System.clearProperty("resource.secDescriptor");  
-      cache.close();
-      ds.disconnect();
-    }      
-    
-  }
-
-  private void checkAccessControlMBean() throws Exception {
-    ObjectName name = new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL);
-    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
-    Set<ObjectName> names = platformMBeanServer.queryNames(name, null);
-    assertFalse(names.isEmpty());
-    assertEquals(1, names.size());
-    assertEquals(name,names.iterator().next());
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73be5635/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationTest.java
deleted file mode 100644
index 5a5d635..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package com.gemstone.gemfire.management.internal.security;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.json.JSONException;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.management.internal.security.JSONAuthorization.User;
-import com.gemstone.gemfire.util.test.TestUtil;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class JSONAuthorizationTest extends TestCase {
-  
-  public static String makePath(String[] strings) {
-    StringBuilder sb = new StringBuilder();
-    for(int i=0;i<strings.length;i++){
-      sb.append(strings[i]);      
-      sb.append(File.separator);
-    }
-    return sb.toString();
-  }
-	
-	public void testSimpleUserAndRole() throws IOException, JSONException {
-		String json = readFile(TestUtil.getResourcePath(getClass(), "testSimpleUserAndRole.json"));
-		JSONAuthorization authorization = new JSONAuthorization(json);		
-		Map<String, User> acl = authorization.getAcl();
-		assertNotNull(acl);
-		assertEquals(1, acl.size());		
-		User user = acl.get("tushark");
-		assertNotNull(user);
-		assertNotNull(user.roles);
-		assertEquals(1,user.roles.length);
-		assertEquals("jmxReader", user.roles[0].name);
-		assertEquals(1, user.roles[0].permissions.length);
-		assertEquals("QUERY", user.roles[0].permissions[0]);
-	}
-	
-	
-	public void testUserAndRoleRegionServerGroup() throws IOException, JSONException {
-		String json = readFile(TestUtil.getResourcePath(getClass(), "testUserAndRoleRegionServerGroup.json"));
-		JSONAuthorization authorization = new JSONAuthorization(json);		
-		Map<String, User> acl = authorization.getAcl();
-		assertNotNull(acl);
-		assertEquals(1, acl.size());		
-		User user = acl.get("tushark");
-		assertNotNull(user);
-		assertNotNull(user.roles);
-		assertEquals(1,user.roles.length);
-		assertEquals("jmxReader", user.roles[0].name);
-		assertEquals(1, user.roles[0].permissions.length);
-		assertEquals("QUERY", user.roles[0].permissions[0]);
-		
-		assertEquals("secureRegion", user.roles[0].regionName);
-		assertEquals("SG2", user.roles[0].serverGroup);
-	}
-	
-	public void testUserMultipleRole()throws IOException, JSONException {
-		String json = readFile(TestUtil.getResourcePath(getClass(), "testUserMultipleRole.json"));
-		JSONAuthorization authorization = new JSONAuthorization(json);		
-		Map<String, User> acl = authorization.getAcl();
-		assertNotNull(acl);
-		assertEquals(1, acl.size());		
-		User user = acl.get("tushark");
-		assertNotNull(user);
-		assertNotNull(user.roles);
-		assertEquals(2,user.roles.length);
-		
-		JSONAuthorization.Role role = user.roles[0];
-		if(role.name.equals("jmxReader")){			
-			assertEquals(1, role.permissions.length);
-			assertEquals("QUERY", role.permissions[0]);
-		} else {
-			assertEquals(7, role.permissions.length);
-			assertEquals("sysMonitors", role.name);
-		}		
-		
-		role = user.roles[1];
-		if(role.name.equals("jmxReader")){			
-			assertEquals(1, role.permissions.length);
-			assertEquals("QUERY", role.permissions[0]);
-		} else {
-			assertEquals(7, role.permissions.length);
-			assertEquals("sysMonitors", role.name);
-			assertTrue(contains(role.permissions, "CMD_EXORT_LOGS"));
-			assertTrue(contains(role.permissions, "CMD_STACK_TRACES"));
-			assertTrue(contains(role.permissions, "CMD_GC"));
-			assertTrue(contains(role.permissions, "CMD_NETSTAT"));
-			assertTrue(contains(role.permissions, "CMD_SHOW_DEADLOCKS")); 
-			assertTrue(contains(role.permissions, "CMD_SHOW_LOG")); 
-			assertTrue(contains(role.permissions, "SHOW_METRICS"));
-		}		
-	}
-	
-	private boolean contains(String[] permissions, String string) {
-		for(String str : permissions)
-			if(str.equals(string))
-					return true;
-		return false;
-	}
-
-
-	public void testInheritRole() throws IOException, JSONException {
-		String json = readFile(TestUtil.getResourcePath(getClass(), "testInheritRole.json"));
-		JSONAuthorization authorization = new JSONAuthorization(json);		
-		Map<String, User> acl = authorization.getAcl();
-		assertNotNull(acl);
-		assertEquals(3, acl.size());		
-		User user = acl.get("tushark");
-		assertNotNull(user);
-		assertNotNull(user.roles);
-		assertEquals(1,user.roles.length);
-		assertEquals("jmxReader", user.roles[0].name);
-		assertEquals(1, user.roles[0].permissions.length);
-		assertEquals("QUERY", user.roles[0].permissions[0]);
-		
-		User admin1 = acl.get("admin1");
-		assertNotNull(admin1);
-		assertNotNull(admin1.roles);
-		assertEquals(1,admin1.roles.length);
-		assertEquals("adminSG1", admin1.roles[0].name);
-		assertEquals("SG1", admin1.roles[0].serverGroup);
-		assertEquals(1, admin1.roles[0].permissions.length);
-		assertEquals("CMD_SHUTDOWN", admin1.roles[0].permissions[0]);
-		
-		User admin2 = acl.get("admin2");
-		assertNotNull(admin2);
-		assertNotNull(admin2.roles);
-		assertEquals(1,admin2.roles.length);
-		assertEquals("adminSG2", admin2.roles[0].name);
-		assertEquals("SG2", admin2.roles[0].serverGroup);
-		assertEquals(2, admin2.roles[0].permissions.length);
-		assertTrue(contains(admin2.roles[0].permissions, "CHANGE_LOG_LEVEL"));
-		assertTrue(contains(admin2.roles[0].permissions, "CMD_SHUTDOWN"));
-	}
-	
-	private String readFile(String name) throws IOException, JSONException {
-		File file = new File(name);
-		FileReader reader = new FileReader(file);
-		char[] buffer = new char[(int) file.length()];
-		reader.read(buffer);
-		String json = new String(buffer);
-		reader.close();
-		return json;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73be5635/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/ResourceOperationJUnit.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/ResourceOperationJUnit.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/ResourceOperationJUnit.java
index b88b56c..476af9b 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/ResourceOperationJUnit.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/ResourceOperationJUnit.java
@@ -432,7 +432,7 @@ public class ResourceOperationJUnit  extends TestCase {
     GemFireCacheImpl cache = null;
     DistributedSystem ds = null;
     Properties pr = new Properties();
-    pr.put("name", "testJMXOperationContext");
+    pr.put("name", "testAuthenticationUsingPropertiesBag");
     pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
     pr.put(DistributionConfig.JMX_MANAGER_START_NAME, "true");
     int port = AvailablePortHelper.getRandomAvailableTCPPort();
@@ -474,9 +474,10 @@ public class ResourceOperationJUnit  extends TestCase {
       fail("Authentication should fail");
     } catch (AuthenticationFailedException e) {
       //expected
-    } catch (SecurityException e) {
+    } catch(SecurityException e){
       //expected
-    } catch(Exception e){
+    }
+    catch(Exception e){
       e.printStackTrace();
       fail("Unexpected error " + e.getMessage());      
     }


Mime
View raw message