1 9 package org.jboss.portlet; 10 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 import javax.portlet.PortletPreferences; 18 import javax.servlet.http.HttpServletRequest ; 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 46 public class JBossRenderRequest 47 extends RenderRequestImpl 48 { 49 50 51 private AuthorizationRealm realm; 52 53 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 dreq) 64 { 65 super(userContext, preferences, window, windowContext, req, resp, dreq); 66 } 67 68 76 80 public Iterator getPortalObjects() 81 { 82 CorePortal portal = (CorePortal)window.getPortal(); 84 PageRepository repository = portal.getPageRepository(); 85 86 ArrayList tmp = new ArrayList (); 88 Collection pages = repository.getPages(); 89 for (Iterator i = pages.iterator();i.hasNext();) 90 { 91 Page page = (Page)i.next(); 92 String name = page.getName(); 93 ServerURL serverURL = page.createURL(); 94 PortalObject objectURL = new PortalObject(0, name, serverURL, resp); 95 tmp.add(objectURL); 96 } 97 98 return tmp.iterator(); 100 } 101 102 106 public PortalServer getServer() 107 { 108 return window.getServer(); 109 } 110 111 114 public Map getInformations() 115 { 116 return userContext.getInformations(); 117 } 118 119 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 getURL() 137 { 138 return getURL(null, null); 139 } 140 141 public String getURL(Boolean wantAuthenticated, Boolean 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 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 179 public boolean hasPermission(String domain, String permission) 180 { 181 return getAuthorizationRealm().hasPermission(domain, getRoleNames(), permission); 182 } 183 184 187 public boolean hasPermission(String permission) 188 { 189 return getAuthorizationRealm().hasPermission(getRoleNames(), permission); 190 } 191 192 195 public boolean hasPermission(String domain, String [] path, String permission) 196 { 197 return getAuthorizationRealm().hasPermission(domain, getRoleNames(), path, permission); 198 } 199 200 203 public boolean hasPermission(String [] path, String 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 } 222 return null; 223 } 224 225 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 |