001: package org.apache.turbine.modules.actions;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import org.apache.turbine.modules.Action;
026: import org.apache.turbine.services.security.TurbineSecurity;
027: import org.apache.turbine.util.RunData;
028: import org.apache.turbine.util.security.AccessControlList;
029: import org.apache.turbine.util.security.TurbineSecurityException;
030:
031: import org.apache.turbine.om.security.User;
032:
033: /**
034: * This action doPerforms an Access Control List and places it into
035: * the RunData object, so it is easily available to modules. The ACL
036: * is also placed into the session. Modules can null out the ACL to
037: * force it to be rebuilt based on more information.
038: *
039: * <p>
040: *
041: * Turbine uses a User-Role-Permission arrangement for access control.
042: * Users are assigned Roles. Roles are assigned Permissions. Turbine
043: * modules then check the Permission required for an action or
044: * information with the set of Permissions currently associated with
045: * the session (which are dependent on the user associated with the
046: * session.)
047: *
048: * <p>
049: *
050: * The criteria for assigning Roles/Permissions is application
051: * dependent, in some cases an application may change a User's Roles
052: * during the session. To achieve flexibility, the ACL takes an
053: * Object parameter, which the application can use to doPerform the
054: * ACL.
055: *
056: * <p>
057: *
058: * This action is special in that it should only be executed by the
059: * Turbine servlet.
060: *
061: * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
062: * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
063: * @author <a href="quintonm@bellsouth.net">Quinton McCombs</a>
064: * @version $Id: AccessController.java 534527 2007-05-02 16:10:59Z tv $
065: */
066: public class AccessController extends Action {
067:
068: /** Logging */
069: private static Log log = LogFactory.getLog(AccessController.class);
070:
071: /**
072: * If there is a user and the user is logged in, doPerform will
073: * set the RunData ACL. The list is first sought from the current
074: * session, otherwise it is loaded through
075: * <code>TurbineSecurity.getACL()</code> and added to the current
076: * session.
077: *
078: * @see org.apache.turbine.services.security.TurbineSecurity
079: * @param data Turbine information.
080: * @exception TurbineSecurityException problem with the security service.
081: */
082: public void doPerform(RunData data) throws TurbineSecurityException {
083: User user = data.getUser();
084:
085: if (!TurbineSecurity.isAnonymousUser(user)
086: && user.hasLoggedIn()) {
087: log.debug("Fetching ACL for " + user.getName());
088: AccessControlList acl = (AccessControlList) data
089: .getSession().getAttribute(
090: AccessControlList.SESSION_KEY);
091: if (acl == null) {
092: log
093: .debug("No ACL found in Session, building fresh ACL");
094: acl = TurbineSecurity.getACL(user);
095: data.getSession().setAttribute(
096: AccessControlList.SESSION_KEY, acl);
097:
098: log.debug("ACL is " + acl);
099: }
100: data.setACL(acl);
101: }
102: }
103: }
|