You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/08/31 11:23:10 UTC

svn commit: rev 37246 - in cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal: coplet profile/impl

Author: cziegeler
Date: Tue Aug 31 02:23:07 2004
New Revision: 37246

Added:
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java   (contents, props changed)
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserProfile.java   (contents, props changed)
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:
Correcting role handling
Starting new profile manager

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	Tue Aug 31 02:23:07 2004
@@ -46,12 +46,8 @@
 
     protected String allowedRoles;
     
-    protected String deniedRoles;
-    
     protected transient List allowedRolesList;
     
-    protected transient List deniedRolesList;
-    
 	/**
 	 * Signals whether a delta has been applied.
 	 */
@@ -182,20 +178,6 @@
     }
     
     /**
-     * @return Returns the denied roles.
-     */
-    public String getDeniedRoles() {
-        return this.deniedRoles;
-    }
-    /**
-     * @param roles The allowed roles to set.
-     */
-    public void setDeniedRoles(String roles) {
-        this.deniedRoles = roles;
-        this.deniedRolesList = null;
-    }
-
-    /**
      * Return the list of roles that are allowed to access this coplet
      * @return A list of roles or null if everyone is allowed.
      */
@@ -218,29 +200,6 @@
         return this.allowedRolesList;
     }
     
-    /**
-     * Return the list of roles that are denied to access this coplet
-     * @return A list of roles or null if everyone is allowed.
-     */
-    public List getDeniedRolesList() {
-        if ( StringUtils.isBlank(this.deniedRoles) ) {
-            return null;
-        }
-        if ( this.deniedRolesList == null ) {
-            this.deniedRolesList = new ArrayList();
-            final StringTokenizer tokenizer = new StringTokenizer(this.deniedRoles, ",");
-            while ( tokenizer.hasMoreElements() ) {
-                String token = (String)tokenizer.nextElement();
-                this.deniedRolesList.add(token);
-            }
-            if ( this.deniedRolesList.size() == 0 ) {
-                this.deniedRoles = null;
-                this.deniedRolesList = null;
-            }
-        }
-        return this.deniedRolesList;
-    }
-
     public void addToAllowedRoles(String role) {
         List l = this.getAllowedRolesList();
         if ( l == null ) {
@@ -251,7 +210,7 @@
                 l.add(role);
             }
         }
-        this.buildRolesString(l, true);
+        this.buildRolesString(l);
     }
     
     public void removeFromAllowedRoles(String role) {
@@ -262,43 +221,13 @@
                 this.allowedRoles = null;
                 this.allowedRolesList = null;
             } else {
-                this.buildRolesString(l, true);
+                this.buildRolesString(l);
             }
         }
     }
     
