KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > acting > DelegatingAuthorizerAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: DelegatingAuthorizerAction.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.cms.cocoon.acting;
21
22 import java.util.Collections JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.avalon.framework.parameters.Parameters;
26 import org.apache.cocoon.environment.ObjectModelHelper;
27 import org.apache.cocoon.environment.Redirector;
28 import org.apache.cocoon.environment.Request;
29 import org.apache.cocoon.environment.Session;
30 import org.apache.cocoon.environment.SourceResolver;
31 import org.apache.lenya.util.Stack;
32
33 /**
34  * AuthorizerAction that delegates the authorizing to an AccessController.
35  */

36 public class DelegatingAuthorizerAction extends AccessControlAction {
37
38     /**
39      * @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)
40      */

41     public Map JavaDoc act(
42         Redirector redirector,
43         SourceResolver resolver,
44         Map JavaDoc objectModel,
45         String JavaDoc src,
46         Parameters parameters)
47         throws Exception JavaDoc {
48
49         return super.act(redirector, resolver, objectModel, src, parameters);
50     }
51
52     /**
53      * @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)
54      */

55     protected Map JavaDoc doAct(
56         Redirector redirector,
57         SourceResolver resolver,
58         Map JavaDoc objectModel,
59         String JavaDoc source,
60         Parameters parameters)
61         throws Exception JavaDoc {
62
63         Request request = ObjectModelHelper.getRequest(objectModel);
64         
65         setHistory(request);
66
67         boolean authorized = getAccessController().authorize(request);
68
69         Map JavaDoc result = null;
70         if (authorized) {
71             result = Collections.EMPTY_MAP;
72         }
73
74         return result;
75     }
76
77     public static final String JavaDoc HISTORY =
78         DelegatingAuthorizerAction.class.getPackage().getName() + ".History";
79
80     /**
81      * Adds the current URL to the history.
82      * @param request The request.
83      */

84     protected void setHistory(Request request) {
85         Session session = request.getSession(true);
86
87         Stack history = (Stack) session.getAttribute(HISTORY);
88
89         if (history == null) {
90             history = new Stack(10);
91             session.setAttribute(HISTORY, history);
92         }
93         
94         String JavaDoc url = request.getRequestURI();
95         String JavaDoc context = request.getContextPath();
96         if (context == null) {
97             context = "";
98         }
99         url = url.substring(context.length());
100
101         history.push(url);
102
103     }
104     
105 }
106
Popular Tags