KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > JBossRenderRequest


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portlet;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import javax.portlet.PortletPreferences;
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19
20 import org.jboss.portal.core.CorePortal;
21 import org.jboss.portal.core.CoreConstants;
22 import org.jboss.portal.core.impl.user.UserContextImpl;
23 import org.jboss.portal.core.model.User;
24 import org.jboss.portal.core.plugins.page.Page;
25 import org.jboss.portal.core.plugins.page.PageRepository;
26 import org.jboss.portal.core.plugins.preferences.ProxyPreferenceSetPlugin;
27 import org.jboss.portal.core.plugins.security.ModelPlugin;
28 import org.jboss.portal.core.security.AuthorizationRealm;
29 import org.jboss.portal.core.security.NullAuthorizationRealm;
30 import org.jboss.portal.core.security.ModelAuthorizationRealm;
31 import org.jboss.portal.core.util.Parameters;
32 import org.jboss.portal.portlet.impl.RenderRequestImpl;
33 import org.jboss.portal.server.PortalRequest;
34 import org.jboss.portal.server.PortalResponse;
35 import org.jboss.portal.server.ServerURL;
36 import org.jboss.portal.server.Window;
37 import org.jboss.portal.server.WindowContext;
38 import org.jboss.portal.server.Component;
39 import org.jboss.portal.server.PortalServer;
40 import org.jboss.portal.server.user.UserContext;
41
42 /**
43  * @author <a HREF="mailto:julien@jboss.org">Julien Viet </a>
44  * @version $Revision: 1.16 $
45  */

46 public class JBossRenderRequest
47       extends RenderRequestImpl
48 {
49
50    /** The authorization realm. */
51    private AuthorizationRealm realm;
52
53    /** The parameters. */
54    private Parameters parameters;
55
56    public JBossRenderRequest(
57          UserContext userContext,
58          PortletPreferences preferences,
59          Window window,
60          WindowContext windowContext,
61          PortalRequest req,
62          PortalResponse resp,
63          HttpServletRequest JavaDoc dreq)
64    {
65       super(userContext, preferences, window, windowContext, req, resp, dreq);
66    }
67
68 // protected PortletPreferences createPreferences()
69
// {
70
// CorePortletContainer container = (CorePortletContainer) portletInstance.getPortletContainer();
71
// PreferencesValidator validator = container.getPreferencesValidator();
72
// ProxyInfo proxyCtor = container.getPreferenceProxyConstructor();
73
// return new JBossPortletPreferences(propertySets, validator, PortletPreferencesImpl.RENDER, proxyCtor);
74
// }
75

76    /**
77     * Returns an internal iterator over the internal link available from this
78     * portlet. This API is subject to change.
79     */

80    public Iterator JavaDoc getPortalObjects()
81    {
82       // Get the portal
83
CorePortal portal = (CorePortal)window.getPortal();
84       PageRepository repository = portal.getPageRepository();
85
86       //
87
ArrayList JavaDoc tmp = new ArrayList JavaDoc();
88       Collection JavaDoc pages = repository.getPages();
89       for (Iterator JavaDoc i = pages.iterator();i.hasNext();)
90       {
91          Page page = (Page)i.next();
92          String JavaDoc name = page.getName();
93          ServerURL serverURL = page.createURL();
94          PortalObject objectURL = new PortalObject(0, name, serverURL, resp);
95          tmp.add(objectURL);
96       }
97       
98       //
99
return tmp.iterator();
100    }
101
102    /**
103     * Exposed temporarily.
104     * @deprecated
105     */

106    public PortalServer getServer()
107    {
108       return window.getServer();
109    }
110
111    /**
112     * Returns a modifiable map of user informations or null if the user is not authenticated.
113     */

114    public Map JavaDoc getInformations()
115    {
116       return userContext.getInformations();
117    }
118
119    /**
120     * Returns the current authenticated user or null if the user is not authenticated
121     */

122    public User getUser()
123    {
124       return ((UserContextImpl)userContext).getUser();
125    }
126
127    public Parameters getParameters()
128    {
129       if (parameters == null)
130       {
131          parameters = new Parameters(getParameterMap());
132       }
133       return parameters;
134    }
135
136    public String JavaDoc getURL()
137    {
138       return getURL(null, null);
139    }
140
141    public String JavaDoc getURL(Boolean JavaDoc wantAuthenticated, Boolean JavaDoc wantSecure)
142    {
143       ServerURL url = req.getURL();
144       if (url != null)
145       {
146          boolean idempotent = false;
147          if (req.getIdempotent() != null)
148          {
149             idempotent = req.getIdempotent().booleanValue();
150          }
151          else
152          {
153             idempotent = url.isIdempotent();
154          }
155          if (idempotent)
156          {
157             return resp.createURL(url, wantAuthenticated, wantSecure, true);
158          }
159       }
160       return null;
161    }
162
163    private Set JavaDoc getRoleNames()
164    {
165       User user = getUser();
166       if (user == null)
167       {
168          return AuthorizationRealm.ANONYMOUS_ROLE_SET;
169       }
170       else
171       {
172          return user.getRoleNames();
173       }
174    }
175
176    /**
177     * Return true if the given role has the global permission on the given domain.
178     */

179    public boolean hasPermission(String JavaDoc domain, String JavaDoc permission)
180    {
181       return getAuthorizationRealm().hasPermission(domain, getRoleNames(), permission);
182    }
183
184    /**
185     * Return true if the given role has the global permission on the given domain.
186     */

187    public boolean hasPermission(String JavaDoc permission)
188    {
189       return getAuthorizationRealm().hasPermission(getRoleNames(), permission);
190    }
191
192    /**
193     * Return true if the given role has the local permission.
194     */

195    public boolean hasPermission(String JavaDoc domain, String JavaDoc[] path, String JavaDoc permission)
196    {
197       return getAuthorizationRealm().hasPermission(domain, getRoleNames(), path, permission);
198    }
199
200    /**
201     * Return true if the given role has the global permission on the given domain.
202     */

203    public boolean hasPermission(String JavaDoc[] path, String JavaDoc permission)
204    {
205       return getAuthorizationRealm().hasPermission(getRoleNames(), path, permission);
206    }
207
208    protected PortletPreferences createPreferences()
209    {
210       Component container = instance.getComponent();
211       ProxyPreferenceSetPlugin plugin = (ProxyPreferenceSetPlugin)container.getPlugin("PROXY");
212       if (plugin != null)
213       {
214 // PreferencesValidator validator = container.getPreferencesValidator();
215
// ProxyInfo proxyCtor = container.getPreferenceProxyConstructor();
216
// return new JBossPortletPreferences(
217
// propertySets,
218
// validator,
219
// PortletPreferencesImpl.RENDER,
220
// proxyCtor);
221
}
222       return null;
223    }
224
225    /**
226     * Returns the authorization manager for this request.
227     */

228    public AuthorizationRealm getAuthorizationRealm()
229    {
230       if (realm == null)
231       {
232          ModelPlugin plugin = (ModelPlugin)component.getPlugin(CoreConstants.REALM_KEY);
233          if (plugin != null)
234          {
235             realm = new ModelAuthorizationRealm(plugin, plugin.getSchemeStore());
236          }
237       }
238       if (realm == null)
239       {
240          realm = NullAuthorizationRealm.instance;
241       }
242       return realm;
243    }
244 }
Popular Tags