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.List ; 22 import java.util.Set ; 23 import java.util.regex.Pattern ; 24 25 import javax.jbi.servicedesc.ServiceEndpoint; 26 import javax.xml.namespace.QName ; 27 28 import org.apache.servicemix.jbi.security.acl.AuthorizationMap; 29 30 31 36 public class DefaultAuthorizationMap implements AuthorizationMap { 37 38 private AuthorizationEntry defaultEntry; 39 private List authorizationEntries; 40 41 public DefaultAuthorizationMap() { 42 } 43 44 public DefaultAuthorizationMap(List authorizationEntries) { 45 this.authorizationEntries = authorizationEntries; 46 } 47 48 51 public List getAuthorizationEntries() { 52 return authorizationEntries; 53 } 54 55 59 public void setAuthorizationEntries(List authorizationEntries) { 60 this.authorizationEntries = authorizationEntries; 61 } 62 63 66 public AuthorizationEntry getDefaultEntry() { 67 return defaultEntry; 68 } 69 70 73 public void setDefaultEntry(AuthorizationEntry defaultEntry) { 74 this.defaultEntry = defaultEntry; 75 } 76 77 public Set getAcls(ServiceEndpoint endpoint) { 78 Set acls = new HashSet (); 79 if (defaultEntry != null) { 80 acls.add(defaultEntry); 81 } 82 for (Iterator iter = authorizationEntries.iterator(); iter.hasNext();) { 83 AuthorizationEntry entry = (AuthorizationEntry) iter.next(); 84 if (match(entry, endpoint)) { 85 if (AuthorizationEntry.TYPE_ADD.equalsIgnoreCase(entry.getType())) { 86 acls.addAll(entry.getAcls()); 87 } else if (AuthorizationEntry.TYPE_SET.equalsIgnoreCase(entry.getType())) { 88 acls.clear(); 89 acls.addAll(entry.getAcls()); 90 } else if (AuthorizationEntry.TYPE_REM.equalsIgnoreCase(entry.getType())) { 91 acls.removeAll(entry.getAcls()); 92 } 93 } 94 } 95 return acls; 96 } 97 98 protected boolean match(AuthorizationEntry entry, ServiceEndpoint endpoint) { 99 return match(entry.getService(), endpoint.getServiceName()) && 100 match(entry.getEndpoint(), endpoint.getEndpointName()); 101 } 102 103 private boolean match(QName acl, QName target) { 104 return match(acl.getNamespaceURI(), target.getNamespaceURI()) && 105 match(acl.getLocalPart(), target.getLocalPart()); 106 } 107 108 private boolean match(String acl, String target) { 109 return acl == null || 110 acl.equals("*") || 111 Pattern.matches(acl, target); 112 } 113 114 } 115 | Popular Tags |