1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.security;
35
36 import info.magnolia.cms.security.auth.Entity;
37 import info.magnolia.cms.security.auth.GroupList;
38 import info.magnolia.cms.security.auth.RoleList;
39 import info.magnolia.context.MgnlContext;
40
41 import java.io.Serializable;
42 import java.util.Collection;
43 import java.util.Iterator;
44 import java.util.Map;
45 import java.util.Set;
46
47 import javax.security.auth.Subject;
48
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51
52
53
54
55
56 public class ExternalUser extends AbstractUser implements Serializable {
57 private static final Logger log = LoggerFactory.getLogger(ExternalUser.class);
58
59
60
61
62 private Entity userDetails;
63
64
65
66
67 private Map<String, String> properties;
68
69
70
71
72 private RoleList roleList;
73
74
75
76
77 private GroupList groupList;
78
79
80
81
82
83
84 @Deprecated
85 protected ExternalUser(Subject subject) {
86 final Set<Entity> principalDetails = subject.getPrincipals(Entity.class);
87 final Iterator<Entity> entityIterator = principalDetails.iterator();
88 this.userDetails = entityIterator.next();
89
90 final Set<RoleList> principalRoles = subject.getPrincipals(RoleList.class);
91 final Iterator<RoleList> roleListIterator = principalRoles.iterator();
92 this.roleList = roleListIterator.next();
93
94 final Set<GroupList> principalGroups = subject.getPrincipals(GroupList.class);
95 final Iterator<GroupList> groupListIterator = principalGroups.iterator();
96 this.groupList = groupListIterator.next();
97 }
98
99 protected ExternalUser(Map<String, String> properties, GroupList groupList, RoleList roleList) {
100 this.properties = properties;
101 this.groupList = groupList;
102 this.roleList = roleList;
103 }
104
105 @Override
106 public boolean hasRole(String roleName) {
107 return this.roleList.has(roleName);
108 }
109
110 @Override
111 public void removeRole(String roleName) {
112 throw new UnsupportedOperationException("not implemented for this ExternalUser");
113 }
114
115 @Override
116 public void addRole(String roleName) {
117 throw new UnsupportedOperationException("not implemented for this ExternalUser");
118 }
119
120
121
122
123
124 @Override
125 public boolean inGroup(String groupName) {
126 return this.groupList.has(groupName);
127 }
128
129
130
131
132 @Override
133 public void removeGroup(String groupName) throws UnsupportedOperationException {
134 throw new UnsupportedOperationException("not implemented for this ExternalUser");
135 }
136
137
138
139
140 @Override
141 public void addGroup(String groupName) throws UnsupportedOperationException {
142 throw new UnsupportedOperationException("not implemented for this ExternalUser");
143 }
144
145 @Override
146 public boolean isEnabled() {
147 return true;
148 }
149
150 @Override
151 public void setEnabled(boolean enabled) {
152 }
153
154 @Override
155 public String getLanguage() {
156 String language = this.properties.get(Entity.LANGUAGE);
157 if (null == language) {
158 language = MgnlContext.getSystemContext().getLocale().getLanguage();
159 }
160 return language;
161 }
162
163 @Override
164 public String getName() {
165 return this.properties.get(Entity.NAME);
166 }
167
168 @Override
169 public String getPassword() {
170 return this.properties.get(Entity.PASSWORD);
171 }
172
173 public String getEmail() {
174 return this.properties.get(Entity.EMAIL);
175 }
176
177 @Override
178 public String getProperty(String propertyName) {
179 String property = this.properties.get(propertyName);
180 if(null == property){
181 log.debug("Unable to retrieve property {} for user {}", propertyName, getName());
182 }
183 return property;
184 }
185
186 @Override
187 public void setProperty(String propertyName, String value) {
188 this.properties.put(propertyName, value);
189 }
190
191 @Override
192 public String getIdentifier() {
193 throw new UnsupportedOperationException("not implemented for this ExternalUser");
194 }
195
196 @Override
197 public Collection<String> getGroups() {
198 return this.groupList.getList();
199 }
200
201 @Override
202 public Collection<String> getAllGroups() {
203 return this.getGroups();
204 }
205
206 @Override
207 public Collection<String> getRoles() {
208 return this.roleList.getList();
209 }
210
211 @Override
212 public Collection<String> getAllRoles() {
213 return this.getRoles();
214 }
215 }