KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
12 import java.util.Set JavaDoc;
13
14 import javax.portlet.PortletPreferences;
15 import javax.servlet.http.HttpServletRequest JavaDoc;
16
17 import org.jboss.portal.core.impl.user.UserContextImpl;
18 import org.jboss.portal.core.model.User;
19 import org.jboss.portal.core.plugins.preferences.ProxyPreferenceSetPlugin;
20 import org.jboss.portal.core.plugins.security.ModelPlugin;
21 import org.jboss.portal.core.security.AuthorizationRealm;
22 import org.jboss.portal.core.security.NullAuthorizationRealm;
23 import org.jboss.portal.core.security.ModelAuthorizationRealm;
24 import org.jboss.portal.core.util.Parameters;
25 import org.jboss.portal.core.CoreConstants;
26 import org.jboss.portal.portlet.impl.ActionRequestImpl;
27 import org.jboss.portal.server.Component;
28 import org.jboss.portal.server.PortalRequest;
29 import org.jboss.portal.server.PortalResponse;
30 import org.jboss.portal.server.Window;
31 import org.jboss.portal.server.WindowContext;
32 import org.jboss.portal.server.PortalServer;
33 import org.jboss.portal.server.user.UserContext;
34
35 /**
36  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
37  * @version $Revision: 1.15 $
38  */

39 public class JBossActionRequest extends ActionRequestImpl
40 {
41
42    /** The authorization realm. */
43    private AuthorizationRealm realm;
44
45    /** The parameters. */
46    private Parameters parameters;
47
48    public JBossActionRequest(UserContext userContext,
49                              PortletPreferences preferences,
50                              Window window,
51                              WindowContext windowCtx,
52                              PortalRequest req,
53                              PortalResponse resp,
54                              HttpServletRequest JavaDoc dreq)
55    {
56       super(userContext, preferences, window, windowCtx, req, resp, dreq);
57       this.realm = null;
58       this.parameters = null;
59    }
60
61    /**
62     * Returns a modifiable map of user informations or null if the user is not authenticated.
63     */

64    public Map JavaDoc getInformations()
65    {
66       return userContext.getInformations();
67    }
68
69    /**
70     * Returns the current authenticated user or null if the user is not authenticated
71     */

72    public User getUser()
73    {
74       return ((UserContextImpl)userContext).getUser();
75    }
76
77    public Parameters getParameters()
78    {
79       if (parameters == null)
80       {
81          parameters = new Parameters(getParameterMap());
82       }
83       return parameters;
84    }
85
86    public Boolean JavaDoc getIdempotent()
87    {
88       return req.getIdempotent();
89    }
90
91    public void setIdempotent(Boolean JavaDoc idempotent)
92    {
93      req.setIdempotent(idempotent);
94    }
95
96    private Set JavaDoc getRoleNames()
97    {
98       User user = getUser();
99       if (user == null)
100       {
101          return AuthorizationRealm.ANONYMOUS_ROLE_SET;
102       }
103       else
104       {
105          return user.getRoleNames();
106       }
107    }
108
109    /**
110     * Return true if the given role has the global permission on the specified domain.
111     */

112    public boolean hasPermission(String JavaDoc domain, String JavaDoc permission)
113    {
114       return getAuthorizationRealm().hasPermission(domain, getRoleNames(), permission);
115    }
116    
117    /**
118     * Return true if the given role has the global permission.
119     */

120    public boolean hasPermission(String JavaDoc permission)
121    {
122       return getAuthorizationRealm().hasPermission(getRoleNames(), permission);
123    }
124    
125    /**
126     * Return true if the given role has the local permission on the specified domain.
127     */

128    public boolean hasPermission(String JavaDoc domain, String JavaDoc[] path, String JavaDoc permission)
129    {
130       return getAuthorizationRealm().hasPermission(domain, getRoleNames(), path, permission);
131    }
132
133    /**
134     * Return true if the given role has the local permission.
135     */

136    public boolean hasPermission(String JavaDoc[] path, String JavaDoc permission)
137    {
138       return getAuthorizationRealm().hasPermission(getRoleNames(), path, permission);
139    }
140
141    protected PortletPreferences createPreferences()
142    {
143       Component container = instance.getComponent();
144       ProxyPreferenceSetPlugin plugin = (ProxyPreferenceSetPlugin)container.getPlugin("PROXY");
145       if (plugin != null)
146       {
147 // PreferencesValidator validator = container.getPreferencesValidator();
148
// ProxyInfo proxyCtor = container.getPreferenceProxyConstructor();
149
// return new JBossPortletPreferences(
150
// propertySets,
151
// validator,
152
// PortletPreferencesImpl.RENDER,
153
// proxyCtor);
154
}
155       return null;
156    }
157
158    /**
159     * Returns the authorization manager for this request.
160     */

161    public AuthorizationRealm getAuthorizationRealm()
162    {
163       if (realm == null)
164       {
165          ModelPlugin plugin = (ModelPlugin)component.getPlugin(CoreConstants.REALM_KEY);
166          if (plugin != null)
167          {
168             realm = new ModelAuthorizationRealm(plugin, plugin.getSchemeStore());
169          }
170       }
171       if (realm == null)
172       {
173          realm = NullAuthorizationRealm.instance;
174       }
175       return realm;
176    }
177
178    /**
179     * Exposed temporarily.
180     * @deprecated
181     */

182    public PortalServer getServer()
183    {
184       return window.getServer();
185    }
186
187    /**
188     * Perform a programmatic sign out.
189     */

190    public void signOut()
191    {
192       req.getSession().invalidate();
193    }
194 }
195
Popular Tags