BrightSide Workbench Full Report + Source Code
RoleAttribute.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.security;
19 
20 import java.util.List;
21 import java.util.TreeMap;
22 import org.jdom.Element;
23 import org.turro.actor.Actors;
24 
29 @Deprecated
30 public class RoleAttribute extends TreeMap<String, RoleValue>{
31 
32  public boolean isInRole(String role) {
33  String[] roles = role.split("\\s*\\|\\s*");
34  for(String r : roles) {
35  if(checkRole(r)) return true;
36  }
37  return false;
38  }
39 
40  private boolean checkRole(String role) {
41  String[] value = role.split("\\s*:\\s*");
42  if(value.length == 2) {
43  if("@actor".equals(value[0])) {
44  return Actors.isActor(value[1]);
45  } else if(containsKey(value[0])) {
46  return get(value[0]).contains(value[1]);
47  }
48  }
49  return false;
50  }
51 
52  public void addFromElementChildren(List<Element> children) {
53  for(Element el : children) {
54  RoleValue rv = get(el.getAttributeValue("name"));
55  if(rv != null) {
56  rv.loadFrom(new RoleValue(el.getAttributeValue("value").split(" *, *")));
57  } else {
58  put(el.getAttributeValue("name"),
59  new RoleValue(el.getAttributeValue("value").split(" *, *")));
60  }
61  }
62  }
63 
64  public static RoleAttribute loadFromElementChildren(List<Element> children) {
65  RoleAttribute ra = new RoleAttribute();
66 
67  for(Element el : children) {
68  ra.put(el.getAttributeValue("name"),
69  new RoleValue(el.getAttributeValue("value").split(" *, *")));
70  }
71 
72  return ra;
73  }
74 
75 }
static boolean isActor(String actor)
Definition: Actors.java:45
void addFromElementChildren(List< Element > children)
static RoleAttribute loadFromElementChildren(List< Element > children)