KickJava   Java API By Example, From Geeks To Geeks.

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


1 package info.magnolia.cms.security;
2
3 import java.util.Collection JavaDoc;
4 import java.util.Collections JavaDoc;
5
6 import org.apache.commons.lang.StringUtils;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10
11 /**
12  * Date: Oct 26, 2005 Time: 5:02:46 PM
13  * @author Sameer Charles
14  * @version $Revision: 6341 $ ($Author: philipp $)
15  */

16 public class DummyUser implements User {
17
18     /**
19      * Logger
20      */

21     private static Logger log = LoggerFactory.getLogger(DummyUser.class);
22
23     /**
24      * Default language
25      */

26     private static final String JavaDoc DEFAULT_LANGUAGE = "en";
27
28     /**
29      * package private constructor
30      */

31     DummyUser() {
32         log.info("Initializing dummy user - Anonymous");
33         log.info("This area and/or instance is not secured");
34     }
35
36     /**
37      * has full access
38      * @param roleName the name of the role
39      * @return true if in role
40      */

41     public boolean hasRole(String JavaDoc roleName) {
42         return true;
43     }
44
45     /**
46      * Simply log that its a dummy user
47      * @param roleName
48      */

49     public void removeRole(String JavaDoc roleName) throws UnsupportedOperationException JavaDoc {
50         log.debug("User [ Anonymous ] has no roles");
51     }
52
53     /**
54      * Simply log that its a dummy user
55      * @param roleName the name of the role
56      */

57     public void addRole(String JavaDoc roleName) throws UnsupportedOperationException JavaDoc {
58         log.debug("No roles can be attached to user [ Anonymous ]");
59     }
60
61     /**
62      * Is this user in a specified group?
63      * @param groupName
64      * @return true if in group
65      */

66     public boolean inGroup(String JavaDoc groupName) {
67         return true;
68     }
69
70     /**
71      * Remove a group. Implementation is optional
72      * @param groupName
73      */

74     public void removeGroup(String JavaDoc groupName) throws UnsupportedOperationException JavaDoc {
75         log.debug("User [ Anonymous ] has no groups");
76     }
77
78     /**
79      * Adds this user to a group. Implementation is optional
80      * @param groupName
81      */

82     public void addGroup(String JavaDoc groupName) throws UnsupportedOperationException JavaDoc {
83         log.debug("No groups can be attached to user [ Anonymous ]");
84     }
85
86     /**
87      * get user language
88      * @return language string
89      */

90
91     public String JavaDoc getLanguage() {
92         return DEFAULT_LANGUAGE;
93     }
94
95     /**
96      * get user name
97      * @return name string
98      */

99     public String JavaDoc getName() {
100         return UserManager.ANONYMOUS_USER;
101     }
102
103     public String JavaDoc getPassword() {
104         return StringUtils.EMPTY;
105     }
106
107     /**
108      * @see info.magnolia.cms.security.User#getGroups()
109      */

110     public Collection JavaDoc getGroups() {
111         return Collections.EMPTY_LIST;
112     }
113
114     /**
115      * @see info.magnolia.cms.security.User#getRoles()
116      */

117     public Collection JavaDoc getRoles() {
118         return Collections.EMPTY_LIST;
119     }
120 }
121
Popular Tags