1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.security.Principal;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.jetspeed.Jetspeed;
24 import org.apache.jetspeed.administration.PortalConfiguration;
25 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
26 import org.apache.jetspeed.om.page.Page;
27 import org.apache.jetspeed.page.PageManager;
28 import org.apache.jetspeed.request.RequestContext;
29
30 /***
31 * Abstracted behavior of security checks for portlet actions
32 *
33 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34 * @version $Id: $
35 */
36 public class PortletActionSecurityConstraintsBehavior
37 extends PortletActionSecurityPathBehavior
38 implements PortletActionSecurityBehavior
39 {
40 protected Log log = LogFactory.getLog(PortletActionSecurityConstraintsBehavior.class);
41 protected String guest = "guest";
42
43 public PortletActionSecurityConstraintsBehavior(PageManager pageManager)
44 {
45 this( pageManager, Boolean.FALSE );
46 }
47 public PortletActionSecurityConstraintsBehavior(PageManager pageManager, Boolean enableCreateUserPagesFromRolesOnEdit )
48 {
49 super( pageManager, enableCreateUserPagesFromRolesOnEdit );
50 PortalConfiguration config = Jetspeed.getConfiguration();
51 if (config != null)
52 {
53 guest = config.getString("default.user.principal");
54 }
55 }
56
57 public boolean checkAccess(RequestContext context, String action)
58 {
59 Page page = context.getPage();
60 try
61 {
62 page.checkAccess(action);
63 }
64 catch (Exception e)
65 {
66 Principal principal = context.getRequest().getUserPrincipal();
67 String userName = this.guest;
68 if (principal != null)
69 userName = principal.getName();
70 log.warn("Insufficient access to page " + page.getPath() + " by user " + userName);
71 return false;
72 }
73 return true;
74 }
75 }