KickJava   Java API By Example, From Geeks To Geeks.

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


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: AccessControlAction.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.avalon.framework.service.ServiceSelector;
27 import org.apache.cocoon.acting.ConfigurableServiceableAction;
28 import org.apache.cocoon.environment.ObjectModelHelper;
29 import org.apache.cocoon.environment.Redirector;
30 import org.apache.cocoon.environment.Request;
31 import org.apache.cocoon.environment.SourceResolver;
32 import org.apache.lenya.ac.AccessController;
33 import org.apache.lenya.ac.AccessControllerResolver;
34 import org.apache.lenya.util.ServletHelper;
35
36 public abstract class AccessControlAction extends ConfigurableServiceableAction {
37
38     private AccessController accessController;
39
40     /**
41      * <p>
42      * Invokes the access control functionality.
43      * If no access controller was found for the requested URL, an empty map is returned.
44      * </p>
45      * <p>
46      * This is a template method. Implement doAct() to add your functionality.
47      * </p>
48      * @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)
49      */

50     public Map JavaDoc act(
51         Redirector redirector,
52         SourceResolver sourceResolver,
53         Map JavaDoc objectModel,
54         String JavaDoc source,
55         Parameters parameters)
56         throws Exception JavaDoc {
57
58         ServiceSelector selector = null;
59         AccessControllerResolver resolver = null;
60         accessController = null;
61
62         Request request = ObjectModelHelper.getRequest(objectModel);
63
64         Map JavaDoc result = null;
65
66         try {
67             selector =
68                 (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
69                 
70             getLogger().debug("Resolving AC resolver for type [" + AccessControllerResolver.DEFAULT_RESOLVER + "]");
71             resolver =
72                 (AccessControllerResolver) selector.select(
73                     AccessControllerResolver.DEFAULT_RESOLVER);
74             getLogger().debug("Resolved AC resolver [" + resolver + "]");
75
76             String JavaDoc webappUrl = ServletHelper.getWebappURI(request);
77             accessController = resolver.resolveAccessController(webappUrl);
78
79             if (accessController == null) {
80                 result = Collections.EMPTY_MAP;
81             } else {
82                 accessController.setupIdentity(request);
83                 result = doAct(redirector, sourceResolver, objectModel, source, parameters);
84             }
85
86         } finally {
87             if (selector != null) {
88                 if (resolver != null) {
89                     selector.release(resolver);
90                 }
91                 manager.release(selector);
92             }
93         }
94         return result;
95     }
96
97     /**
98      * The actual act method.
99      * @param redirector The <code>Redirector</code> in charge
100      * @param resolver The <code>SourceResolver</code> in charge
101      * @param objectModel The <code>Map</code> with object of the
102      * calling environment which can be used
103      * to select values this controller may need
104      * (ie Request, Response).
105      * @param source A source <code>String</code> to the Action
106      * @param parameters The <code>Parameters</code> for this invocation
107      * @return Map The returned <code>Map</code> object with
108      * sitemap substitution values which can be used
109      * in subsequent elements attributes like SRC=
110      * using a xpath like expression: SRC="mydir/{myval}/foo"
111      * If the return value is null the processing inside
112      * the <map:act> element of the sitemap will
113      * be skipped.
114      * @exception Exception Indicates something is totally wrong
115      */

116     protected abstract Map JavaDoc doAct(
117         Redirector redirector,
118         SourceResolver resolver,
119         Map JavaDoc objectModel,
120         String JavaDoc source,
121         Parameters parameters)
122         throws Exception JavaDoc;
123
124     /**
125      * Returns the access controller.
126      * @return An access controller.
127      */

128     public AccessController getAccessController() {
129         return accessController;
130     }
131
132 }
133
Popular Tags