01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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 extends
37: PortletActionSecurityPathBehavior implements
38: PortletActionSecurityBehavior {
39: protected Log log = LogFactory
40: .getLog(PortletActionSecurityConstraintsBehavior.class);
41: protected String guest = "guest";
42:
43: public PortletActionSecurityConstraintsBehavior(
44: PageManager pageManager) {
45: this (pageManager, Boolean.FALSE);
46: }
47:
48: public PortletActionSecurityConstraintsBehavior(
49: PageManager pageManager,
50: Boolean enableCreateUserPagesFromRolesOnEdit) {
51: super (pageManager, enableCreateUserPagesFromRolesOnEdit);
52: PortalConfiguration config = Jetspeed.getConfiguration();
53: if (config != null) {
54: guest = config.getString("default.user.principal");
55: }
56: }
57:
58: public boolean checkAccess(RequestContext context, String action) {
59: Page page = context.getPage();
60: try {
61: page.checkAccess(action);
62: } catch (Exception e) {
63: Principal principal = context.getRequest()
64: .getUserPrincipal();
65: String userName = this .guest;
66: if (principal != null)
67: userName = principal.getName();
68: log.warn("Insufficient access to page " + page.getPath()
69: + " by user " + userName);
70: return false;
71: }
72: return true;
73: }
74: }
|