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.portal.security.portlets;
18  
19  //jetspeed
20  import org.apache.jetspeed.portal.Portlet;
21  import org.apache.jetspeed.portal.PortletState;
22  
23  import org.apache.jetspeed.services.JetspeedSecurity;
24  
25  //turbine
26  import org.apache.turbine.util.RunData;
27  //import org.apache.turbine.util.TurbineRuntimeException;
28  
29  
30  
31  /***
32  <p>
33  This object is used to wrap a Portlet, ensuring that access control rules are enforced.
34  </p>
35  
36  @author <A HREF="mailto:sgala@apache.org">Santiago Gala</A>
37  @author <A HREF="mailto:morciuch@apache.org">Mark Orciuch</A>
38  @version $Id: StatefulPortletWrapper.java,v 1.5 2004/02/23 03:27:46 jford Exp $
39  */
40  public class StatefulPortletWrapper extends PortletWrapper implements PortletState
41  {
42  
43      /*
44       * The portletstate of our portlet
45       */
46      private PortletState wrappedState = null;
47  
48      public StatefulPortletWrapper( Portlet inner )
49      {
50          super( inner );
51          if( inner instanceof PortletState )
52          {
53              wrappedState = (PortletState) inner;
54          }
55          else
56          {
57              //Report error or throw exception
58          }
59      }
60  
61      // PortletState Interface implementation
62      
63      /***
64       * Implements the default close behavior: any authenticated user may
65       * remove a portlet from his page
66       *
67       * @param rundata the RunData object for the current request
68       */
69      public final boolean allowClose( RunData rundata )
70      {
71          return checkPermission(rundata, 
72                                 JetspeedSecurity.PERMISSION_CLOSE );
73      }
74  
75      /***
76       * Returns true if this portlet is currently closed
77       */
78      public final boolean isClosed(RunData rundata)
79      {
80          return wrappedState.isClosed( rundata );
81      }
82  
83      /***
84       * Toggles the portlet state between closed and normal
85       *
86       * @param minimized the new portlet state
87       * @param data the RunData for this request
88       */
89      public final void setClosed(boolean close, RunData rundata)
90      {
91          if( allowClose( rundata ) )
92          {
93              wrappedState.setClosed( close, rundata );
94          }
95      }
96  
97      /***
98       * Implements the default info behavior: any authenticated user may
99       * get information on a portlet
100      *
101      * @param rundata the RunData object for the current request
102      */
103     public final boolean allowInfo( RunData rundata )
104     {
105         return checkPermission(rundata, 
106                                JetspeedSecurity.PERMISSION_INFO );
107     }
108 
109     /***
110      * Implements the default customize behavior: any authenticated user may
111      * customize a portlet
112      *
113      * @param rundata the RunData object for the current request
114      */
115     public final boolean allowCustomize( RunData rundata )
116     {
117         return checkPermission(rundata, 
118                                JetspeedSecurity.PERMISSION_CUSTOMIZE );
119     }
120 
121     /***
122      * Implements the default maximize behavior: any authenticated user may
123      * maximize a portlet
124      *
125      * @param rundata the RunData object for the current request
126      */
127     public boolean allowMaximize( RunData rundata )
128     {
129         return checkPermission(rundata, 
130                                JetspeedSecurity.PERMISSION_MAXIMIZE );
131     }
132 
133     /***
134      * Implements the default info behavior: any authenticated user may
135      * minimize a portlet
136      *
137      * @param rundata the RunData object for the current request
138      */
139     public boolean allowMinimize( RunData rundata )
140     {
141         return checkPermission(rundata, 
142                                JetspeedSecurity.PERMISSION_MINIMIZE );
143     }
144 
145     /***
146      * Returns true if this portlet is currently minimized
147      */
148     public boolean isMinimized(RunData rundata)
149     {
150         return wrappedState.isMinimized( rundata );
151     }
152 
153     /***
154     Change the portlet visibility state ( minimized <-> normal )
155 
156     @param minimize True if the portlet change to minimized
157     @param rundata A RunData object
158     */
159     public void setMinimized( boolean minimize, RunData rundata )
160     {
161         if( allowMinimize( rundata ) )
162         {
163             wrappedState.setMinimized(minimize, rundata );
164         }
165     }
166     
167     /***
168      * Implements the default info behavior: any authenticated user may
169      * view portlet in print friendly format
170      *
171      * @param rundata the RunData object for the current request
172      */
173     public boolean allowPrintFriendly( RunData rundata )
174     {
175         return checkPermission(rundata, 
176                                JetspeedSecurity.PERMISSION_PRINT_FRIENDLY );
177     }
178 
179 }