1 13 package info.magnolia.cms.security; 14 15 import java.util.List ; 16 17 import org.apache.commons.lang.StringUtils; 18 19 20 24 public class AccessManagerImpl implements AccessManager { 25 26 private List userPermissions; 27 28 public boolean isGranted(String path, long permissions) { 29 if (StringUtils.isEmpty(path)) { 30 return (getPermissions("/") & permissions) == permissions; } 32 return (getPermissions(path) & permissions) == permissions; 33 } 34 35 public void setPermissionList(List permissions) { 36 this.userPermissions = permissions; 37 } 38 39 public long getPermissions(String path) { 40 if (userPermissions == null) { 41 return Permission.ALL; 42 } 43 long permission = 0; 44 int patternLength = 0; 45 for (int i = 0; i < userPermissions.size(); i++) { 46 info.magnolia.cms.security.Permission p = (info.magnolia.cms.security.Permission) userPermissions.get(i); 47 if (p.match(path)) { 48 int l = p.getPattern().getLength(); 49 if (patternLength == l && (permission > p.getPermissions())) { 50 permission = p.getPermissions(); 51 } 52 else if (patternLength <= l) { 53 patternLength = l; 54 permission = p.getPermissions(); 55 } 56 } 57 } 58 return permission; 59 } 60 } 61 | Popular Tags |