shuber 2005/03/16 14:48:22 CET
Modified files: core/src/conf/metadata/jbproject/jahia Jahia Non Distributable Libs.library core/src/java/org/jahia/engines/shared Application_Field.java core/src/java/org/jahia/services/applications JetspeedDispatchingProvider.java PlutoServletRequestImpl.java Log: Implemented isUserInRole for portlets. Revision Changes Path No http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/.diff?r1=.-1&r2=No&f=h No http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/.diff?r1=.-1&r2=No&f=h No http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/.diff?r1=.-1&r2=No&f=h No http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/.diff?r1=.-1&r2=No&f=h 1.10 +15 -5 jahia/core/src/java/org/jahia/engines/shared/Application_Field.java http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/shared/Application_Field.java.diff?r1=1.9&r2=1.10&f=h 1.11 +13 -16 jahia/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java.diff?r1=1.10&r2=1.11&f=h 1.2 +86 -45 jahia/core/src/java/org/jahia/services/applications/PlutoServletRequestImpl.java http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/applications/PlutoServletRequestImpl.java.diff?r1=1.1&r2=1.2&f=h Index: Application_Field.java =================================================================== RCS file: /home/cvs/repository/jahia/core/src/java/org/jahia/engines/shared/Application_Field.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Application_Field.java 15 Mar 2005 16:50:44 -0000 1.9 +++ Application_Field.java 16 Mar 2005 13:48:22 -0000 1.10 @@ -207,6 +207,8 @@ if ( (epInstance.getApplicationID() == selectedAppID) && (existingDefName.equals( selectedEntryPointDefName))) { + + // we haven't changed the selected application newEntryPointInstanceID = entryPointInstanceID; } else { // we selected a new entry point, we must destroy the @@ -234,11 +236,19 @@ break; } } - EntryPointInstance newEPInstance = ServicesRegistry.getInstance(). - getApplicationsManagerService().createEntryPointInstance( - newEntryPointDefinition); - if (newEPInstance != null) { - newEntryPointInstanceID = newEPInstance.getID(); + + // we need to check here if we need to create a new instance + // or if we will just be using an existing one (for example + // if the user hasn't changed his choice in the case of an + // update). + if (newEntryPointInstanceID == -1) { + EntryPointInstance newEPInstance = ServicesRegistry.getInstance(). + getApplicationsManagerService(). + createEntryPointInstance( + newEntryPointDefinition); + if (newEPInstance != null) { + newEntryPointInstanceID = newEPInstance.getID(); + } } if (newEntryPointInstanceID != -1) { Index: JetspeedDispatchingProvider.java =================================================================== RCS file: /home/cvs/repository/jahia/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JetspeedDispatchingProvider.java 10 Mar 2005 14:16:36 -0000 1.10 +++ JetspeedDispatchingProvider.java 16 Mar 2005 13:48:22 -0000 1.11 @@ -40,27 +40,21 @@ package org.jahia.services.applications; +import java.security.Principal; +import java.util.HashMap; +import java.util.Map; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; + import org.jahia.data.applications.ApplicationBean; +import org.jahia.data.applications.EntryPointInstance; import org.jahia.exceptions.JahiaException; import org.jahia.exceptions.JahiaInitializationException; import org.jahia.params.ParamBean; -import org.jahia.settings.SettingsBean; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.jahia.data.applications.EntryPointInstance; import org.jahia.registries.ServicesRegistry; -import org.jahia.data.applications.ServletBean; -import org.jahia.services.usermanager.JahiaUserManagerService; -import java.security.Principal; -import java.util.HashMap; -import java.util.Map; import org.jahia.services.usermanager.JahiaGroup; -import org.jahia.data.applications.EntryPointDefinition; -import java.util.Iterator; -import javax.portlet.PortletMode; +import org.jahia.services.usermanager.JahiaUserManagerService; +import org.jahia.settings.SettingsBean; public class JetspeedDispatchingProvider implements DispatchingProvider, UserRoleResolver { @@ -310,7 +304,10 @@ request.removeAttribute(JahiaJ2SessionPortalURL. APPUNIQUEID_REQUEST_ATTRIBUTEKEY); - result.append(response.getStringBuffer()); + String portletOutput = response.getStringBuffer(); + if (portletOutput != null) { + result.append(portletOutput); + } } catch (Throwable t) { t.printStackTrace(); } Index: PlutoServletRequestImpl.java =================================================================== RCS file: /home/cvs/repository/jahia/core/src/java/org/jahia/services/applications/PlutoServletRequestImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PlutoServletRequestImpl.java 23 Dec 2004 16:19:41 -0000 1.1 +++ PlutoServletRequestImpl.java 16 Mar 2005 13:48:22 -0000 1.2 @@ -30,75 +30,121 @@ import org.apache.pluto.om.portlet.PortletDefinition; import org.apache.pluto.om.window.PortletWindow; import org.jahia.bin.Jahia; +import org.jahia.services.usermanager.JahiaGroup; +import org.jahia.services.usermanager.JahiaUser; +import org.jahia.registries.ServicesRegistry; +import org.jahia.data.applications.ApplicationBean; +import org.jahia.exceptions.*; +import java.util.StringTokenizer; +import org.jahia.data.applications.EntryPointInstance; /** - * @version $Id: PlutoServletRequestImpl.java,v 1.1 2004/12/23 16:19:41 shuber Exp $ + * @version $Id: PlutoServletRequestImpl.java,v 1.2 2005/03/16 13:48:22 shuber Exp $ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jeremy Ford</a> */ -public class PlutoServletRequestImpl extends ServletRequestImpl -{ +public class PlutoServletRequestImpl extends ServletRequestImpl { /** Logger */ private static final Log log = LogFactory.getLog(PlutoServletRequestImpl.class); private PortletWindow portletWindow; - public PlutoServletRequestImpl(javax.servlet.http.HttpServletRequest servletRequest, PortletWindow window) - { + public PlutoServletRequestImpl (javax.servlet.http.HttpServletRequest + servletRequest, PortletWindow window) { super(servletRequest, window); this.portletWindow = window; } - private String getUserName() - { + private String getUserName () { return Jahia.getThreadParamBean().getUser().getUsername(); } /** * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) */ - public boolean isUserInRole(String roleName) - { + public boolean isUserInRole (String roleName) { boolean result = false; - if (roleName != null && roleName.length() > 0) - { - String mappedName = mapRoleRefToRole(roleName); - log.warn("NOT YET IMPLEMENTED"); - /** @todo NOT YET IMPLEMENTED */ - result = false; - - if(!result) - { - result = super.isUserInRole(roleName); + if (roleName != null && roleName.length() > 0) { + String mappedName = mapRoleRefToRole(roleName); + + JahiaUser user = Jahia.getThreadParamBean().getUser(); + if (user != null) { + + String appUniqueID = (String) Jahia.getThreadParamBean(). + getRealRequest().getAttribute( + JahiaJ2SessionPortalURL.APPUNIQUEID_REQUEST_ATTRIBUTEKEY); + StringTokenizer tokens = new StringTokenizer(appUniqueID, "_"); + int windowID = Integer.parseInt(tokens.nextToken()); + int entryPointInstanceID = Integer.parseInt(tokens.nextToken()); + + ApplicationBean appBean = null; + try { + EntryPointInstance entryPointInstance = ServicesRegistry.getInstance().getApplicationsManagerService().getEntryPointInstance(entryPointInstanceID); + appBean = ServicesRegistry.getInstance(). + getApplicationsManagerService(). + getApplication(entryPointInstance.getApplicationID()); + } catch (JahiaException je) { + log.error("Error retrieving application bean with ID=" + + appUniqueID, je); + } + + // Hollis all apps groups roles are a group with siteID=0 + JahiaGroup roleGroup = ServicesRegistry.getInstance(). + getJahiaGroupManagerService(). + lookupGroup(0, + appBean.getID() + "_" + windowID + "_" + + mappedName); + if (roleGroup != null) { + if (roleGroup.isMember(user) == true) { + log.debug("User [" + user.getUsername() + + "] is a member of role [" + roleGroup.getName() + + "]"); + return true; // user is indeed member of role (aka group) + } else { + log.debug("User [" + user.getUsername() + + "] is NOT a member of role [" + + roleGroup.getName() + "]"); + return false; // user is not member of role (=group) + } + } else { + log.debug("Role [" + + appBean.getID() + + "_" + windowID + "_" + mappedName + + "] not found in Jahia's groups!"); + return false; // the role (aka group) does not exist + } + } else { + log.debug("No user logged, ignoring call !"); + return false; } + } return result; } - private String mapRoleRefToRole(String roleName) - { - PortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition(); - SecurityRoleRefSet roleRefSet = portletDefinition.getInitSecurityRoleRefSet(); - SecurityRoleSet roleSet = portletDefinition.getPortletApplicationDefinition().getWebApplicationDefinition() - .getSecurityRoles(); + private String mapRoleRefToRole (String roleName) { + PortletDefinition portletDefinition = portletWindow.getPortletEntity(). + getPortletDefinition(); + SecurityRoleRefSet roleRefSet = portletDefinition. + getInitSecurityRoleRefSet(); + SecurityRoleSet roleSet = portletDefinition. + getPortletApplicationDefinition(). + getWebApplicationDefinition() + .getSecurityRoles(); Iterator roleRefIter = roleRefSet.iterator(); - while (roleRefIter.hasNext()) - { + while (roleRefIter.hasNext()) { SecurityRoleRef roleRef = (SecurityRoleRef) roleRefIter.next(); - if (roleName.equals(roleRef.getRoleName())) - { + if (roleName.equals(roleRef.getRoleName())) { String roleLinkName = roleRef.getRoleLink(); - if (roleLinkName == null || roleLinkName.length() == 0) - { + if (roleLinkName == null || roleLinkName.length() == 0) { roleLinkName = roleName; } Iterator roleIter = roleSet.iterator(); - while (roleIter.hasNext()) - { + while (roleIter.hasNext()) { SecurityRole role = (SecurityRole) roleIter.next(); if (roleLinkName.equals(role.getRoleName())) return role.getRoleName(); @@ -108,22 +154,18 @@ return roleName; } - public void setAttribute( String name, Object value ) - { + public void setAttribute (String name, Object value) { this._getHttpServletRequest().setAttribute(name, value); } - public Principal getUserPrincipal() - { - JetspeedRequestContext context = (JetspeedRequestContext) getAttribute("org.apache.jetspeed.request.RequestContext"); - if (context != null) - { + public Principal getUserPrincipal () { + JetspeedRequestContext context = (JetspeedRequestContext) getAttribute( + "org.apache.jetspeed.request.RequestContext"); + if (context != null) { Set principals = context.getSubject().getPrincipals(); - if (principals != null) - { + if (principals != null) { Iterator it = principals.iterator(); - if (it.hasNext()) - { + if (it.hasNext()) { return (Principal) it.next(); } } @@ -132,5 +174,4 @@ } - }