Author: cziegeler
Date: Tue Aug 31 03:35:12 2004
New Revision: 37247

Added:
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfo.java
   (contents, props changed)
Modified:
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/StaticProfileManager.java
Log:
Improving group based profile manager

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
     (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
     Tue Aug 31 03:35:12 2004
@@ -23,11 +23,13 @@
 import org.apache.avalon.framework.CascadingRuntimeException;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.ProcessingException;
 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;
+import org.apache.cocoon.webapps.authentication.AuthenticationManager;
 
 /**
  * The profile manager using the authentication framework
@@ -39,12 +41,17 @@
 public class GroupBasedProfileManager 
     extends AbstractProfileManager { 
 
-    protected UserProfile getUserProfile() {
+    protected static final String KEY_PREFIX = 
GroupBasedProfileManager.class.getName() + ':';
+    
+    protected UserProfile getUserProfile(String layoutKey) {
+        if ( layoutKey == null ) {
+            layoutKey = this.getDefaultLayoutKey();
+        }
         PortalService service = null;
         try {
             service = (PortalService)this.manager.lookup(PortalService.ROLE);
 
-            return 
(UserProfile)service.getAttribute(GroupBasedProfileManager.class.getName());
+            return (UserProfile)service.getAttribute(KEY_PREFIX + layoutKey);
         } catch (ServiceException e) {
             // this should never happen
             throw new CascadingRuntimeException("Unable to lookup portal 
service.", e);
@@ -53,12 +60,14 @@
         }
     }
     
-    protected void removeUserProfile() {
+    protected void removeUserProfiles() {
+        // TODO: remove all profiles - we have to rememember all used layout 
keys
+        String layoutKey = this.getDefaultLayoutKey();
         PortalService service = null;
         try {
             service = (PortalService)this.manager.lookup(PortalService.ROLE);
 
-            service.removeAttribute(GroupBasedProfileManager.class.getName());
+            service.removeAttribute(KEY_PREFIX + layoutKey);
         } catch (ServiceException e) {
             // this should never happen
             throw new CascadingRuntimeException("Unable to lookup portal 
service.", e);
@@ -81,7 +90,7 @@
      * @see org.apache.cocoon.portal.profile.ProfileManager#logout()
      */
     public void logout() {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         if ( profile != null ) {
             ServiceSelector adapterSelector = null;
             try {
@@ -104,7 +113,7 @@
             } finally {
                 this.manager.release(adapterSelector);
             }
-            this.removeUserProfile();
+            this.removeUserProfiles();
         }
         super.logout();
     }
@@ -113,7 +122,7 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(java.lang.String)
      */
     public CopletInstanceData getCopletInstanceData(String copletID) {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         if ( profile != null ) {
             return 
(CopletInstanceData)profile.getCopletInstanceDatas().get(copletID);
         }
@@ -124,7 +133,7 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#getCopletData(java.lang.String)
      */
     public CopletData getCopletData(String copletDataId) {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         if ( profile != null ) {
             return (CopletData)profile.getCopletDatas().get(copletDataId);
         }
@@ -135,7 +144,7 @@
      * @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 UserProfile profile = this.getUserProfile(null);
         final List coplets = new ArrayList();
         if ( profile != null ) {
             final Iterator iter = 
profile.getCopletInstanceDatas().values().iterator();
@@ -153,7 +162,7 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void register(CopletInstanceData coplet) {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         profile.getCopletInstanceDatas().put(coplet.getId(), coplet);
     }
     
@@ -161,7 +170,7 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void unregister(CopletInstanceData coplet) {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         profile.getCopletInstanceDatas().remove(coplet.getId());
     }
 
@@ -170,7 +179,7 @@
      */
     public void register(Layout layout) {
         if ( layout != null && layout.getId() != null ) {
-            final UserProfile profile = this.getUserProfile();    
+            final UserProfile profile = this.getUserProfile(null);    
             profile.getLayouts().put(layout.getId(), layout);
         }
     }
@@ -180,7 +189,7 @@
      */
     public void unregister(Layout layout) {
         if ( layout != null && layout.getId() != null ) {
-            final UserProfile profile = this.getUserProfile();
+            final UserProfile profile = this.getUserProfile(null);
             profile.getLayouts().remove(layout.getId());
         }
     }
@@ -201,7 +210,7 @@
             if ( null != l) {
                 return l;
             }
-            final UserProfile profile = this.getUserProfile();
+            final UserProfile profile = this.getUserProfile(layoutKey);
             return (Layout)profile.getLayouts().get(layoutID);
         } catch (Exception ce) {
             throw new CascadingRuntimeException("Exception during loading of 
profile.", ce);
@@ -214,7 +223,7 @@
      * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletDatas()
      */
     public Collection getCopletDatas() {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         if ( profile != null ) {
             return profile.getCopletDatas().values();
         }
@@ -225,11 +234,38 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceDatas()
      */
     public Collection getCopletInstanceDatas() {
-        final UserProfile profile = this.getUserProfile();
+        final UserProfile profile = this.getUserProfile(null);
         if ( profile != null ) {
             return profile.getCopletInstanceDatas().values();
         }
         return null;
     }
+
+    /**
+     * Return the user info about the current user.
+     * This implementation uses the authentication framework - if you
+     * want to use a different authentication method just overwrite this
+     * method.
+     */
+    protected UserInfo getUserInfo() {
+        AuthenticationManager authManager = null;
+        try {
+            authManager = 
(AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE);
+            final UserInfo info = new UserInfo();
+            info.setUserName(authManager.getState().getHandler().getUserId());
+            try {
+                
info.setGroup((String)authManager.getState().getHandler().getContext().getContextInfo().get("group"));
+            } catch (ProcessingException pe) {
+                // ignore this
+            }
+            return info;    
+        } catch (ServiceException ce) {
+            // ignore this here
+            return null;
+        } finally {
+            this.manager.release( authManager );
+        }
+    }
+        
     
 }

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/StaticProfileManager.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/StaticProfileManager.java
 (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/StaticProfileManager.java
 Tue Aug 31 03:35:12 2004
@@ -304,30 +304,35 @@
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void register(CopletInstanceData coplet) {
+        // nothing to do
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void unregister(CopletInstanceData coplet) {
+        // nothing to do
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.layout.Layout)
      */
     public void register(Layout layout) {
+        // nothing to do
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.layout.Layout)
      */
     public void unregister(Layout layout) {
+        // nothing to do
     }
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.profile.ProfileManager#saveUserProfiles()
      */
     public void saveUserProfiles() {
+        // nothing to do
     }
 
     /* (non-Javadoc)
@@ -338,7 +343,6 @@
         super.configure(configuration);
         Configuration child = configuration.getChild("profiles-path");
         this.profilesPath = child.getValue("cocoon:/profiles");
-        //this.profilesPath = "context://samples/simple-portal/profiles";
     }
         
     /* (non-Javadoc)

Added: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfo.java
==============================================================================
--- (empty file)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfo.java
     Tue Aug 31 03:35:12 2004
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+/**
+ * Information about the current user.
+ * This data object is used for loading the profile. It decouples the
+ * portal from the used authentication method.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
+ * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class UserInfo {
+    
+    protected String userName;
+    
+    protected String group;
+    
+    /**
+     * @return Returns the group.
+     */
+    public String getGroup() {
+        return group;
+    }
+
+    /**
+     * @param group The group to set.
+     */
+    public void setGroup(String group) {
+        this.group = group;
+    }
+    
+    /**
+     * @return Returns the userName.
+     */
+    public String getUserName() {
+        return userName;
+    }
+    
+    /**
+     * @param userName The userName to set.
+     */
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+}

Reply via email to