1 package net.sourceforge.blogentis.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import net.sourceforge.blogentis.om.Blog;
26
27 import org.apache.turbine.modules.actions.VelocitySecureAction;
28 import org.apache.turbine.util.RunData;
29 import org.apache.turbine.util.security.AccessControlList;
30
31 /***
32 * @author abas
33 */
34 public abstract class SecureBlogAction extends VelocitySecureAction {
35 /***
36 * Get the array of permissions this actions needs. The logged-in user
37 * must have at least one of them to be allowed access to this screen.
38 *
39 * @return the array of permissions.
40 */
41 protected abstract String[] getPermissions();
42
43 protected final boolean isAuthorized(RunData data) {
44 if (!data.getUser().hasLoggedIn())
45 return false;
46 BlogParameterParser pp = (BlogParameterParser)data.getParameters();
47 Blog blog = pp.getBlog();
48 if (blog == null)
49 return false;
50 AccessControlList acl = data.getACL();
51 if (acl == null)
52 return false;
53 String[] permissions = getPermissions();
54 for(int i = 0; i < permissions.length; i++)
55 if (acl.hasPermission(permissions[i], blog.getName()))
56 return true;
57 return false;
58 }
59 }