KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > tools > acting > CheckAccessAction


1 /*
2  * Copyright 1999-2005 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 package org.apache.cocoon.portal.tools.acting;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.avalon.framework.thread.ThreadSafe;
22 import org.apache.cocoon.ProcessingException;
23 import org.apache.cocoon.acting.ServiceableAction;
24 import org.apache.cocoon.environment.Redirector;
25 import org.apache.cocoon.environment.SourceResolver;
26 import org.apache.cocoon.portal.tools.PortalToolManager;
27 import org.apache.cocoon.portal.tools.service.UserRightsService;
28
29 /**
30  * Check whether the current user is allowed to access the given page.
31  *
32  * @version CVS $Id: CheckAccessAction.java 156712 2005-03-09 23:27:35Z antonio $
33  */

34 public class CheckAccessAction
35 extends ServiceableAction
36 implements 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 JavaDoc act(Redirector redirector,
42                    SourceResolver resolver,
43                    Map JavaDoc objectModel,
44                    String JavaDoc source,
45                    Parameters parameters)
46     throws Exception JavaDoc {
47         String JavaDoc url = parameters.getParameter("url");
48         PortalToolManager ptm = (PortalToolManager) this.manager.lookup(PortalToolManager.ROLE);
49         try {
50             UserRightsService userRightsService = ptm.getUserRightsService();
51             // FIXME: replace the throw with something else
52
if (!userRightsService.userIsAllowed(url, ptm.getPortalObjects().getPortalService().getComponentManager().getProfileManager().getUser())) {
53                 throw new ProcessingException(
54                     "You are not allowed to request this page.");
55             }
56         } finally {
57             this.manager.release(ptm);
58         }
59         return EMPTY_MAP;
60     }
61
62 }
Popular Tags