1 18 package org.apache.activemq.security; 19 20 import org.apache.activemq.filter.DestinationMapEntry; 21 22 import java.lang.reflect.Constructor ; 23 import java.lang.reflect.Method ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Set ; 27 import java.util.StringTokenizer ; 28 29 38 public class AuthorizationEntry extends DestinationMapEntry { 39 40 private Set readACLs = Collections.EMPTY_SET; 41 private Set writeACLs = Collections.EMPTY_SET; 42 private Set adminACLs = Collections.EMPTY_SET; 43 44 private String adminRoles = null; 45 private String readRoles = null; 46 private String writeRoles = null; 47 48 private String groupClass = "org.apache.activemq.jaas.GroupPrincipal"; 49 50 public String getGroupClass() { 51 return groupClass; 52 } 53 54 public void setGroupClass(String groupClass) { 55 this.groupClass = groupClass; 56 } 57 58 public Set getAdminACLs() { 59 return adminACLs; 60 } 61 62 public void setAdminACLs(Set adminACLs) { 63 this.adminACLs = adminACLs; 64 } 65 66 public Set getReadACLs() { 67 return readACLs; 68 } 69 70 public void setReadACLs(Set readACLs) { 71 this.readACLs = readACLs; 72 } 73 74 public Set getWriteACLs() { 75 return writeACLs; 76 } 77 78 public void setWriteACLs(Set writeACLs) { 79 this.writeACLs = writeACLs; 80 } 81 82 public void setAdmin(String roles) throws Exception { 88 adminRoles = roles; 89 setAdminACLs(parseACLs(adminRoles)); 90 } 91 92 public void setRead(String roles) throws Exception { 93 readRoles = roles; 94 setReadACLs(parseACLs(readRoles)); 95 } 96 97 public void setWrite(String roles) throws Exception { 98 writeRoles = roles; 99 setWriteACLs(parseACLs(writeRoles)); 100 } 101 102 protected Set parseACLs(String roles) throws Exception { 103 Set answer = new HashSet (); 104 StringTokenizer iter = new StringTokenizer (roles, ","); 105 while (iter.hasMoreTokens()) { 106 String name = iter.nextToken().trim(); 107 Class [] paramClass = new Class [1]; 108 paramClass[0] = String .class; 109 110 Object [] param = new Object [1]; 111 param[0] = new String (name); 112 113 try { 114 Class cls = Class.forName(groupClass); 115 116 Constructor [] constructors = cls.getConstructors(); 117 int i; 118 for (i=0; i<constructors.length; i++) { 119 Class [] paramTypes = constructors[i].getParameterTypes(); 120 if (paramTypes.length!=0 && paramTypes[0].equals(paramClass[0])) break; 121 } 122 if (i < constructors.length) { 123 Object instance = constructors[i].newInstance(param); 124 answer.add(instance); 125 } 126 else { 127 Object instance = cls.newInstance(); 128 Method [] methods = cls.getMethods(); 129 i=0; 130 for (i=0; i<methods.length; i++) { 131 Class [] paramTypes = methods[i].getParameterTypes(); 132 if (paramTypes.length!=0 && methods[i].getName().equals("setName") && paramTypes[0].equals(paramClass[0])) break; 133 } 134 135 if (i < methods.length) { 136 methods[i].invoke(instance, param); 137 answer.add(instance); 138 } 139 else throw new NoSuchMethodException (); 140 } 141 } 142 catch (Exception e) { throw e; } 143 } 144 return answer; 145 } 146 147 public void afterPropertiesSet() throws Exception { 148 super.afterPropertiesSet(); 149 150 if(adminRoles!=null) { 151 setAdminACLs(parseACLs(adminRoles)); 152 } 153 154 if(writeRoles!=null) { 155 setWriteACLs(parseACLs(writeRoles)); 156 } 157 158 if(readRoles!=null) { 159 setReadACLs(parseACLs(readRoles)); 160 } 161 162 } 163 } 164 | Popular Tags |