18 package org.turro.elephant.impl.security;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.TreeMap;
25 import java.util.concurrent.locks.Lock;
26 import java.util.concurrent.locks.ReentrantLock;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.jdom.Attribute;
30 import org.jdom.Document;
31 import org.jdom.Element;
32 import org.jdom.JDOMException;
33 import org.jdom.input.SAXBuilder;
34 import org.jdom.xpath.XPath;
35 import org.turro.elephant.context.ElephantContext;
43 public class ProfileMap extends TreeMap<String, RoleAttribute> {
47 if(containsKey(profile)) {
48 return get(profile).isInRole(role);
55 List<String> profiles =
new ArrayList<String>();
56 for(String s : keySet()) {
60 else if(
get(s).isInRole(role)) {
67 public static final String
69 ROLES_SITE_CONFIGURATION =
"/WEB-INF/elephant/conf/xproles-site.xml";
72 private static final Lock lock =
new ReentrantLock();
92 private static ProfileMap loadFromElementsList(List<Element> elements) {
95 for(Element el : elements) {
100 pm.put(el.getAttributeValue(
"name"), RoleAttribute.loadFromElementChildren(el.getChildren(
"resource")));
108 List roles =
new ArrayList();
112 if(l !=
null) roles.addAll(l);
116 if(l !=
null) roles.addAll(l);
120 public static List
loadRoleFile(File confFile, String expression)
throws IOException {
121 if (confFile.exists()) {
122 SAXBuilder builder =
new SAXBuilder();
124 Document doc = builder.build(confFile);
125 return XPath.selectNodes(doc, expression);
126 }
catch (IOException ex) {
128 }
catch (JDOMException ex) {
136 List<String> names =
new ArrayList<String>();
138 names.add(a.getValue());
144 List<String> names =
new ArrayList<String>();
145 for(Attribute a : (List<Attribute>)
loadRoleByExpression(
"/xproles/role[resource/@name='" + filter +
"']/@name")) {
146 names.add(a.getValue());
static String getRealPath(String path)
static String logMsg(String msg)
static List loadRoleByExpression(String expression)
static List loadRoleFile(File confFile, String expression)
boolean isInRoleByProfile(String profile, String role)
static final String ROLES_CONFIGURATION
static ProfileMap loadProfiles()
static List getRoleNamesByFilter(String filter)
static void resetProfiles()
static List getRoleNames()
List< String > getProfilesInRole(String role)
void addFromElementChildren(List< Element > children)