@Test public void testGetRolesForInvocation() { Dictionary<String, Object> config = new Hashtable<>(); config.put("foo", "r1, r2"); config.put("bar(java.lang.String, int)[/aa/,/42/]", "ra"); config.put("bar(java.lang.String, int)[/bb/,/42/]", "rb"); config.put("bar(java.lang.String, int)[\"cc\", \"17\"]", "rc"); config.put("bar(java.lang.String, int)", "rd"); config.put("bar(java.lang.String)", "re"); config.put("bar", "rf"); config.put("ba*", "rg #Wildcard"); List<String> roles1 = new ArrayList<>(); assertEquals(Specificity.NAME_MATCH, ACLConfigurationParser.getRolesForInvocation("foo", new Object [] {}, new String [] {}, config, roles1)); assertEquals(Arrays.asList("r1", "r2"), roles1); List<String> roles2 = new ArrayList<>(); assertEquals(Specificity.NAME_MATCH, ACLConfigurationParser.getRolesForInvocation("foo", new Object [] {"test"}, new String [] {"java.lang.String"}, config, roles2)); assertEquals(Arrays.asList("r1", "r2"), roles2); List<String> roles3 = new ArrayList<>(); assertEquals(Specificity.NO_MATCH, ACLConfigurationParser.getRolesForInvocation("test", new Object [] {}, new String [] {}, config, roles3)); assertEquals(0, roles3.size()); List<String> roles4 = new ArrayList<>(); assertEquals(Specificity.ARGUMENT_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {"aa", 42}, new String [] {"java.lang.String", "int"}, config, roles4)); assertEquals(Collections.singletonList("ra"), roles4); List<String> roles5 = new ArrayList<>(); assertEquals(Specificity.ARGUMENT_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {"bb", 42}, new String [] {"java.lang.String", "int"}, config, roles5)); assertEquals(Collections.singletonList("rb"), roles5); List<String> roles6 = new ArrayList<>(); assertEquals(Specificity.ARGUMENT_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {"cc", 17}, new String [] {"java.lang.String", "int"}, config, roles6)); assertEquals(Collections.singletonList("rc"), roles6); List<String> roles7 = new ArrayList<>(); assertEquals(Specificity.SIGNATURE_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {"aaa", 42}, new String [] {"java.lang.String", "int"}, config, roles7)); assertEquals(Collections.singletonList("rd"), roles7); List<String> roles8 = new ArrayList<>(); assertEquals(Specificity.SIGNATURE_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {"aa"}, new String [] {"java.lang.String"}, config, roles8)); assertEquals(Collections.singletonList("re"), roles8); List<String> roles9 = new ArrayList<>(); assertEquals(Specificity.NAME_MATCH, ACLConfigurationParser.getRolesForInvocation("bar", new Object [] {42}, new String [] {"int"}, config, roles9)); assertEquals(Collections.singletonList("rf"), roles9); List<String> roles10 = new ArrayList<>(); assertEquals(Specificity.WILDCARD_MATCH, ACLConfigurationParser.getRolesForInvocation("barr", new Object [] {42}, new String [] {"int"}, config, roles10)); assertEquals(Collections.singletonList("rg"), roles10); }
public static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature, Dictionary<String, Object> config, List<String> addToRoles) { Dictionary<String, Object> properties = trimKeys(config); String pid = (String)properties.get("service.pid"); Specificity s = getRolesBasedOnSignature(methodName, params, signature, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } s = getRolesBasedOnSignature(methodName, params, null, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } List<String> roles = getMethodNameWildcardRoles(properties, methodName); if (roles != null) { addToRoles.addAll(roles); return Specificity.WILDCARD_MATCH; } else if (compulsoryRoles != null && !pid.contains("jmx.acl")){ addToRoles.addAll(ACLConfigurationParser.parseRoles(compulsoryRoles)); return Specificity.NAME_MATCH; } else { return Specificity.NO_MATCH; } }
ACLConfigurationParser { public static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature, Dictionary<String, Object> config, List<String> addToRoles) { Dictionary<String, Object> properties = trimKeys(config); String pid = (String)properties.get("service.pid"); Specificity s = getRolesBasedOnSignature(methodName, params, signature, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } s = getRolesBasedOnSignature(methodName, params, null, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } List<String> roles = getMethodNameWildcardRoles(properties, methodName); if (roles != null) { addToRoles.addAll(roles); return Specificity.WILDCARD_MATCH; } else if (compulsoryRoles != null && !pid.contains("jmx.acl")){ addToRoles.addAll(ACLConfigurationParser.parseRoles(compulsoryRoles)); return Specificity.NAME_MATCH; } else { return Specificity.NO_MATCH; } } }
ACLConfigurationParser { public static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature, Dictionary<String, Object> config, List<String> addToRoles) { Dictionary<String, Object> properties = trimKeys(config); String pid = (String)properties.get("service.pid"); Specificity s = getRolesBasedOnSignature(methodName, params, signature, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } s = getRolesBasedOnSignature(methodName, params, null, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } List<String> roles = getMethodNameWildcardRoles(properties, methodName); if (roles != null) { addToRoles.addAll(roles); return Specificity.WILDCARD_MATCH; } else if (compulsoryRoles != null && !pid.contains("jmx.acl")){ addToRoles.addAll(ACLConfigurationParser.parseRoles(compulsoryRoles)); return Specificity.NAME_MATCH; } else { return Specificity.NO_MATCH; } }  }
ACLConfigurationParser { public static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature, Dictionary<String, Object> config, List<String> addToRoles) { Dictionary<String, Object> properties = trimKeys(config); String pid = (String)properties.get("service.pid"); Specificity s = getRolesBasedOnSignature(methodName, params, signature, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } s = getRolesBasedOnSignature(methodName, params, null, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } List<String> roles = getMethodNameWildcardRoles(properties, methodName); if (roles != null) { addToRoles.addAll(roles); return Specificity.WILDCARD_MATCH; } else if (compulsoryRoles != null && !pid.contains("jmx.acl")){ addToRoles.addAll(ACLConfigurationParser.parseRoles(compulsoryRoles)); return Specificity.NAME_MATCH; } else { return Specificity.NO_MATCH; } }  static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature,
                                                    Dictionary<String, Object> config, List<String> addToRoles); static Specificity getRolesForInvocationForAlias(String methodName, Object[] params, String[] signature,
                                                    Dictionary<String, Object> config, List<String> addToRoles); static void getCompulsoryRoles(List<String> roles); static List<String> parseRoles(String roleStr); }
ACLConfigurationParser { public static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature, Dictionary<String, Object> config, List<String> addToRoles) { Dictionary<String, Object> properties = trimKeys(config); String pid = (String)properties.get("service.pid"); Specificity s = getRolesBasedOnSignature(methodName, params, signature, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } s = getRolesBasedOnSignature(methodName, params, null, properties, addToRoles); if (s != Specificity.NO_MATCH) { return s; } List<String> roles = getMethodNameWildcardRoles(properties, methodName); if (roles != null) { addToRoles.addAll(roles); return Specificity.WILDCARD_MATCH; } else if (compulsoryRoles != null && !pid.contains("jmx.acl")){ addToRoles.addAll(ACLConfigurationParser.parseRoles(compulsoryRoles)); return Specificity.NAME_MATCH; } else { return Specificity.NO_MATCH; } }  static Specificity getRolesForInvocation(String methodName, Object[] params, String[] signature,
                                                    Dictionary<String, Object> config, List<String> addToRoles); static Specificity getRolesForInvocationForAlias(String methodName, Object[] params, String[] signature,
                                                    Dictionary<String, Object> config, List<String> addToRoles); static void getCompulsoryRoles(List<String> roles); static List<String> parseRoles(String roleStr);  }