View Javadoc

1   /*
2    * Copyright 2000-2001,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.portlets.security;
18  
19  import java.util.Iterator;
20  
21  // velocity
22  import org.apache.velocity.context.Context;
23  
24  // turbine util
25  import org.apache.turbine.util.RunData;
26  import org.apache.turbine.util.StringUtils;
27  
28  // jetspeed services
29  import org.apache.jetspeed.services.JetspeedSecurity;
30  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31  import org.apache.jetspeed.services.logging.JetspeedLogger;
32  import org.apache.jetspeed.services.resources.JetspeedResources;
33  
34  // jetspeed velocity
35  import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
36  import org.apache.jetspeed.portal.portlets.VelocityPortlet;
37  
38  
39  /***
40   * This action sets up the template context for browsing of security roles in the Turbine database.
41   *
42   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
43   * @version $Id: RoleBrowserAction.java,v 1.9 2004/02/23 02:53:08 jford Exp $
44   */
45  public class RoleBrowserAction extends VelocityPortletAction
46  {
47      
48      /***
49       * Static initialization of the logger for this class
50       */    
51      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(RoleBrowserAction.class.getName());     
52      
53      /***
54       * Build the maximized state content for this portlet. (Same as normal state).
55       *
56       * @param portlet The velocity-based portlet that is being built.
57       * @param context The velocity context for this request.
58       * @param rundata The turbine rundata context for this request.
59       */
60      protected void buildMaximizedContext( VelocityPortlet portlet,
61                                            Context context,
62                                            RunData rundata )
63      {
64          buildNormalContext( portlet, context, rundata);
65      }
66  
67      /***
68       * Build the configure state content for this portlet.
69       * TODO: we could configure this portlet with configurable skins, etc..
70       *
71       * @param portlet The velocity-based portlet that is being built.
72       * @param context The velocity context for this request.
73       * @param rundata The turbine rundata context for this request.
74       */
75      protected void buildConfigureContext( VelocityPortlet portlet,
76                                            Context context,
77                                            RunData rundata )
78      {
79  
80          buildNormalContext( portlet, context, rundata);
81      }
82  
83      /***
84       * Build the normal state content for this portlet.
85       *
86       * @param portlet The velocity-based portlet that is being built.
87       * @param context The velocity context for this request.
88       * @param rundata The turbine rundata context for this request.
89       */
90      protected void buildNormalContext( VelocityPortlet portlet,
91                                         Context context,
92                                         RunData rundata )
93      {
94          try
95          {
96              Iterator roles = JetspeedSecurity.getRoles();
97              context.put(SecurityConstants.CONTEXT_ROLES, roles);
98          }
99          catch (Exception e)
100         {
101            // log the error msg
102             logger.error("Error in Jetspeed Role Security", e);
103 
104             rundata.setMessage("Error in Jetspeed Role Security: " + e.toString());
105             rundata.setStackTrace(StringUtils.stackTrace(e), e);
106             rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error"));
107         }
108     }
109 
110 
111 }