1 17 package org.apache.servicemix.jbi.security.acl.impl; 18 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 import java.util.StringTokenizer ; 23 24 import javax.xml.XMLConstants ; 25 import javax.xml.namespace.QName ; 26 27 import org.apache.servicemix.jbi.security.GroupPrincipal; 28 29 34 public class AuthorizationEntry { 35 36 39 public static final String TYPE_ADD = "add"; 40 43 public static final String TYPE_SET = "set"; 44 47 public static final String TYPE_REM = "rem"; 48 49 private Set acls; 50 private QName service; 51 private String endpoint; 52 private String type = TYPE_ADD; 53 54 public AuthorizationEntry() { 55 } 56 57 public AuthorizationEntry(QName service, String endpoint, String roles) { 58 this.service = service; 59 this.endpoint = endpoint; 60 setRoles(roles); 61 } 62 63 public AuthorizationEntry(QName service, String endpoint, String roles, String type) { 64 this.service = service; 65 this.endpoint = endpoint; 66 setRoles(roles); 67 this.type = type; 68 } 69 70 73 public String getType() { 74 return type; 75 } 76 77 80 public void setType(String type) { 81 this.type = type; 82 } 83 84 87 public String getEndpoint() { 88 return endpoint; 89 } 90 91 94 public void setEndpoint(String endpoint) { 95 this.endpoint = endpoint; 96 } 97 98 101 public QName getService() { 102 return service; 103 } 104 105 108 public void setService(QName service) { 109 if (XMLConstants.NULL_NS_URI.equals(service.getNamespaceURI()) && 112 service.getPrefix() != null && service.getPrefix().length() > 0) { 113 service = new QName (service.getPrefix(), service.getLocalPart()); 114 } 115 this.service = service; 116 } 117 118 121 public Set getAcls() { 122 return acls; 123 } 124 125 128 public void setAcls(Set acls) { 129 this.acls = acls; 130 } 131 132 public void setRoles(String roles) { 133 this.acls = new HashSet (); 134 StringTokenizer iter = new StringTokenizer (roles, ","); 135 while (iter.hasMoreTokens()) { 136 String name = iter.nextToken().trim(); 137 this.acls.add(new GroupPrincipal(name)); 138 } 139 } 140 141 public String getRoles() { 142 StringBuffer sb = new StringBuffer (); 143 if (this.acls != null) { 144 for (Iterator iter = this.acls.iterator(); iter.hasNext();) { 145 GroupPrincipal p = (GroupPrincipal) iter.next(); 146 sb.append(p); 147 if (iter.hasNext()) { 148 sb.append(","); 149 } 150 } 151 } 152 return sb.toString(); 153 } 154 155 public String toString() { 156 return "AuthorizationEntry[service=" + service + ", endpoint=" + endpoint + ", roles=" + getRoles() + "]"; 157 } 158 } 159 | Popular Tags |