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.util.Collection;
42 import java.util.Iterator;
43 import java.util.Set;
44 import java.io.Serializable;
45
46 import javax.security.auth.Subject;
47
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51
52
53
54
55
56
57
58 public class ExternalUser extends AbstractUser implements Serializable {
59 private static final Logger log = LoggerFactory.getLogger(ExternalUser.class);
60
61
62
63
64 private Entity userDetails;
65
66
67
68
69 private RoleList roleList;
70
71
72
73
74 private GroupList groupList;
75
76
77
78
79 protected ExternalUser(Subject subject) {
80 final Set<Entity> principalDetails = subject.getPrincipals(Entity.class);
81 final Iterator<Entity> entityIterator = principalDetails.iterator();
82 this.userDetails = entityIterator.next();
83
84 final Set<RoleList> principalRoles = subject.getPrincipals(RoleList.class);
85 final Iterator<RoleList> roleListIterator = principalRoles.iterator();
86 this.roleList = roleListIterator.next();
87
88 final Set<GroupList> principalGroups = subject.getPrincipals(GroupList.class);
89 final Iterator<GroupList> groupListIterator = principalGroups.iterator();
90 this.groupList = groupListIterator.next();
91 }
92
93 public boolean hasRole(String roleName) {
94 return this.roleList.has(roleName);
95 }
96
97 public void removeRole(String roleName) {
98 throw new UnsupportedOperationException("not implemented for this ExternalUser");
99 }
100
101 public void addRole(String roleName) {
102 throw new UnsupportedOperationException("not implemented for this ExternalUser");
103 }
104
105
106
107
108
109 public boolean inGroup(String groupName) {
110 return this.groupList.has(groupName);
111 }
112
113
114
115
116 public void removeGroup(String groupName) throws UnsupportedOperationException {
117 throw new UnsupportedOperationException("not implemented for this ExternalUser");
118 }
119
120
121
122
123 public void addGroup(String groupName) throws UnsupportedOperationException {
124 throw new UnsupportedOperationException("not implemented for this ExternalUser");
125 }
126
127 public boolean isEnabled() {
128 return true;
129 }
130
131 public void setEnabled(boolean enabled) {
132 }
133
134 public String getLanguage() {
135 String language = (String) this.userDetails.getProperty(Entity.LANGUAGE);
136 if (null == language) {
137 language = MgnlContext.getSystemContext().getLocale().getLanguage();
138 }
139 return language;
140 }
141
142 public String getName() {
143 return (String) this.userDetails.getProperty(Entity.NAME);
144 }
145
146
147
148
149
150 public String getPassword() {
151 return (String) this.userDetails.getProperty(Entity.PASSWORD);
152 }
153
154 public String getProperty(String propertyName) {
155 throw new UnsupportedOperationException("not implemented for this ExternalUser");
156 }
157
158 public void setProperty(String propertyName, String value) {
159 throw new UnsupportedOperationException("not implemented for this ExternalUser");
160 }
161
162 public Collection<String> getGroups() {
163 return this.groupList.getList();
164 }
165
166 public Collection<String> getAllGroups() {
167 return this.getGroups();
168 }
169
170 public Collection<String> getRoles() {
171 return this.roleList.getList();
172 }
173
174 public Collection<String> getAllRoles() {
175 return this.getRoles();
176 }
177 }