1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.util.StringUtil;
30
31 import java.util.Vector;
32
33 import javax.servlet.http.HttpServletRequest;
34
35
36
37 /***
38 * <p>
39 * This class represents a "granted-privileges"-tag in dbforms-config.xml
40 * </p>
41 *
42 * @author Joachim Peer
43 */
44 public class GrantedPrivileges implements java.io.Serializable {
45 private static Log logCat = LogFactory.getLog(GrantedPrivileges.class
46 .getName());
47
48 /*** DOCUMENT ME! */
49 public static final int PRIVILEG_SELECT = 0;
50
51 /*** DOCUMENT ME! */
52 public static final int PRIVILEG_INSERT = 1;
53
54 /*** DOCUMENT ME! */
55 public static final int PRIVILEG_UPDATE = 2;
56
57 /*** DOCUMENT ME! */
58 public static final int PRIVILEG_DELETE = 3;
59 private Vector[] grantedRoles;
60
61 /***
62 * Creates a new GrantedPrivileges object.
63 */
64 public GrantedPrivileges() {
65 grantedRoles = new Vector[4];
66
67
68 }
69
70 /***
71 * DOCUMENT ME!
72 *
73 * @param delete DOCUMENT ME!
74 */
75 public void setDelete(String delete) {
76 logCat.info("delete");
77 grantedRoles[PRIVILEG_DELETE] = StringUtil.splitString(delete, ",;~");
78 }
79
80
81 /***
82 * DOCUMENT ME!
83 *
84 * @param insert DOCUMENT ME!
85 */
86 public void setInsert(String insert) {
87 logCat.info("insert");
88 grantedRoles[PRIVILEG_INSERT] = StringUtil.splitString(insert, ",;~");
89 }
90
91
92 /***
93 * DOCUMENT ME!
94 *
95 * @param select DOCUMENT ME!
96 */
97 public void setSelect(String select) {
98 logCat.info("select");
99 grantedRoles[PRIVILEG_SELECT] = StringUtil.splitString(select, ",;~");
100 }
101
102
103 /***
104 * DOCUMENT ME!
105 *
106 * @param update DOCUMENT ME!
107 */
108 public void setUpdate(String update) {
109 logCat.info("update");
110 grantedRoles[PRIVILEG_UPDATE] = StringUtil.splitString(update, ",;~");
111 }
112
113
114 /***
115 * DOCUMENT ME!
116 *
117 * @param request DOCUMENT ME!
118 * @param privileg DOCUMENT ME!
119 *
120 * @return DOCUMENT ME!
121 */
122 public boolean hasUserPrivileg(HttpServletRequest request,
123 int privileg) {
124 if (grantedRoles[privileg] == null) {
125 return true;
126 }
127
128 for (int i = 0; i < grantedRoles[privileg].size(); i++) {
129 String aGrantedRole = (String) grantedRoles[privileg].elementAt(i);
130
131 if (request.isUserInRole(aGrantedRole)) {
132 return true;
133 }
134 }
135
136 return false;
137 }
138 }