1 package org.tigris.scarab.services.security; 2 3 48 49 import java.util.List ; 50 import java.util.ArrayList ; 51 52 import org.apache.commons.configuration.Configuration; 53 import org.apache.fulcrum.Service; 54 import org.apache.fulcrum.BaseService; 55 import org.apache.fulcrum.TurbineServices; 56 57 63 public class ScarabSecurity 64 extends BaseService 65 implements Service 66 { 67 68 public static final String SERVICE_NAME = "ScarabSecurity"; 69 70 public static final String TOOL_KEY = 71 "services.PullService.tool.request.security"; 72 73 private static final String SCREEN_PREFIX = "screen."; 74 private static final String ACTION_PREFIX = "action."; 75 76 protected static final String MAP_PREFIX = "map."; 77 78 82 public static final String NONE = "None"; 83 84 87 public static final String ISSUE__EDIT = 88 getService().getPermissionImpl("Issue__Edit"); 89 90 93 public static final String ISSUE__ENTER = 94 getService().getPermissionImpl("Issue__Enter"); 95 96 99 public static final String ISSUE__VIEW = 100 getService().getPermissionImpl("Issue__View"); 101 102 105 public static final String ISSUE__SEARCH = 106 getService().getPermissionImpl("Issue__Search"); 107 108 111 public static final String ISSUE__MOVE = 112 getService().getPermissionImpl("Issue__Move"); 113 114 117 public static final String ISSUE__ATTACH = 118 getService().getPermissionImpl("Issue__Attach"); 119 120 123 public static final String ISSUE__ASSIGN = 124 getService().getPermissionImpl("Issue__Assign"); 125 126 129 public static final String ITEM__APPROVE = 130 getService().getPermissionImpl("Item__Approve"); 131 132 135 public static final String ITEM__DELETE = 136 getService().getPermissionImpl("Item__Delete"); 137 138 141 public static final String USER__EDIT_PREFERENCES = 142 getService().getPermissionImpl("User__Edit_Preferences"); 143 144 147 public static final String DOMAIN__ADMIN = 148 getService().getPermissionImpl("Domain__Admin"); 149 150 153 public static final String DOMAIN__EDIT = 154 getService().getPermissionImpl("Domain__Edit"); 155 156 159 public static final String MODULE__EDIT = 160 getService().getPermissionImpl("Module__Edit"); 161 162 165 public static final String MODULE__CONFIGURE = 166 getService().getPermissionImpl("Module__Configure"); 167 168 171 public static final String MODULE__ADD = 172 getService().getPermissionImpl("Module__Add"); 173 174 178 public static final String USER__APPROVE_ROLES = 179 getService().getPermissionImpl("User__Approve_Roles"); 180 181 184 public static final String VOTE__MANAGE = 185 getService().getPermissionImpl("Vote__Manage"); 186 187 192 public static final String USER__CHANGE_PASSWORD = 193 getService().getPermissionImpl("User__Change_Password"); 194 195 196 private Configuration props; 197 private List allPermissions; 198 199 public ScarabSecurity() 200 { 201 } 202 203 public void init() 204 { 205 props = getConfiguration(); 206 setInit(true); 207 } 208 209 212 private void addPerm(List perms, String perm) 213 { 214 if (perm != null && perm.length() > 0 && !perms.contains(perm)) 215 { 216 perms.add(perm); 217 } 218 } 219 220 protected List getAllPermissionsImpl() 221 { 222 if (allPermissions == null) 223 { 224 List tmpPerms = new ArrayList (); 225 addPerm(tmpPerms, ScarabSecurity.ISSUE__EDIT); 226 addPerm(tmpPerms, ScarabSecurity.ISSUE__ENTER); 227 addPerm(tmpPerms, ScarabSecurity.ISSUE__SEARCH); 228 addPerm(tmpPerms, ScarabSecurity.ISSUE__VIEW); 229 addPerm(tmpPerms, ScarabSecurity.ISSUE__ASSIGN); 230 addPerm(tmpPerms, ScarabSecurity.ISSUE__ATTACH); 231 addPerm(tmpPerms, ScarabSecurity.ISSUE__MOVE); 232 addPerm(tmpPerms, ScarabSecurity.ITEM__APPROVE); 233 addPerm(tmpPerms, ScarabSecurity.ITEM__DELETE); 234 addPerm(tmpPerms, ScarabSecurity.DOMAIN__ADMIN); 235 addPerm(tmpPerms, ScarabSecurity.DOMAIN__EDIT); 236 addPerm(tmpPerms, ScarabSecurity.MODULE__EDIT); 237 addPerm(tmpPerms, ScarabSecurity.MODULE__CONFIGURE); 238 addPerm(tmpPerms, ScarabSecurity.MODULE__ADD); 239 addPerm(tmpPerms, ScarabSecurity.USER__EDIT_PREFERENCES); 240 addPerm(tmpPerms, ScarabSecurity.USER__APPROVE_ROLES); 241 addPerm(tmpPerms, ScarabSecurity.VOTE__MANAGE); 242 allPermissions = tmpPerms; 243 } 244 245 return allPermissions; 246 } 247 248 protected String getScreenPermissionImpl(String screen) 249 { 250 String t = screen.replace(',','.'); 251 return getPermissionImpl(props.getString(SCREEN_PREFIX + t,null)); 252 } 253 254 protected String getActionPermissionImpl(String action) 255 { 256 String perm = null; 257 String property = props.getString(ACTION_PREFIX + action); 258 if (NONE.equals(property)) 259 { 260 perm = NONE; 261 } 262 else 263 { 264 perm = getPermissionImpl(property); 265 } 266 return perm; 267 } 268 269 protected String getPermissionImpl(String permConstant) 270 { 271 return props.getString(MAP_PREFIX + permConstant,null); 272 } 273 274 275 279 public static List getAllPermissions() 280 { 281 return getService().getAllPermissionsImpl(); 282 } 283 284 public static String getScreenPermission(String screen) 285 { 286 return getService().getScreenPermissionImpl(screen); 287 } 288 289 public static String getActionPermission(String action) 290 { 291 return getService().getActionPermissionImpl(action); 292 } 293 294 299 protected static final ScarabSecurity getService() 300 { 301 return (ScarabSecurity) TurbineServices.getInstance() 302 .getService(ScarabSecurity.SERVICE_NAME); 303 } 304 305 } 306 | Popular Tags |