001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: DelegatingAuthorizerAction.java 473861 2006-11-12 03:51:14Z gregor $ */
020:
021: package org.apache.lenya.cms.cocoon.acting;
022:
023: import java.util.Collections;
024: import java.util.Map;
025:
026: import org.apache.avalon.excalibur.pool.Poolable;
027: import org.apache.avalon.framework.parameters.Parameters;
028: import org.apache.cocoon.environment.ObjectModelHelper;
029: import org.apache.cocoon.environment.Redirector;
030: import org.apache.cocoon.environment.Request;
031: import org.apache.cocoon.environment.Session;
032: import org.apache.cocoon.environment.SourceResolver;
033: import org.apache.lenya.util.Stack;
034:
035: /**
036: * AuthorizerAction that delegates the authorizing to an AccessController.
037: */
038: public class DelegatingAuthorizerAction extends AccessControlAction
039: implements Poolable {
040:
041: /**
042: * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
043: */
044: public Map act(Redirector redirector, SourceResolver resolver,
045: Map objectModel, String src, Parameters parameters)
046: throws Exception {
047:
048: return super .act(redirector, resolver, objectModel, src,
049: parameters);
050: }
051:
052: /**
053: * @see org.apache.lenya.cms.cocoon.acting.AccessControlAction#doAct(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
054: */
055: protected Map doAct(Redirector redirector, SourceResolver resolver,
056: Map objectModel, String source, Parameters parameters)
057: throws Exception {
058:
059: Request request = ObjectModelHelper.getRequest(objectModel);
060:
061: setHistory(request);
062:
063: boolean authorized = getAccessController().authorize(request);
064:
065: Map result = null;
066: if (authorized) {
067: result = Collections.EMPTY_MAP;
068: }
069:
070: return result;
071: }
072:
073: /**
074: * <code>HISTORY</code> Name of the session attribute that holds the history
075: */
076: public static final String HISTORY = DelegatingAuthorizerAction.class
077: .getPackage().getName()
078: + ".History";
079:
080: /**
081: * Adds the current URL to the history.
082: * @param request The request.
083: */
084: protected void setHistory(Request request) {
085: Session session = request.getSession(true);
086:
087: Stack history = (Stack) session.getAttribute(HISTORY);
088:
089: if (history == null) {
090: history = new Stack(10);
091: session.setAttribute(HISTORY, history);
092: }
093:
094: String url = request.getRequestURI();
095: String context = request.getContextPath();
096: if (context == null) {
097: context = "";
098: }
099: url = url.substring(context.length());
100:
101: history.push(url);
102:
103: }
104:
105: }
|