-    public void addToDeniedRoles(String role) {
-        List l = this.getDeniedRolesList();
-        if ( l == null ) {
-            l = new ArrayList();
-            l.add(role);
-        } else {
-            if ( !l.contains(role) ) {
-                l.add(role);
-            }
-        }
-        this.buildRolesString(l, false);
-    }
-    
-    public void removeFromDeniedRoles(String role) {
-        List l = this.getDeniedRolesList();
-        if ( l != null && l.contains(role) ) {
-            l.remove(role);
-            if ( l.size() == 0 ) {
-                this.deniedRoles = null;
-                this.deniedRolesList = null;
-            } else {
-                this.buildRolesString(l, false);
-            }
-        }
-    }
-
-    protected void buildRolesString(List fromList, boolean allow) {
-        if ( allow ) {
-            this.allowedRolesList = fromList;
-        } else {
-            this.deniedRolesList = fromList;
-        }
+    protected void buildRolesString(List fromList) {
+        this.allowedRolesList = fromList;
         StringBuffer buffer = new StringBuffer();
         boolean first = true;
         Iterator i = fromList.iterator();
@@ -310,10 +239,6 @@
             first = false;
             buffer.append(role);
         }
-        if ( allow ) {
-            this.allowedRoles = buffer.toString();
-        } else {
-            this.deniedRoles = buffer.toString();
-        }
+        this.allowedRoles = 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	Tue Aug 31 02:23:07 2004
@@ -50,11 +50,7 @@
 		</field>
 
 		<field name="allowedRoles" type="java.lang.String">
-			<bind-xml name="allowed-roles"/>
-		</field>
-
-		<field name="deniedRoles" type="java.lang.String">
-			<bind-xml name="denied-roles"/>
+			<bind-xml name="roles"/>
 		</field>
 
 		<field name="attributes" type="org.exolab.castor.mapping.MapItem" collection="map" handler="org.apache.cocoon.portal.util.AttributesFieldHandler">

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	Tue Aug 31 02:23:07 2004
@@ -55,34 +55,39 @@
      * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void register(CopletInstanceData coplet) {
+        // overwrite in subclass
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.layout.Layout)
      */
     public void register(Layout layout) {
+        // overwrite in subclass
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#saveUserProfiles()
      */
     public void saveUserProfiles() {
+        // overwrite in subclass
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void unregister(CopletInstanceData coplet) {
+        // overwrite in subclass
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.layout.Layout)
      */
     public void unregister(Layout layout) {
+        // overwrite in subclass
     }
 
-    /**
-     * Change the default layout key for most functions
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#setDefaultLayoutKey(java.lang.String)
      */
     public void setDefaultLayoutKey(String layoutKey) {
         PortalService service = null;
@@ -101,8 +106,8 @@
         }
     }
     
-    /**
-     * Get the default layout key
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getDefaultLayoutKey()
      */
     public String getDefaultLayoutKey() {
         PortalService service = null;
@@ -126,12 +131,14 @@
      * @see org.apache.cocoon.portal.profile.ProfileManager#login()
      */
     public void login() {
+        // overwrite in subclass
     }
     
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#logout()
      */
     public void logout() {
+        // overwrite in subclass
     }
 
     /* (non-Javadoc)

Added: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java	Tue Aug 31 02:23:07 2004
@@ -0,0 +1,235 @@
+/*
+ * Copyright 1999-2002,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.profile.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
+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.coplet.adapter.CopletAdapter;
+import org.apache.cocoon.portal.layout.Layout;
+
+/**
+ * The profile manager using the authentication framework
+ * 
+ * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
+ * 
+ * @version CVS $Id: AbstractUserProfileManager.java 37123 2004-08-27 12:11:53Z cziegeler $
+ */
+public class GroupBasedProfileManager 
+    extends AbstractProfileManager { 
+
+    protected UserProfile getUserProfile() {
+        PortalService service = null;
+        try {
+            service = (PortalService)this.manager.lookup(PortalService.ROLE);
+
+            return (UserProfile)service.getAttribute(GroupBasedProfileManager.class.getName());
+        } catch (ServiceException e) {
+            // this should never happen
+            throw new CascadingRuntimeException("Unable to lookup portal service.", e);
+        } finally {
+            this.manager.release(service);
+        }
+    }
+    
+    protected void removeUserProfile() {
+        PortalService service = null;
+        try {
+            service = (PortalService)this.manager.lookup(PortalService.ROLE);
+
+            service.removeAttribute(GroupBasedProfileManager.class.getName());
+        } catch (ServiceException e) {
+            // this should never happen
+            throw new CascadingRuntimeException("Unable to lookup portal service.", e);
+        } finally {
+            this.manager.release(service);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#login()
+     */
+    public void login() {
+        super.login();
+        // TODO - we should move most of the stuff from getPortalLayout to here
+        // for now we use a hack :)
+        this.getPortalLayout(null, null);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#logout()
+     */
+    public void logout() {
+        final UserProfile profile = this.getUserProfile();
+        if ( profile != null ) {
+            ServiceSelector adapterSelector = null;
+            try {
+                adapterSelector = (ServiceSelector)this.manager.lookup(CopletAdapter.ROLE+"Selector");
+
+                Iterator iter = profile.getCopletInstanceDatas().values().iterator();
+                while ( iter.hasNext() ) {
+                    CopletInstanceData cid = (CopletInstanceData) iter.next();
+                    CopletAdapter adapter = null;
+                    try {
+                        adapter = (CopletAdapter)adapterSelector.select(cid.getCopletData().getCopletBaseData().getCopletAdapterName());
+                        adapter.logout( cid );
+                    } finally {
+                        adapterSelector.release( adapter );
+                    }
+                }
+
+            } catch (ServiceException e) {
+                throw new CascadingRuntimeException("Unable to lookup portal service.", e);
+            } finally {
+                this.manager.release(adapterSelector);
+            }
+            this.removeUserProfile();
+        }
+        super.logout();
+    }
+       
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(java.lang.String)
+     */
+    public CopletInstanceData getCopletInstanceData(String copletID) {
+        final UserProfile profile = this.getUserProfile();
+        if ( profile != null ) {
+            return (CopletInstanceData)profile.getCopletInstanceDatas().get(copletID);
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletData(java.lang.String)
+     */
+    public CopletData getCopletData(String copletDataId) {
+        final UserProfile profile = this.getUserProfile();
+        if ( profile != null ) {
+            return (CopletData)profile.getCopletDatas().get(copletDataId);
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(org.apache.cocoon.portal.coplet.CopletData)
+     */
+    public List getCopletInstanceData(CopletData data) {
+        final UserProfile profile = this.getUserProfile();
+        final List coplets = new ArrayList();
+        if ( profile != null ) {
+            final Iterator iter = profile.getCopletInstanceDatas().values().iterator();
+            while ( iter.hasNext() ) {
+                final CopletInstanceData current = (CopletInstanceData)iter.next();
+                if ( current.getCopletData().equals(data) ) {
+                    coplets.add( current );
+                }
+            }
+        }
+        return coplets;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
+     */
+    public void register(CopletInstanceData coplet) {
+        final UserProfile profile = this.getUserProfile();
+        profile.getCopletInstanceDatas().put(coplet.getId(), coplet);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
+     */
+    public void unregister(CopletInstanceData coplet) {
+        final UserProfile profile = this.getUserProfile();
+        profile.getCopletInstanceDatas().remove(coplet.getId());
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.layout.Layout)
+     */
+    public void register(Layout layout) {
+        if ( layout != null && layout.getId() != null ) {
+            final UserProfile profile = this.getUserProfile();    
+            profile.getLayouts().put(layout.getId(), layout);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.layout.Layout)
+     */
+    public void unregister(Layout layout) {
+        if ( layout != null && layout.getId() != null ) {
+            final UserProfile profile = this.getUserProfile();
+            profile.getLayouts().remove(layout.getId());
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getPortalLayout(java.lang.String, java.lang.String)
+     */
+    public Layout getPortalLayout(String layoutKey, String layoutID) {
+        PortalService service = null;
+
+        try {
+            service = (PortalService) this.manager.lookup(PortalService.ROLE);
+            if ( null == layoutKey ) {
+                layoutKey = this.getDefaultLayoutKey();
+            }
+            // FIXME actually this is a hack for full screen
+            Layout l = (Layout) service.getTemporaryAttribute("DEFAULT_LAYOUT:" + layoutKey);
+            if ( null != l) {
+                return l;
+            }
+            final UserProfile profile = this.getUserProfile();
+            return (Layout)profile.getLayouts().get(layoutID);
+        } catch (Exception ce) {
+            throw new CascadingRuntimeException("Exception during loading of profile.", ce);
+        } finally {
+            this.manager.release(service);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletDatas()
+     */
+    public Collection getCopletDatas() {
+        final UserProfile profile = this.getUserProfile();
+        if ( profile != null ) {
+            return profile.getCopletDatas().values();
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceDatas()
+     */
+    public Collection getCopletInstanceDatas() {
+        final UserProfile profile = this.getUserProfile();
+        if ( profile != null ) {
+            return profile.getCopletInstanceDatas().values();
+        }
+        return null;
+    }
+    
+}

Added: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserProfile.java
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserProfile.java	Tue Aug 31 02:23:07 2004
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.profile.impl;
+
+import java.util.Map;
+
+/**
+ * This data object holds all information about the current user:
+ * - references to the configuration
+ * - all selected coplets (coplet instance datas)
+ * - layout objects
+ * 
+ * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
+ * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class UserProfile {
+    
+    protected Map copletBaseDatas;
+    
+    protected Map copletDatas;
+    
+    protected Map copletInstanceDatas;
+    
+    protected Map layouts;
+    
+    /**
+     * @return Returns the copletBaseDatas.
+     */
+    public Map getCopletBaseDatas() {
+        return copletBaseDatas;
+    }
+    
+    /**
+     * @param copletBaseDatas The copletBaseDatas to set.
+     */
+    public void setCopletBaseDatas(Map copletBaseDatas) {
+        this.copletBaseDatas = copletBaseDatas;
+    }
+    
+    /**
+     * @return Returns the copletDatas.
+     */
+    public Map getCopletDatas() {
+        return copletDatas;
+    }
+    
+    /**
+     * @param copletDatas The copletDatas to set.
+     */
+    public void setCopletDatas(Map copletDatas) {
+        this.copletDatas = copletDatas;
+    }
+    
+    /**
+     * @return Returns the copletInstanceDatas.
+     */
+    public Map getCopletInstanceDatas() {
+        return copletInstanceDatas;
+    }
+    
+    /**
+     * @param copletInstanceDatas The copletInstanceDatas to set.
+     */
+    public void setCopletInstanceDatas(Map copletInstanceDatas) {
+        this.copletInstanceDatas = copletInstanceDatas;
+    }
+    
+    /**
+     * @return Returns the layouts.
+     */
+    public Map getLayouts() {
+        return layouts;
+    }
+    
+    /**
+     * @param layouts The layouts to set.
+     */
+    public void setLayouts(Map layouts) {
+        this.layouts = layouts;
+    }
+}