1 9 package org.jboss.portal.core.security; 10 11 import java.util.Iterator ; 12 import java.util.Set ; 13 14 20 public class ModelAuthorizationRealm implements AuthorizationRealm 21 { 22 23 private final Model model; 24 private final SchemeStore store; 25 26 public ModelAuthorizationRealm(Model model, SchemeStore store) 27 { 28 this.model = model; 29 this.store = store; 30 } 31 32 public Scheme getScheme(String domain) 33 { 34 if (domain == null) 35 { 36 throw new IllegalArgumentException (); 37 } 38 39 Scheme scheme = store.getScheme(domain); 41 42 if (scheme == null) 44 { 45 scheme = model.getDefaultScheme(); 46 } 47 return scheme; 48 } 49 50 public Model getModel() 51 { 52 return model; 53 } 54 55 public boolean hasPermission(String domain, String role, String permission) 56 { 57 return hasPermission(domain, role, new String [0], permission); 58 } 59 60 public boolean hasPermission(String domain, Set roles, String permission) 61 { 62 return hasPermission(domain, roles, new String [0], permission); 63 } 64 65 public boolean hasPermission(String domain, String role, String [] path, String permission) 66 { 67 if (role == null) 68 { 69 throw new IllegalArgumentException (); 70 } 71 if (path == null) 72 { 73 throw new IllegalArgumentException (); 74 } 75 if (permission == null) 76 { 77 throw new IllegalArgumentException (); 78 } 79 for (int index = path.length;index >= 0;index--) 80 { 81 String [] tmp = new String [index]; 82 System.arraycopy(path, 0, tmp, 0, index); 83 Scheme scheme = getScheme(domain); 84 Set ownedPermissions = scheme.get(tmp, role); 85 for (Iterator j = ownedPermissions.iterator();j.hasNext();) 86 { 87 String ownedPermission = (String )j.next(); 88 if (model.implies(ownedPermission, permission)) 89 { 90 return true; 91 } 92 } 93 } 94 return false; 95 } 96 97 public boolean hasPermission(String domain, Set roles, String [] path, String permission) 98 { 99 if (roles == null) 100 { 101 throw new IllegalArgumentException (); 102 } 103 if (path == null) 104 { 105 throw new IllegalArgumentException (); 106 } 107 if (permission == null) 108 { 109 throw new IllegalArgumentException (); 110 } 111 for (int index = path.length;index >= 0;index--) 112 { 113 String [] tmp = new String [index]; 114 System.arraycopy(path, 0, tmp, 0, index); 115 Scheme scheme = getScheme(domain); 116 Set ownedPermissions = scheme.get(tmp, roles); 117 for (Iterator j = ownedPermissions.iterator();j.hasNext();) 118 { 119 String ownedPermission = (String )j.next(); 120 if (model.implies(ownedPermission, permission)) 121 { 122 return true; 123 } 124 } 125 } 126 return false; 127 } 128 129 public boolean hasPermission(String role, String permission) 130 { 131 return hasPermission("", role, permission); 132 } 133 134 public boolean hasPermission(Set roles, String permission) 135 { 136 return hasPermission("", roles, permission); 137 } 138 139 public boolean hasPermission(String role, String [] path, String permission) 140 { 141 return hasPermission("", role, path, permission); 142 } 143 144 public boolean hasPermission(Set roles, String [] path, String permission) 145 { 146 return hasPermission("", roles, path, permission); 147 } 148 } 149 | Popular Tags |