KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > JetspeedAccessController


1 /*
2  * Copyright 2000-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 package org.apache.jetspeed.modules.actions;
18
19 import org.apache.turbine.util.RunData;
20 import org.apache.turbine.modules.Action;
21 import org.apache.turbine.TurbineConstants;
22
23 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
24 import org.apache.jetspeed.services.logging.JetspeedLogger;
25 import org.apache.jetspeed.services.rundata.JetspeedRunData;
26 import org.apache.jetspeed.services.Profiler;
27 import org.apache.jetspeed.services.resources.JetspeedResources;
28 import org.apache.jetspeed.om.profile.Profile;
29 import org.apache.jetspeed.om.security.JetspeedUser;
30 import org.apache.jetspeed.services.security.nosecurity.FakeJetspeedUser;
31 import org.apache.jetspeed.services.JetspeedSecurity;
32
33 /**
34     Calls the profiler to load the requested PSML resource based on request params
35     Its necessary to load the profile from this action, not the SessionValidator
36     in order to get the cached ACL list from logon
37   
38 @author <a HREF="mailto:taylor@apache.org">David Sean Taylor</a>
39 @version $Id: JetspeedAccessController.java,v 1.10 2004/02/23 02:59:06 jford Exp $
40 */

41
42 public class JetspeedAccessController extends Action
43 {
44    
45     /**
46      * Static initialization of the logger for this class
47      */

48     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedAccessController.class.getName());
49     
50     public void doPerform( RunData data ) throws Exception JavaDoc
51     {
52         JetspeedUser user = (JetspeedUser)data.getUser();
53
54         getACL(data);
55         JetspeedRunData jdata = null;
56         
57         try
58         {
59             jdata = (JetspeedRunData)data;
60         }
61         catch (ClassCastException JavaDoc e)
62         {
63             logger.error("The RunData object does not implement the expected interface, "
64                        + "please verify the RunData factory settings", e);
65             return;
66         }
67
68         Profile newProfile = null;
69         Profile currentProfile = null;
70
71         try
72         {
73             // get the profile and store it in the RunData
74
newProfile = Profiler.getProfile(jdata);
75             currentProfile = jdata.getProfile();
76         }
77         catch (Throwable JavaDoc other)
78         {
79             data.setScreenTemplate(JetspeedResources.getString(TurbineConstants.TEMPLATE_ERROR));
80             String JavaDoc message = other.getMessage() != null ? other.getMessage() : other.toString();
81             data.setMessage(message);
82             data.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(other), other);
83
84             if (currentProfile == null)
85             {
86                 currentProfile = Profiler.createProfile();
87             }
88             if (newProfile == null)
89             {
90                 newProfile = Profiler.createProfile();
91             }
92             if (data.getUser() == null)
93             {
94                 JetspeedUser juser = new FakeJetspeedUser(JetspeedSecurity.getAnonymousUserName(), false);
95                 data.setUser(juser);
96             }
97         }
98
99
100         if ((currentProfile == null)
101          || (!currentProfile.equals(newProfile)))
102         {
103             // the profile changed due to the request parameters,
104
// change it in the RunData
105
jdata.setProfile(newProfile);
106         }
107  
108     }
109
110     protected void getACL(RunData data)
111     {
112         data.setACL(null);
113 /*
114         if ( data.getUser() != null && data.getUser().hasLoggedIn() )
115         {
116             AccessControlList acl = (AccessControlList)
117                 data.getSession().getValue(AccessControlList.SESSION_KEY);
118             if ( acl == null )
119             {
120                 //acl = TurbineSecurity.getACL( data.getUser() );
121                 acl = null;
122                 data.getSession().putValue( AccessControlList.SESSION_KEY,
123                                             (Object)acl );
124             }
125             data.setACL(acl);
126         }
127 */

128     }
129
130 }
Popular Tags