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 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 RoleList roleList;
68
69
70
71
72 private GroupList groupList;
73
74
75
76
77 protected ExternalUser(Subject subject) {
78 final Set<Entity> principalDetails = subject.getPrincipals(Entity.class);
79 final Iterator<Entity> entityIterator = principalDetails.iterator();
80 this.userDetails = entityIterator.next();
81
82 final Set<RoleList> principalRoles = subject.getPrincipals(RoleList.class);
83 final Iterator<RoleList> roleListIterator = principalRoles.iterator();
84 this.roleList = roleListIterator.next();
85
86 final Set<GroupList> principalGroups = subject.getPrincipals(GroupList.class);
87 final Iterator<GroupList> groupListIterator = principalGroups.iterator();
88 this.groupList = groupListIterator.next();
89 }
90
91 public boolean hasRole(String roleName) {
92 return this.roleList.has(roleName);
93 }
94
95 public void removeRole(String roleName) {
96 throw new UnsupportedOperationException("not implemented for this ExternalUser");
97 }
98
99 public void addRole(String roleName) {
100 throw new UnsupportedOperationException("not implemented for this ExternalUser");
101 }
102
103
104
105
106
107 public boolean inGroup(String groupName) {
108 return this.groupList.has(groupName);
109 }
110
111
112
113
114 public void removeGroup(String groupName) throws UnsupportedOperationException {
115 throw new UnsupportedOperationException("not implemented for this ExternalUser");
116 }
117
118
119
120
121 public void addGroup(String groupName) throws UnsupportedOperationException {
122 throw new UnsupportedOperationException("not implemented for this ExternalUser");
123 }
124
125 public boolean isEnabled() {
126 return true;
127 }
128
129 public void setEnabled(boolean enabled) {
130 }
131
132 public String getLanguage() {
133 String language = (String) this.userDetails.getProperty(Entity.LANGUAGE);
134 if (null == language) {
135 language = MgnlContext.getSystemContext().getLocale().getLanguage();
136 }
137 return language;
138 }
139
140 public String getName() {
141 return (String) this.userDetails.getProperty(Entity.NAME);
142 }
143
144 public String getPassword() {
145 return (String) this.userDetails.getProperty(Entity.PASSWORD);
146 }
147
148 public String getProperty(String propertyName) {
149 throw new UnsupportedOperationException("not implemented for this ExternalUser");
150 }
151
152 public void setProperty(String propertyName, String value) {
153 throw new UnsupportedOperationException("not implemented for this ExternalUser");
154 }
155
156 public Collection<String> getGroups() {
157 return this.groupList.getList();
158 }
159
160 public Collection<String> getAllGroups() {
161 return this.getGroups();
162 }
163
164 public Collection<String> getRoles() {
165 return this.roleList.getList();
166 }
167
168 public Collection<String> getAllRoles() {
169 return this.getRoles();
170 }
171 }