BrightSide Workbench Full Report + Source Code
UserProfileMap.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.io.IOException;
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.jdom.Element;
25 import org.jdom.JDOMException;
26 import org.jdom.xpath.XPath;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.plugin.contacts.IContact;
29 import org.turro.plugin.contacts.IProfile;
30 
35 @Deprecated
36 public class UserProfileMap extends RoleAttribute {
37 
38  public static final String USERS_CONFIGURATION = "/WEB-INF/elephant/conf/xpusers.xml";
39 
40  public static UserProfileMap loadFromUser(Element user) throws IOException {
42  UserProfileMap upm = new UserProfileMap();
43  try {
44  List<Element> roles = XPath.selectNodes(user, "role");
45  for(Element el : roles) {
46  upm.loadFromProfile(pm, el.getAttributeValue("name"));
47  }
48  } catch (JDOMException ex) {
49  Logger.getLogger(UserProfileMap.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
50  }
51  return upm;
52  }
53 
54  public static UserProfileMap loadFromContact(IContact contact) throws IOException {
56  UserProfileMap upm = new UserProfileMap();
57  if(contact.isValid()) {
58  for(String role : contact.getRoles()) {
59  upm.loadFromProfile(pm, role);
60  upm.put("#" + role, new RoleValue(new String[] { "on" }));
61  }
62  for(String syndication : contact.getSyndications()) {
63  upm.put("@" + syndication, new RoleValue(new String[] { "on" }));
64  }
65  if(contact.isUser()) {
66  IProfile profile = contact.getProfile();
67  if(contact.isAdmin()) {
68  upm.put("@admin", new RoleValue(new String[] { "is" }));
69  }
70  if(profile.isWorker()) {
71  upm.put("@worker", new RoleValue(new String[] { "is" }));
72  }
73  if(profile.isStudent()) {
74  upm.put("@student", new RoleValue(new String[] { "is" }));
75  }
76  if(profile.isResponsible()) {
77  upm.put("@responsible", new RoleValue(new String[] { "is" }));
78  }
79  if(profile.isHHRR()) {
80  upm.put("@hhrr", new RoleValue(new String[] { "is" }));
81  }
82  if(profile.isCompanyHHRR()) {
83  upm.put("@companyhhrr", new RoleValue(new String[] { "is" }));
84  }
85  if(profile.isCenterHHRR()) {
86  upm.put("@centerhhrr", new RoleValue(new String[] { "is" }));
87  }
88  if(profile.isCenterHHRR()) {
89  upm.put("@translator", new RoleValue(new String[] { "is" }));
90  }
91  }
92  }
93  return upm;
94  }
95 
96  public void loadFromProfile(ProfileMap profiles, String profile) {
97  if(profiles != null) {
98  if(profiles.containsKey(profile)) {
99  loadFrom(profiles.get(profile));
100  }
101  }
102  }
103 
104  public void loadFrom(RoleAttribute attributes) {
105  for(String name : attributes.keySet()) {
106  loadAttribute(name, attributes.get(name));
107  }
108  }
109 
110  public void loadAttribute(String name, RoleValue values) {
111  if(!containsKey(name)) {
112  put(name, new RoleValue(new String[] {}));
113  }
114  get(name).loadFrom(values);
115  }
116 
117 }
void loadAttribute(String name, RoleValue values)
void loadFromProfile(ProfileMap profiles, String profile)
static UserProfileMap loadFromUser(Element user)
static UserProfileMap loadFromContact(IContact contact)