KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > security > ExternalUser


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.security;
14
15 import info.magnolia.cms.security.auth.Entity;
16 import info.magnolia.cms.security.auth.GroupList;
17 import info.magnolia.cms.security.auth.RoleList;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import javax.security.auth.Subject JavaDoc;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29 /**
30  * This class wraps a user content object to provide some nice methods
31  * @author philipp
32  * @author Sameer Charles
33  * @version $Revision:2558 $ ($Author:scharles $)
34  */

35 public class ExternalUser implements User {
36
37     public static Logger log = LoggerFactory.getLogger(ExternalUser.class);
38
39     /**
40      * user properties
41      */

42     private Entity userDetails;
43
44     /**
45      * user roles
46      */

47     private RoleList roleList;
48
49     /**
50      * user groups
51      */

52     private GroupList groupList;
53
54     /**
55      * @param subject as created by login module
56      */

57     protected ExternalUser(Subject JavaDoc subject) {
58         Set JavaDoc principalSet = subject.getPrincipals(Entity.class);
59         Iterator JavaDoc entityIterator = principalSet.iterator();
60         this.userDetails = (Entity) entityIterator.next();
61         principalSet = subject.getPrincipals(RoleList.class);
62         Iterator JavaDoc roleListIterator = principalSet.iterator();
63         this.roleList = (RoleList) roleListIterator.next();
64         principalSet = subject.getPrincipals(GroupList.class);
65         Iterator JavaDoc groupListIterator = principalSet.iterator();
66         this.groupList = (GroupList) groupListIterator.next();
67     }
68
69     /*
70      * (non-Javadoc)
71      * @see info.magnolia.cms.security.UserInterface#hasRole(java.lang.String)
72      */

73     public boolean hasRole(String JavaDoc roleName) {
74         return this.roleList.has(roleName);
75     }
76
77     /*
78      * (non-Javadoc)
79      * @see info.magnolia.cms.security.UserInterface#removeRole(java.lang.String)
80      */

81     public void removeRole(String JavaDoc roleName) {
82         throw new UnsupportedOperationException JavaDoc("not implemented for this ExternalUser");
83     }
84
85     /*
86      * (non-Javadoc)
87      * @see info.magnolia.cms.security.UserInterface#addRole(java.lang.String)
88      */

89     public void addRole(String JavaDoc roleName) {
90         throw new UnsupportedOperationException JavaDoc("not implemented for this ExternalUser");
91     }
92
93     /**
94      * Is this user in a specified group?
95      * @param groupName
96      * @return true if in group
97      */

98     public boolean inGroup(String JavaDoc groupName) {
99         return this.groupList.has(groupName);
100     }
101
102     /**
103      * Remove a group. Implementation is optional
104      * @param groupName
105      */

106     public void removeGroup(String JavaDoc groupName) throws UnsupportedOperationException JavaDoc {
107         throw new UnsupportedOperationException JavaDoc("not implemented for this ExternalUser");
108     }
109
110     /**
111      * Adds this user to a group. Implementation is optional
112      * @param groupName
113      */

114     public void addGroup(String JavaDoc groupName) throws UnsupportedOperationException JavaDoc {
115         throw new UnsupportedOperationException JavaDoc("not implemented for this ExternalUser");
116     }
117
118     /*
119      * (non-Javadoc)
120      * @see info.magnolia.cms.security.UserInterface#getLanguage()
121      */

122
123     public String JavaDoc getLanguage() {
124         return (String JavaDoc) this.userDetails.getProperty(Entity.LANGUAGE);
125     }
126
127     /*
128      * (non-Javadoc)
129      * @see info.magnolia.cms.security.UserInterface#getName()
130      */

131     public String JavaDoc getName() {
132         return (String JavaDoc) this.userDetails.getProperty(Entity.NAME);
133     }
134
135     /**
136      * get user password
137      * @return password string
138      */

139     public String JavaDoc getPassword() {
140         return (String JavaDoc) this.userDetails.getProperty(Entity.PASSWORD);
141     }
142
143     /**
144      * @see info.magnolia.cms.security.User#getGroups()
145      */

146     public Collection JavaDoc getGroups() {
147         return this.groupList.getList();
148     }
149
150     /**
151      * @see info.magnolia.cms.security.User#getRoles()
152      */

153     public Collection JavaDoc getRoles() {
154         return this.roleList.getList();
155     }
156 }
Popular Tags