cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 37213 - in cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal: coplet profile/impl
Date Mon, 30 Aug 2004 18:15:59 GMT
Author: cziegeler
Date: Mon Aug 30 11:15:56 2004
New Revision: 37213

Modified:
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/copletdata.xml
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
Log:
Start adding role based protection

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java	(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java	Mon
Aug 30 11:15:56 2004
@@ -15,12 +15,16 @@
  */
 package org.apache.cocoon.portal.coplet;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
 import org.apache.cocoon.portal.factory.impl.AbstractProducible;
 import org.apache.cocoon.portal.util.DeltaApplicable;
+import org.apache.commons.lang.StringUtils;
 
 /**
  *
@@ -28,7 +32,7 @@
  * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
  * @author <a href="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
  * 
- * @version CVS $Id: CopletData.java,v 1.10 2004/03/05 13:02:10 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public class CopletData 
 extends AbstractProducible
@@ -40,6 +44,10 @@
 
     protected Map attributes = new HashMap();
 
+    protected String roles;
+    
+    protected transient List rolesList;
+    
 	/**
 	 * Signals whether a delta has been applied.
 	 */
@@ -153,4 +161,83 @@
 	public boolean deltaApplied() {
 		return this.deltaApplied;
 	}
+    
+    /**
+     * @return Returns the roles.
+     */
+    public String getRoles() {
+        return roles;
+    }
+    /**
+     * @param roles The roles to set.
+     */
+    public void setRoles(String roles) {
+        this.roles = roles;
+        this.rolesList = null;
+    }
+    
+    /**
+     * Return the list of roles that are allowed to access this coplet
+     * @return A list of roles or null if everyone is allowed.
+     */
+    public List getAllowedRoles() {
+        if ( StringUtils.isBlank(this.roles) ) {
+            return null;
+        }
+        if ( this.rolesList == null ) {
+            this.rolesList = new ArrayList();
+            final StringTokenizer tokenizer = new StringTokenizer(this.roles, ",");
+            while ( tokenizer.hasMoreElements() ) {
+                String token = (String)tokenizer.nextElement();
+                this.rolesList.add(token);
+            }
+            if ( this.rolesList.size() == 0 ) {
+                this.roles = null;
+                this.rolesList = null;
+            }
+        }
+        return this.rolesList;
+    }
+    
+    public void addAllowedRole(String role) {
+        List l = this.getAllowedRoles();
+        if ( l == null ) {
+            l = new ArrayList();
+            l.add(role);
+        } else {
+            if ( !l.contains(role) ) {
+                l.add(role);
+            }
+        }
+        this.buildRolesString(l);
+    }
+    
+    public void removeAllowedRole(String role) {
+        List l = this.getAllowedRoles();
+        if ( l != null && l.contains(role) ) {
+            l.remove(role);
+            if ( l.size() == 0 ) {
+                this.roles = null;
+                this.rolesList = null;
+            } else {
+                this.buildRolesString(l);
+            }
+        }
+    }
+    
+    protected void buildRolesString(List fromList) {
+        this.rolesList = fromList;
+        StringBuffer buffer = new StringBuffer();
+        boolean first = true;
+        Iterator i = fromList.iterator();
+        while ( i.hasNext() ) {
+            String role = (String)i.next();
+            if ( !first ) {
+                buffer.append(',');
+            }
+            first = false;
+            buffer.append(role);
+        }
+        this.roles = buffer.toString();
+    }
 }

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/copletdata.xml
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/copletdata.xml	(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/copletdata.xml	Mon
Aug 30 11:15:56 2004
@@ -49,6 +49,10 @@
 			<bind-xml name="title"/>
 		</field>
 
+		<field name="roles" type="java.lang.String">
+			<bind-xml name="roles"/>
+		</field>
+
 		<field name="attributes" type="org.exolab.castor.mapping.MapItem" collection="map" handler="org.apache.cocoon.portal.util.AttributesFieldHandler">
 			<bind-xml name="attribute"/>
 		</field>

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
Mon Aug 30 11:15:56 2004
@@ -15,8 +15,6 @@
  */
 package org.apache.cocoon.portal.profile.impl;
 
-import java.util.List;
-
 import org.apache.avalon.framework.CascadingRuntimeException;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -27,7 +25,6 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.portal.PortalService;
-import org.apache.cocoon.portal.coplet.CopletData;
 import org.apache.cocoon.portal.coplet.CopletInstanceData;
 import org.apache.cocoon.portal.layout.Layout;
 import org.apache.cocoon.portal.profile.ProfileManager;
@@ -37,7 +34,7 @@
  * 
  * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  * 
- * @version CVS $Id: AbstractProfileManager.java,v 1.7 2004/04/28 13:58:16 cziegeler Exp
$
+ * @version CVS $Id$
  */
 public abstract class AbstractProfileManager 
     extends AbstractLogEnabled 
@@ -55,67 +52,33 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(org.apache.cocoon.portal.coplet.CopletData)
-     */
-    public List getCopletInstanceData(CopletData data) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(java.lang.String)
-     */
-    public CopletInstanceData getCopletInstanceData(String copletID) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.portal.profile.ProfileManager#getPortalLayout(java.lang.String,
java.lang.String)
-     */
-    public Layout getPortalLayout(String layoutKey, String layoutID) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void register(CopletInstanceData coplet) {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.layout.Layout)
      */
     public void register(Layout layout) {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#saveUserProfiles()
      */
     public void saveUserProfiles() {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void unregister(CopletInstanceData coplet) {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.layout.Layout)
      */
     public void unregister(Layout layout) {
-        // TODO Auto-generated method stub
-
     }
 
     /**
@@ -207,6 +170,9 @@
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
     public void configure(Configuration configuration) throws ConfigurationException {
         Configuration child = configuration.getChild("default-layout-key");
         // get configured default LayoutKey

Mime
View raw message