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.cocoon.portal.tools.acting;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.avalon.framework.thread.ThreadSafe;
23: import org.apache.cocoon.ProcessingException;
24: import org.apache.cocoon.acting.ServiceableAction;
25: import org.apache.cocoon.environment.Redirector;
26: import org.apache.cocoon.environment.SourceResolver;
27: import org.apache.cocoon.portal.tools.PortalToolManager;
28: import org.apache.cocoon.portal.tools.service.UserRightsService;
29:
30: /**
31: * Check whether the current user is allowed to access the given page.
32: *
33: * @version CVS $Id: CheckAccessAction.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class CheckAccessAction extends ServiceableAction implements
36: ThreadSafe {
37:
38: /* (non-Javadoc)
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 act(Redirector redirector, SourceResolver resolver,
42: Map objectModel, String source, Parameters parameters)
43: throws Exception {
44: String url = parameters.getParameter("url");
45: PortalToolManager ptm = (PortalToolManager) this .manager
46: .lookup(PortalToolManager.ROLE);
47: try {
48: UserRightsService userRightsService = ptm
49: .getUserRightsService();
50: // FIXME: replace the throw with something else
51: if (!userRightsService.userIsAllowed(url, ptm
52: .getPortalObjects().getPortalService()
53: .getComponentManager().getProfileManager()
54: .getUser())) {
55: throw new ProcessingException(
56: "You are not allowed to request this page.");
57: }
58: } finally {
59: this.manager.release(ptm);
60: }
61: return EMPTY_MAP;
62: }
63:
64: }
|