1 16 17 package org.apache.jetspeed.portal.security.portlets; 18 19 import org.apache.jetspeed.om.security.JetspeedUser; 21 import org.apache.jetspeed.portal.Portlet; 22 import org.apache.jetspeed.portal.PortletState; 23 import org.apache.jetspeed.portal.PortletConfig; 24 import org.apache.jetspeed.portal.PortletException; 25 import org.apache.jetspeed.portal.PortletInstance; 26 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 27 import org.apache.jetspeed.services.logging.JetspeedLogger; 28 import org.apache.jetspeed.services.portletcache.Cacheable; 29 import org.apache.jetspeed.services.security.PortalResource; 30 import org.apache.jetspeed.services.JetspeedSecurity; 31 import org.apache.jetspeed.util.template.JetspeedLink; 32 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 33 import org.apache.jetspeed.util.MimeType; 34 import org.apache.jetspeed.services.PortletStats; 35 36 import org.apache.turbine.util.RunData; 38 import org.apache.turbine.services.localization.Localization; 39 40 import org.apache.ecs.ConcreteElement; 42 import org.apache.jetspeed.util.JetspeedClearElement; 43 44 45 46 54 public class PortletWrapper implements Portlet 55 { 56 59 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PortletWrapper.class.getName()); 60 61 64 private Portlet wrappedPortlet = null; 65 private PortalResource portalResource = null; 66 private ConcreteElement content = null; 67 68 public PortletWrapper(Portlet inner) 69 { 70 wrappedPortlet = inner; 71 portalResource = new PortalResource(wrappedPortlet); 72 } 73 74 76 public final String getName() 77 { 78 return wrappedPortlet.getName(); 80 } 81 82 84 public final void setName(String name) 85 { 86 wrappedPortlet.setName(name); 88 } 89 90 92 public final PortletConfig getPortletConfig() 93 { 94 return wrappedPortlet.getPortletConfig(); 95 } 96 97 99 public final void setPortletConfig(PortletConfig pc) 100 { 101 wrappedPortlet.setPortletConfig(pc); 103 } 104 105 107 public ConcreteElement getContent(RunData rundata) 108 { 109 110 if (checkPermission(rundata, JetspeedSecurity.PERMISSION_VIEW)) 111 { 112 if (PortletStats.isEnabled()) 113 { 114 long start = System.currentTimeMillis(); 115 content = wrappedPortlet.getContent(rundata); 116 long time = System.currentTimeMillis() - start; PortletStats.logAccess(rundata, this, PortletStats.ACCESS_OK, time); 118 } else { 119 content = wrappedPortlet.getContent(rundata); 120 } 121 122 return content; 123 } 124 else 125 { 126 if (PortletStats.isEnabled()) 127 { 128 PortletStats.logAccess(rundata, this, PortletStats.ACCESS_DENIED); 129 } 130 return new JetspeedClearElement(Localization.getString(rundata, "SECURITY_NO_ACCESS_TO_PORTLET")); 131 } 132 } 133 134 139 public String getDescription() 140 { 141 return wrappedPortlet.getDescription(); 142 } 143 144 public String getDescription(String instanceDescription) 145 { 146 return wrappedPortlet.getDescription(instanceDescription); 147 } 148 149 151 public void setDescription(String description) 152 { 153 wrappedPortlet.setDescription(description); 154 } 155 156 159 public String getImage(String instanceImage) 160 { 161 return wrappedPortlet.getImage(instanceImage); 162 } 163 164 167 public void setImage(String image) 168 { 169 wrappedPortlet.setImage(image); 170 } 171 174 public String getTitle() 175 { 176 179 return wrappedPortlet.getTitle(); 180 181 182 } 183 184 187 public String getTitle(String instanceTitle) 188 { 189 return wrappedPortlet.getTitle(instanceTitle); 190 } 191 192 195 public void setTitle(String title) 196 { 197 200 wrappedPortlet.setTitle(title); 201 202 } 203 204 205 207 public boolean getAllowEdit(RunData rundata) 208 { 209 return checkPermission(rundata, JetspeedSecurity.PERMISSION_CUSTOMIZE); 210 } 211 212 214 public boolean getAllowView(RunData rundata) 215 { 216 217 if (checkPermission(rundata, JetspeedSecurity.PERMISSION_VIEW)) 218 { 219 return wrappedPortlet.getAllowView(rundata); 220 } 221 return false; 222 } 223 224 226 public boolean getAllowMaximize(RunData rundata) 227 { 228 return checkPermission(rundata, JetspeedSecurity.PERMISSION_MAXIMIZE); 229 } 230 231 234 public void init() throws PortletException 235 { 236 239 wrappedPortlet.init(); 240 241 } 242 243 246 public long getCreationTime() 247 { 248 251 return wrappedPortlet.getCreationTime(); 252 253 } 254 255 258 public void setCreationTime(long creationTime) 259 { 260 263 wrappedPortlet.setCreationTime(creationTime); 264 } 265 266 269 public boolean supportsType(MimeType mimeType) 270 { 271 274 return wrappedPortlet.supportsType(mimeType); 275 276 } 277 278 284 protected boolean checkPermission(RunData rundata, String permissionName) 285 { 286 try 287 { 288 JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata); 289 portalResource.setOwner(jsLink.getUserName()); 290 JetspeedLinkFactory.putInstance(jsLink); 291 } 292 catch (Exception e) 293 { 294 logger.warn(e.getMessage(), e); 295 portalResource.setOwner(null); 296 } 297 298 if (logger.isDebugEnabled()) 299 { 300 logger.debug("checking for Portlet permission: " 301 + permissionName 302 + " for portlet: " 303 + wrappedPortlet.getName() 304 + " Owner = " 305 + portalResource.getOwner()); 306 } 307 308 return JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 309 portalResource, 310 permissionName); 311 } 312 313 315 322 public boolean isShowTitleBar(RunData rundata) 323 { 324 if (wrappedPortlet.getPortletConfig() != null) 325 { 326 return Boolean.valueOf(wrappedPortlet.getPortletConfig().getInitParameter("_showtitlebar", "true")).booleanValue(); 328 } 329 return getAttribute("_showtitlebar", "true", rundata).equals("true"); 330 } 331 332 333 341 public String getAttribute(String attrName, String attrDefValue, RunData rundata) 342 { 343 if (checkPermission(rundata, JetspeedSecurity.PERMISSION_VIEW)) 344 { 345 return wrappedPortlet.getAttribute(attrName, attrDefValue, rundata); 346 } 347 else 348 { 349 return wrappedPortlet.getAttribute(attrName, attrDefValue, rundata); 352 } 353 354 } 355 356 363 public void setAttribute(String attrName, String attrValue, RunData rundata) 364 { 365 if (checkPermission(rundata, JetspeedSecurity.PERMISSION_VIEW)) 366 { 367 wrappedPortlet.setAttribute(attrName, attrValue, rundata); 368 } 369 else 370 { 371 wrappedPortlet.setAttribute(attrName, attrValue, rundata); 374 } 375 376 } 377 378 384 public PortletInstance getInstance(RunData rundata) 385 { 386 return wrappedPortlet.getInstance(rundata); 387 } 388 389 396 public static Portlet wrap(Portlet aPortlet) 397 { 398 if (aPortlet instanceof PortletState) 400 { 401 if (aPortlet instanceof Cacheable) 402 { 403 return new CacheableStatefulPortletWrapper(aPortlet); 404 } 405 return new StatefulPortletWrapper(aPortlet); 406 } 407 if (aPortlet instanceof Cacheable) 408 { 409 return new CacheablePortletWrapper(aPortlet); 410 } 411 return new PortletWrapper(aPortlet); 412 413 } 414 415 416 public String getID() 417 { 418 return wrappedPortlet.getID(); 419 } 420 421 public void setID(String id) 422 { 423 wrappedPortlet.setID(id); 424 } 425 426 429 public boolean providesCustomization() 430 { 431 return wrappedPortlet.providesCustomization(); 432 } 433 434 public Portlet getPortlet() 435 { 436 return wrappedPortlet; 437 } 438 } 439 | Popular Tags |