public class FileBasedACRs
extends java.lang.Object
This reference implementation uses a simple scheme for specifying the rules. The first step is to create a namespace for the resources being accessed. For files and URL's, this is easy as they already have a namespace. Be extremely careful about canonicalizing when relying on information from the user in an access control decision.
For functions, data, and services, you will have to come up with your own namespace for the resources being accessed. You might simply define a flat namespace with a list of category names. For example, you might specify 'FunctionA', 'FunctionB', and 'FunctionC'. Or you can create a richer namespace with a hierarchical structure, such as:
/functions
There is a single configuration file supporting each of the five methods in the AccessController interface. These files are located in the ESAPI resources directory as specified when the JVM was started. The use of a default deny rule is STRONGLY recommended. The file format is as follows:
path | role,role | allow/deny | comment ------------------------------------------------------------------------------------ /banking/* | user,admin | allow | authenticated users can access /banking /admin | admin | allow | only admin role can access /admin / | any | deny | default deny ruleTo find the matching rules, this implementation follows the general approach used in Java EE when matching HTTP requests to servlets in web.xml. The four mapping rules are used in the following order:
| Modifier and Type | Class and Description |
|---|---|
private class |
FileBasedACRs.Rule
The Class Rule.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map |
dataMap
The data map.
|
private FileBasedACRs.Rule |
deny
A rule containing "deny".
|
private java.util.Map |
fileMap
The file map.
|
private java.util.Map |
functionMap
The function map.
|
private Logger |
logger
The logger.
|
private java.util.Map |
serviceMap
The service map.
|
private java.util.Map |
urlMap
The url map.
|
| Constructor and Description |
|---|
FileBasedACRs() |
| Modifier and Type | Method and Description |
|---|---|
private java.util.List |
commaSplit(java.lang.String input)
This method splits a String by the ',' and returns the result as a List.
|
boolean |
isAuthorizedForData(java.lang.String action,
java.lang.Object data)
TODO Javadoc
|
boolean |
isAuthorizedForFile(java.lang.String filepath)
TODO Javadoc
|
boolean |
isAuthorizedForFunction(java.lang.String functionName)
TODO Javadoc
|
boolean |
isAuthorizedForService(java.lang.String serviceName)
TODO Javadoc
|
boolean |
isAuthorizedForURL(java.lang.String url)
Check if URL is authorized.
|
private java.util.Map |
loadDataRules(java.lang.String ruleset)
Loads access rules by storing them in a hashmap.
|
private java.util.Map |
loadRules(java.lang.String ruleset)
Loads access rules by storing them in a hashmap.
|
private boolean |
matchRule(java.util.Map map,
java.lang.Class clazz,
java.lang.String action)
Checks to see if the current user has access to the specified Class and action.
|
private boolean |
matchRule(java.util.Map map,
java.lang.String path)
Checks to see if the current user has access to the specified data, File, Object, etc.
|
private boolean |
overlap(java.util.List ruleActions,
java.lang.String action)
This method merely checks to see if ruleActions contains the action requested.
|
private boolean |
overlap(java.util.Set ruleRoles,
java.util.Set userRoles)
Return true if there is overlap between the two sets.
|
private FileBasedACRs.Rule |
searchForRule(java.util.Map map,
java.util.Set roles,
java.lang.Class clazz,
java.lang.String action)
Search for rule.
|
private FileBasedACRs.Rule |
searchForRule(java.util.Map map,
java.util.Set roles,
java.lang.String path)
Search for rule.
|
private java.util.List |
validateRoles(java.util.List roles)
Checks that the roles passed in contain only letters, numbers, and underscores.
|
private java.util.Map urlMap
private java.util.Map functionMap
private java.util.Map dataMap
private java.util.Map fileMap
private java.util.Map serviceMap
private FileBasedACRs.Rule deny
private Logger logger
public boolean isAuthorizedForURL(java.lang.String url)
url - The URL tested for authorizationtrue if access is allowed, false otherwise.public boolean isAuthorizedForFunction(java.lang.String functionName)
throws AccessControlException
AccessControlExceptionpublic boolean isAuthorizedForData(java.lang.String action,
java.lang.Object data)
throws AccessControlException
AccessControlExceptionpublic boolean isAuthorizedForFile(java.lang.String filepath)
throws AccessControlException
AccessControlExceptionpublic boolean isAuthorizedForService(java.lang.String serviceName)
throws AccessControlException
AccessControlExceptionprivate boolean matchRule(java.util.Map map,
java.lang.String path)
map - the map containing access rulespath - the path of the requested File, URL, Object, etc.private boolean matchRule(java.util.Map map,
java.lang.Class clazz,
java.lang.String action)
map - the map containing access rulesclazz - the Class being requested for accessaction - the action the User has asked to performprivate FileBasedACRs.Rule searchForRule(java.util.Map map, java.util.Set roles, java.lang.String path)
map - the map containing access rulesroles - the roles of the User being checked for accesspath - the File, URL, Object, etc. being checked for accessprivate FileBasedACRs.Rule searchForRule(java.util.Map map, java.util.Set roles, java.lang.Class clazz, java.lang.String action)
map - the map containing access rulesroles - the roles used to determine access levelclazz - the Class being requested for accessaction - the action the User has asked to performprivate boolean overlap(java.util.Set ruleRoles,
java.util.Set userRoles)
ruleRoles - the rule rolesuserRoles - the user rolesprivate boolean overlap(java.util.List ruleActions,
java.lang.String action)
ruleActions - actions listed for a ruleaction - the action requested that will be searched for in ruleActionsprivate java.util.List validateRoles(java.util.List roles)
roles - roles to validate according to criteria started aboveprivate java.util.Map loadRules(java.lang.String ruleset)
ruleset - the name of the data that contains access rulesprivate java.util.Map loadDataRules(java.lang.String ruleset)
ruleset - the name of the data that contains access rulesprivate java.util.List commaSplit(java.lang.String input)
input - the String to split by ','