01: /**
02: *
03: */package ru.emdev.EmForge.security.web;
04:
05: import org.apache.commons.lang.StringUtils;
06:
07: /**
08: * Contains all site roles
09: *
10: * @author szakusov, 14.03.2008: Implemented to keep all site roles in one place
11: */
12: public enum SiteRole {
13:
14: ADMIN("ROLE_EMFORGEADMIN", "EmForge Admin",
15: "allows to manipulate EmForge"), USER("ROLE_EMFORGEUSER",
16: "EmForge User", "default role for any registered user"), WRITER(
17: "ROLE_WIKIWRITER", "Wiki Writer",
18: "allows to create/edit/delete wiki-pages and add/delete attachments");
19:
20: private String m_id;
21: private String m_name;
22: private String m_help;
23:
24: /**
25: * @param i_id is a role id
26: * @param i_name is a role name
27: * @param i_help is a help string
28: */
29: private SiteRole(String i_id, String i_name, String i_help) {
30:
31: m_id = i_id;
32: m_name = i_name;
33: m_help = i_help;
34: }
35:
36: /**
37: * @return the role id
38: */
39: public String getId() {
40:
41: return m_id;
42: }
43:
44: /**
45: * @return the role name
46: */
47: public String getName() {
48:
49: return m_name;
50: }
51:
52: /**
53: * @param i_roleName a role name to check
54: * @return <code>True</code> if the specified role is site role, otherwise <code>False</code>
55: */
56: public static boolean isSiteRole(String i_roleName) {
57:
58: boolean result = false;
59:
60: for (SiteRole role : SiteRole.values()) {
61: if (StringUtils.equals(role.m_id, i_roleName)) {
62: result = true;
63: break;
64: }
65: }
66: return result;
67: }
68:
69: /**
70: * @see java.lang.Enum#toString()
71: */
72: @Override
73: public String toString() {
74:
75: return m_id + " " + m_help;
76: }
77:
78: }
|