portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r533884 - in /portals/jetspeed-2/branches/J2-M2-REDUX/components: jetspeed-profiler/src/main/java/org/apache/jetspeed/ jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/ jetspeed-registry/src/main/java/org/apache/jetspeed/ jets...
Date Mon, 30 Apr 2007 23:47:14 GMT
Author: ate
Date: Mon Apr 30 16:47:12 2007
New Revision: 533884

URL: http://svn.apache.org/viewvc?view=rev&rev=533884
Log:
Ugh, damn svn, seems not all files were committed???
This really should have been part of the previous commit, r533883

Added:
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java   (with props)
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java   (with props)
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java   (with props)
Removed:
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecondaryData.java
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSeedData.java
Modified:
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/   (props changed)
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/   (props changed)
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/   (props changed)
    portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/   (props changed)

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Apr 30 16:47:12 2007
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Added: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java?view=auto&rev=533884
==============================================================================
--- portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java (added)
+++ portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java Mon Apr 30 16:47:12 2007
@@ -0,0 +1,434 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.serializer;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.ProfilerException;
+import org.apache.jetspeed.profiler.rules.PrincipalRule;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.profiler.rules.RuleCriterion;
+import org.apache.jetspeed.security.BasePrincipal;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.serializer.objects.JSPrincipalRule;
+import org.apache.jetspeed.serializer.objects.JSPrincipalRules;
+import org.apache.jetspeed.serializer.objects.JSProfilingRule;
+import org.apache.jetspeed.serializer.objects.JSProfilingRules;
+import org.apache.jetspeed.serializer.objects.JSRuleCriterion;
+import org.apache.jetspeed.serializer.objects.JSRuleCriterions;
+import org.apache.jetspeed.serializer.objects.JSSnapshot;
+import org.apache.jetspeed.serializer.objects.JSUser;
+
+/**
+ * @version $Id$
+ * 
+ */
+public class JetspeedProfilerSerializer extends AbstractJetspeedComponentSerializer
+{
+    protected Profiler pm;
+
+    protected UserManager userManager;
+
+    public JetspeedProfilerSerializer(Profiler pm, UserManager userManager)
+    {
+        this.pm = pm;
+        this.userManager = userManager;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processExport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processExport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_PROFILER))
+        {
+            log.info("collecting profiling rules and user profiling rules");
+            exportProfilingRules(snapshot, settings, log);
+            exportUserPrincipalRules(snapshot, settings, log);
+        }
+    }
+
+    protected void deleteData(Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_PROFILER))
+        {
+            log.info("deleting profiling rules and user profiling rules");
+
+            try
+            {
+                Iterator _itUsers = userManager.getUsers("");
+                while (_itUsers.hasNext())
+                {
+                    JSUser _user = (JSUser) _itUsers.next();
+                    Principal principal = _user.getPrincipal();
+                    if (principal != null)
+                    {
+                        Collection col = pm.getRulesForPrincipal(principal);
+                        Iterator _itCol = col.iterator();
+                        while (_itCol.hasNext())
+                        {
+                            pm.deletePrincipalRule((PrincipalRule)_itCol.next());
+                        }
+                    }
+                }
+                Iterator _itRules = pm.getRules().iterator();
+                while ( _itRules.hasNext() )
+                {
+                    pm.deleteProfilingRule((ProfilingRule)_itRules.next());
+                }                
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(e);
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processImport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processImport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_PROFILER))
+        {
+            log.info("creating profiling rules and user profiling rules");
+            recreateProfilingRules(snapshot, settings, log);
+            recreateUserPrincipalRules(snapshot, settings, log);
+        }
+    }
+
+    private void recreateProfilingRules(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        log.debug("recreateProfilingRules - processing");
+        JSProfilingRules rules = snapshot.getRules();
+        if ((rules != null) && (rules.size() > 0))
+        {
+            Iterator _it = rules.iterator();
+            while (_it.hasNext())
+            {
+                JSProfilingRule _c = (JSProfilingRule) _it.next();
+
+                try
+                {
+                    ProfilingRule rule = null;
+
+                    rule = pm.getRule(_c.getId());
+                    if ((rule == null) || (isSettingSet(settings, JetspeedSerializer.KEY_OVERWRITE_EXISTING)))
+                    {
+                        rule = recreateRule(pm, rule, _c);
+                        pm.storeProfilingRule(rule);
+                    }
+                }
+                catch (Exception e)
+                {
+                    throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(
+                            "org.apache.jetspeed.capabilities.Capabilities", e.getLocalizedMessage()));
+                }
+            }
+            /** reset the default profiling rule */
+            String defaultRuleID = snapshot.getDefaultRule();
+            if (defaultRuleID != null)
+            {
+                ProfilingRule defaultRule = pm.getRule(defaultRuleID);
+                if (defaultRule != null)
+                    pm.setDefaultRule(defaultRuleID);
+            }
+        }
+        else
+            log.debug("NO PROFILING RULES?????");
+        log.debug("recreateProfilingRules - done");
+    }
+
+    /**
+     * called only after users have been established
+     * 
+     * @throws SerializerException
+     */
+    private void recreateUserPrincipalRules(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        log.debug("recreateUserPrincipalRules - started");
+
+        // get Rules for each user
+
+        Iterator _itUsers = snapshot.getUsers().iterator();
+        while (_itUsers.hasNext())
+        {
+            JSUser _user = (JSUser) _itUsers.next();
+            JSPrincipalRules jsRules = _user.getRules();
+            try
+            {
+                User user = userManager.getUser(_user.getName());
+                Principal principal = getUserPrincipal(user);
+                if (jsRules != null)
+                {
+                    Iterator _itRoles = jsRules.iterator();
+                    while (_itRoles.hasNext())
+                    {
+                        JSPrincipalRule pr = (JSPrincipalRule) _itRoles.next();
+                        ProfilingRule pRule = pm.getRule(pr.getRule());
+
+                        try
+                        {
+                            PrincipalRule p1 = pm.createPrincipalRule();
+                            p1.setLocatorName(pr.getLocator());
+                            p1.setProfilingRule(pRule);
+                            p1.setPrincipalName(principal.getName());
+                            pm.storePrincipalRule(p1);
+                        }
+                        catch (Exception eRole)
+                        {
+                            eRole.printStackTrace();
+                        }
+                    }
+                }
+            }
+            catch (Exception eUser)
+            {
+                eUser.printStackTrace();
+            }
+        }
+        log.debug("recreateUserPrincipalRules - done");
+
+    }
+
+    /**
+     * recreate a rule criterion object from the deserialized wrapper
+     * 
+     * @param profiler
+     *            established profile manager
+     * @param jsr
+     *            deserialized object
+     * @return new RuleCriterion with content set to deserialized wrapepr
+     * @throws SerializerException
+     */
+    protected RuleCriterion recreateRuleCriterion(Profiler profiler, JSRuleCriterion jsr, ProfilingRule rule)
+            throws SerializerException, ClassNotFoundException
+
+    {
+        try
+        {
+
+            RuleCriterion c = profiler.createRuleCriterion();
+            if (c == null)
+                throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(
+                        "org.apache.jetspeed.profiler.rules.RuleCriterion", "returned null"));
+            c.setFallbackOrder(jsr.getFallBackOrder());
+            c.setFallbackType(jsr.getFallBackType());
+            c.setName(jsr.getName());
+            c.setType(jsr.getType());
+            c.setValue(jsr.getValue());
+            c.setRuleId(rule.getId());
+            return c;
+        }
+        catch (Exception e)
+        {
+            SerializerException.CREATE_OBJECT_FAILED.create("org.apache.jetspeed.profiler.rules.RuleCriterion", e
+                    .getLocalizedMessage());
+            return null;
+        }
+    }
+
+    /**
+     * recreate a profiling rule object from the deserialized wrapper and store
+     * it
+     * 
+     * @param profiler
+     *            established profile manager
+     * @param jsp
+     * deserialized object @
+     * @throws SerializerException,
+     *             ClassNotFoundException, ProfilerException
+     */
+    protected ProfilingRule recreateRule(Profiler profiler, ProfilingRule existingRule, JSProfilingRule jsp)
+            throws SerializerException, ClassNotFoundException, ProfilerException
+    {
+        ProfilingRule rule = null;
+        boolean existing = false;
+
+        if (existingRule == null)
+        {
+            rule = profiler.getRule(jsp.getId());
+            if (jsp.isStandardRule())
+                rule = profiler.createProfilingRule(true);
+            else
+                rule = profiler.createProfilingRule(false);
+            rule.setId(jsp.getId());
+        }
+        else
+        {
+            rule = existingRule;
+            existing = true;
+        }
+
+        rule.setTitle(jsp.getDescription());
+
+        JSRuleCriterions col = jsp.getCriterions();
+
+        Iterator _it = col.iterator();
+        while (_it.hasNext())
+        {
+            RuleCriterion c = recreateRuleCriterion(profiler, (JSRuleCriterion) _it.next(), rule);
+            if (c != null)
+            {
+                Collection cHelp = rule.getRuleCriteria();
+                if ((existing) && (cHelp.contains(c)))
+                    cHelp.remove(c); // remove existing duplicate
+                cHelp.add(c); // add the current version back in
+            }
+        }
+        return rule;
+
+    }
+
+    private Principal getUserPrincipal(User user)
+    {
+        Subject subject = user.getSubject();
+        // get the user principal
+        Set principals = subject.getPrincipals();
+        Iterator list = principals.iterator();
+        while (list.hasNext())
+        {
+            BasePrincipal principal = (BasePrincipal) list.next();
+            String path = principal.getFullPath();
+            if (path.startsWith("/user/"))
+                return principal;
+        }
+        return null;
+    }
+
+    /**
+     * read the permissions and then the profiling rules.
+     * <p>
+     * after that update the cross reference with the users
+     * 
+     * @throws SerializerException
+     */
+    private void exportProfilingRules(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        HashMap rulesMap = new HashMap();
+        Class standardRuleClass = null;
+        try
+        {
+            ProfilingRule tempStandardRule = pm.createProfilingRule(true);
+            standardRuleClass = tempStandardRule.getClass();
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] {
+                    "Standard Rule", e.getMessage() }));
+        }
+
+        Iterator list = null;
+        try
+        {
+            list = pm.getRules().iterator();
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] {
+                    "ProfilingRules", e.getMessage() }));
+        }
+        while (list.hasNext())
+        {
+            try
+            {
+                ProfilingRule p = (ProfilingRule) list.next();
+                if (!(rulesMap.containsKey(p.getId())))
+                {
+                    JSProfilingRule rule = createProfilingRule(p, (standardRuleClass == p.getClass()));
+                    rulesMap.put(rule.getId(), rule);
+                    snapshot.getRules().add(rule);
+
+                }
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "ProfilingRules", e.getMessage() }));
+            }
+        }
+
+        // determine the defualt rule
+        ProfilingRule defaultRule = pm.getDefaultRule();
+        if (defaultRule != null)
+            snapshot.setDefaultRule(defaultRule.getId());
+    }
+
+    private void exportUserPrincipalRules(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        // get Rules for each user
+
+        Iterator _itUsers = snapshot.getUsers().iterator();
+        while (_itUsers.hasNext())
+        {
+            JSUser _user = (JSUser) _itUsers.next();
+            Principal principal = _user.getPrincipal();
+            if (principal != null)
+            {
+                Collection col = pm.getRulesForPrincipal(principal);
+                Iterator _itCol = col.iterator();
+                while (_itCol.hasNext())
+                {
+                    PrincipalRule p1 = (PrincipalRule) _itCol.next();
+                    JSPrincipalRule pr = new JSPrincipalRule(p1.getLocatorName(), p1.getProfilingRule().getId());
+                    _user.getRules().add(pr);
+                }
+            }
+        }
+    }
+
+    /**
+     * Create the Profiling Rule Wrapper
+     * 
+     * @param p
+     * @return
+     */
+    private JSProfilingRule createProfilingRule(ProfilingRule p, boolean standard)
+    {
+        JSProfilingRule rule = new JSProfilingRule();
+
+        rule.setStandardRule(standard);
+        rule.setDescription(p.getTitle());
+        rule.setId(p.getId());
+
+        Collection col = p.getRuleCriteria();
+        Iterator keys = col.iterator();
+        while (keys.hasNext())
+        {
+            RuleCriterion rc = (RuleCriterion) keys.next();
+            rule.getCriterions().add(new JSRuleCriterion(rc));
+        }
+        return rule;
+
+    }
+}

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Apr 30 16:47:12 2007
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Added: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java?view=auto&rev=533884
==============================================================================
--- portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java (added)
+++ portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java Mon Apr 30 16:47:12 2007
@@ -0,0 +1,471 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.serializer;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+import java.util.prefs.Preferences;
+
+import org.apache.commons.logging.Log;
+import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
+import org.apache.jetspeed.om.common.portlet.PortletApplication;
+import org.apache.jetspeed.om.preference.impl.PrefsPreference;
+import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
+import org.apache.jetspeed.search.SearchEngine;
+import org.apache.jetspeed.serializer.objects.JSApplication;
+import org.apache.jetspeed.serializer.objects.JSApplications;
+import org.apache.jetspeed.serializer.objects.JSEntities;
+import org.apache.jetspeed.serializer.objects.JSEntity;
+import org.apache.jetspeed.serializer.objects.JSEntityPreference;
+import org.apache.jetspeed.serializer.objects.JSEntityPreferences;
+import org.apache.jetspeed.serializer.objects.JSNVPElements;
+import org.apache.jetspeed.serializer.objects.JSPortlet;
+import org.apache.jetspeed.serializer.objects.JSPortlets;
+import org.apache.jetspeed.serializer.objects.JSSnapshot;
+import org.apache.pluto.om.common.Preference;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.pluto.om.portlet.PortletDefinitionList;
+
+/**
+ * @version $Id$
+ * 
+ */
+public class JetspeedRegistrySerializer extends AbstractJetspeedComponentSerializer
+{
+    protected PortletEntityAccessComponent entityAccess;
+
+    protected PortletRegistry registry;
+    protected SearchEngine searchEngine;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processExport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processExport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_ENTITIES))
+        {
+            log.info("collecting applications and entities");
+            exportEntities(snapshot, settings, log);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processImport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processImport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_ENTITIES))
+        {
+            log.info("creating entities");
+            importEntities(snapshot, settings, log);
+        }
+    }
+
+    protected void deleteData(Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_ENTITIES))
+        {
+            log.info("deleting applications and entities");
+            try
+            {
+                Iterator _it = registry.getPortletApplications().iterator();
+                while (_it.hasNext())
+                {
+                    PortletApplication pa = (PortletApplication)_it.next();
+                    Collection portlets = pa.getPortletDefinitions();
+                    
+                    if (searchEngine != null)
+                    {
+                        searchEngine.remove(pa);
+                        searchEngine.remove(portlets);
+                    }
+                    Iterator _pdIter = portlets.iterator();
+                    while ( _pdIter.hasNext() )
+                    {
+                        entityAccess.removePortletEntities((PortletDefinition)_pdIter.next());
+                    }
+                    registry.removeApplication(pa);
+                }
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(e);
+            }
+        }
+    }
+
+    private void importEntities(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        JSApplications applications = snapshot.getApplications();
+
+        if (applications == null)
+        {
+            System.out.println("NO DATA!!!!!!");
+            return;
+        }
+        Iterator it = applications.iterator();
+        while (it.hasNext())
+        {
+            JSApplication app = (JSApplication) it.next();
+            MutablePortletApplication portletApp = registry.getPortletApplication(app.getName());
+            if (portletApp != null)
+            {
+                importPA(app, portletApp, settings, log);
+            }
+        }
+    }
+
+    void importPA(JSApplication app, MutablePortletApplication pa, Map settings, Log log) throws SerializerException
+    {
+
+        System.out.println("--processed PA " + pa.getName() + " with id=" + pa.getId());
+        /**
+         * while more PAs for each portletDef
+         * list:entityMan:getPortletEntity(pd)
+         */
+
+        Iterator pi = app.getPortlets().iterator();
+        while (pi.hasNext())
+        {
+            JSPortlet portlet = (JSPortlet) pi.next();
+            PortletDefinition pd = pa.getPortletDefinitionByName(portlet.getName());
+            if (pd != null)
+            {
+                importPD(portlet, pd, settings, log);
+            }
+        }
+    }
+
+    private void importPD(JSPortlet portlet, PortletDefinition pd, Map settings, Log log) throws SerializerException
+    {
+
+        JSEntities entities = portlet.getEntities();
+        Iterator it = entities.iterator();
+        while (it.hasNext())
+        {
+            JSEntity entity = (JSEntity) it.next();
+            MutablePortletEntity portletEntity = entityAccess.getPortletEntity(entity.getId());
+            if (portletEntity == null)
+            {
+                portletEntity = entityAccess.newPortletEntityInstance(pd, entity.getId());
+                try
+                {
+                    entityAccess.storePortletEntity(portletEntity);
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+            // check preferences
+
+            importEntityPref(entity, portletEntity, settings, log);
+        }
+    }
+
+    private void importEntityPref(JSEntity entity, MutablePortletEntity portletEntity, Map settings, Log log)
+    {
+
+        // do I carry any preferences?
+        JSEntityPreferences preferences = entity.getEntityPreferences();
+        if ((preferences == null) || (preferences.size() == 0))
+            return;
+
+        // since I do have preferences let us make sure we have a root node
+
+        String rootForEntity = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + portletEntity.getId();
+        try
+        {
+            Preferences.userRoot().node(rootForEntity); // will create it if it
+            // doesn't exist
+
+            Iterator it = preferences.iterator();
+            while (it.hasNext())
+            {
+                JSEntityPreference preference = (JSEntityPreference) it.next();
+
+                // do we have preferences for this one?
+                importPreferenceNode(preference, portletEntity, settings, log);
+            }
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return;
+        }
+
+    }
+
+    private void importPreferenceNode(JSEntityPreference preference, MutablePortletEntity entity, Map settings, Log log)
+    {
+
+        String child = preference.getName();
+
+        String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId() + "/" + child + "/"
+                + PrefsPreference.PORTLET_PREFERENCES_ROOT;
+        Preferences prefNode = Preferences.userRoot().node(prefNodePath);
+
+        if (prefNode == null)
+            return;
+
+        JSNVPElements prefList = preference.getPreferences();
+        try
+        {
+            PrefsPreferenceSetImpl preferenceSet = new PrefsPreferenceSetImpl(prefNode);
+
+            Iterator it = prefList.getMyMap().keySet().iterator();
+
+            while (it.hasNext())
+            {
+                String key = (String) it.next();
+                String value = (String) prefList.getMyMap().get(key);
+                Preference p = preferenceSet.get(key);
+                if ((p == null) || isSettingSet(settings, JetspeedSerializer.KEY_OVERWRITE_EXISTING))
+                {
+
+                    Vector v = new Vector();
+                    v.add(value);
+                    preferenceSet.add(key, v);
+                    log.debug("Entity " + entity.getId() + " updated with preference " + key + "=" + value);
+                }
+            }
+            preferenceSet.flush();
+            return;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return;
+
+        }
+
+    }
+
+    private void exportEntities(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        Collection col = registry.getPortletApplications();
+        if ((col == null) || (col.size() == 0))
+            return;
+        Iterator list = null;
+        try
+        {
+            list = col.iterator();
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "registry",
+                    e.getMessage() }));
+        }
+        while (list.hasNext())
+        {
+            try
+            {
+                MutablePortletApplication pa = (MutablePortletApplication) list.next();
+                // PortletApplicationDefinition pa =
+                // (PortletApplicationDefinition)list.next();
+                snapshot.getApplications().add(exportPA(pa));
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "PortletApplicationDefinition", e.getMessage() }));
+            }
+        }
+    }
+
+    private JSApplication exportPA(MutablePortletApplication pa) throws SerializerException
+    {
+
+        JSApplication app = new JSApplication();
+        System.out.println("--processed PA " + pa.getName() + " with id=" + pa.getId());
+        app.setID(pa.getId().toString());
+        app.setName(pa.getName());
+        /**
+         * while more PAs for each portletDef
+         * list:entityMan:getPortletEntity(pd)
+         */
+        PortletDefinitionList portletList = pa.getPortletDefinitionList(); // .get(JetspeedObjectID.createFromString(TEST_PORTLET));
+        Iterator pi = portletList.iterator();
+        PortletDefinition pd = null;
+
+        JSPortlets portlets = new JSPortlets();
+        while (pi.hasNext())
+        {
+            try
+            {
+                pd = (PortletDefinition) pi.next();
+                JSPortlet p = exportPD(pd);
+                if (p != null)
+                {
+                    System.out.println("--processed PA " + pa.getName() + " with pd=" + pd.getName());
+                    portlets.add(p);
+                }
+                else
+                    System.out.println("--processed PA " + pa.getName() + " with NULL pd=" + pd.getName());
+
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "PortletDefinition", e.getMessage() }));
+            }
+        }
+        app.setPortlets(portlets);
+        return app;
+    }
+
+    private JSPortlet exportPD(PortletDefinition pd) throws SerializerException
+    {
+
+        try
+        {
+            Collection col = entityAccess.getPortletEntities(pd);
+            if ((col == null) || (col.size() == 0))
+                return null;
+            JSPortlet portlet = new JSPortlet();
+            portlet.setName(pd.getName());
+            Iterator list = null;
+            try
+            {
+                list = col.iterator();
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] {
+                        "entityAccess", e.getMessage() }));
+            }
+            JSEntities entities = new JSEntities();
+
+            while (list.hasNext())
+            {
+                MutablePortletEntity entity = (MutablePortletEntity) list.next();
+                JSEntity jsEntity = exportEntityPref(entity);
+                if (jsEntity != null)
+                    entities.add(jsEntity);
+
+            }
+            System.out.println("-----processedAnyEntities for PD=" + pd.getName());
+            portlet.setEntities(entities);
+            return portlet;
+
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                    "Entity", e.getMessage() }));
+        }
+    }
+
+    JSEntity exportEntityPref(MutablePortletEntity entity)
+    {
+        JSEntity jsEntity = new JSEntity();
+        jsEntity.setId(entity.getId().toString());
+        String rootForEntity = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId();
+        try
+        {
+            if (!(Preferences.userRoot().nodeExists(rootForEntity)))
+            {
+                // System.out.println("No preferences exist for entity "+
+                // entity.getId());
+                return jsEntity;
+            }
+
+            Preferences prefNode = Preferences.userRoot().node(rootForEntity);
+            String[] children = prefNode.childrenNames();
+            if ((children != null) && (children.length > 0))
+            {
+                JSEntityPreferences permissions = new JSEntityPreferences();
+
+                for (int i = 0; i < children.length; i++)
+                {
+                    JSEntityPreference permission = exportPreferenceNode(entity, children[i]);
+                    if (permission != null)
+                        permissions.add(permission);
+                }
+                System.out.println("processed preferences for entity=" + entity.getId());
+                jsEntity.setEntityPreferences(permissions);
+                return jsEntity;
+                // processPreferenceNode(entity,prefNode,null);
+            }
+            return jsEntity;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+    JSEntityPreference exportPreferenceNode(MutablePortletEntity entity, String child)
+    {
+        String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId() + "/" + child + "/"
+                + PrefsPreference.PORTLET_PREFERENCES_ROOT;
+        Preferences prefNode = Preferences.userRoot().node(prefNodePath);
+
+        if (prefNode == null)
+            return null;
+        JSEntityPreference permission = new JSEntityPreference();
+        permission.setName(child);
+
+        try
+        {
+            PrefsPreferenceSetImpl preferenceSet = new PrefsPreferenceSetImpl(prefNode);
+            if (preferenceSet.size() == 0)
+                return null;
+            Iterator it = preferenceSet.iterator();
+            JSNVPElements v = new JSNVPElements();
+
+            while (it.hasNext())
+            {
+                Preference pref = (Preference) it.next();
+                String name = pref.getName();
+                Iterator ii = pref.getValues();
+                while (ii.hasNext())
+                {
+                    Object o = ii.next();
+                    v.add(name, o.toString());
+                }
+            }
+            if (v.size() > 0)
+            {
+                permission.setPreferences(v);
+                return permission;
+            }
+            return null;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return null;
+
+        }
+
+    }
+}

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Apr 30 16:47:12 2007
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Added: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java?view=auto&rev=533884
==============================================================================
--- portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java (added)
+++ portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java Mon Apr 30 16:47:12 2007
@@ -0,0 +1,918 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.serializer;
+
+import java.lang.reflect.Constructor;
+import java.security.Permission;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.prefs.Preferences;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.jetspeed.security.BasePrincipal;
+import org.apache.jetspeed.security.FolderPermission;
+import org.apache.jetspeed.security.FragmentPermission;
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.PagePermission;
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.PermissionManager;
+import org.apache.jetspeed.security.PortalResourcePermission;
+import org.apache.jetspeed.security.PortletPermission;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.om.InternalPermission;
+import org.apache.jetspeed.security.om.InternalPrincipal;
+import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
+import org.apache.jetspeed.serializer.objects.JSGroup;
+import org.apache.jetspeed.serializer.objects.JSGroups;
+import org.apache.jetspeed.serializer.objects.JSNVPElements;
+import org.apache.jetspeed.serializer.objects.JSPermission;
+import org.apache.jetspeed.serializer.objects.JSRole;
+import org.apache.jetspeed.serializer.objects.JSRoles;
+import org.apache.jetspeed.serializer.objects.JSSnapshot;
+import org.apache.jetspeed.serializer.objects.JSUser;
+import org.apache.jetspeed.serializer.objects.JSUserAttributes;
+import org.apache.jetspeed.serializer.objects.JSUserGroups;
+import org.apache.jetspeed.serializer.objects.JSUserRoles;
+import org.apache.jetspeed.serializer.objects.JSUserUsers;
+import org.apache.jetspeed.serializer.objects.JSUsers;
+
+/**
+ * @version $Id$
+ * 
+ */
+public class JetspeedSecuritySerializer extends AbstractJetspeedComponentSerializer
+{
+    private static String ENCODING_STRING = "JETSPEED 2.1 - 2006";
+
+    private static String JETSPEED = "JETSPEED";
+
+    private static class Refs
+    {
+        private HashMap roleMap = new HashMap();
+
+        private HashMap groupMap = new HashMap();
+
+        private HashMap userMap = new HashMap();
+
+        private HashMap permissionMap = new HashMap();
+    }
+
+    protected GroupManager groupManager;
+
+    protected RoleManager roleManager;
+
+    protected UserManager userManager;
+
+    protected PasswordCredentialProvider pcp;
+
+    protected PermissionManager pm;
+
+    public JetspeedSecuritySerializer(GroupManager groupManager, RoleManager roleManager, UserManager userManager,
+            PasswordCredentialProvider pcp, PermissionManager pm)
+    {
+        this.groupManager = groupManager;
+        this.roleManager = roleManager;
+        this.userManager = userManager;
+        this.pcp = pcp;
+        this.pm = pm;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processExport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processExport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_USERS))
+        {
+            log.info("collecting users/roles/groups and permissions");
+            Refs refs = new Refs();
+            exportRolesGroupsUsers(refs, snapshot, settings, log);
+            exportPermissions(refs, snapshot, settings, log);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.serializer.JetspeedComponentSerializer#processImport(org.apache.jetspeed.serializer.objects.JSSnapshot,
+     *      java.util.Map, org.apache.commons.logging.Log)
+     */
+    protected void processImport(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_USERS))
+        {
+            log.info("creating users/roles/groups and permissions");
+            Refs refs = new Refs();
+            recreateRolesGroupsUsers(refs, snapshot, settings, log);
+            recreatePermissions(refs, snapshot, settings, log);
+        }
+    }
+
+    protected void deleteData(Map settings, Log log) throws SerializerException
+    {
+        if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_USERS))
+        {
+            log.info("deleting users/roles/groups and permissions");
+            try
+            {
+                Iterator _it = pm.getPermissions().iterator();
+                while ( _it.hasNext() )
+                {
+                    InternalPermission ip = (InternalPermission)_it.next();
+                    Class permissionClass = Class.forName(ip.getClassname());
+                    Class[] parameterTypes = { String.class, String.class };
+                    Constructor permissionConstructor = permissionClass.getConstructor(parameterTypes);
+                    Object[] initArgs = { ip.getName(), ip.getActions() };
+                    Permission permission = (Permission) permissionConstructor.newInstance(initArgs);            
+                    pm.removePermission(permission);
+                }
+                
+                String anonymousUser = userManager.getAnonymousUser();
+                _it = userManager.getUserNames("");
+                while (_it.hasNext())
+                {
+                    String userName = (String)_it.next();
+                    if ( !anonymousUser.equals(userName) )
+                    {
+                        userManager.removeUser((String)_it.next());
+                    }
+                }
+                
+                _it = groupManager.getGroups("");
+                while (_it.hasNext())
+                {
+                    groupManager.removeGroup(((Group)_it.next()).getPrincipal().getName());
+                }
+                
+                _it = roleManager.getRoles("");
+                while (_it.hasNext())
+                {
+                    roleManager.removeRole(((Role)_it.next()).getPrincipal().getName());
+                }
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(e);
+            }
+        }
+    }
+
+    /**
+     * import the groups, roles and finally the users to the current environment
+     * 
+     * @throws SerializerException
+     */
+    private void recreateRolesGroupsUsers(Refs refs, JSSnapshot snapshot, Map settings, Log log)
+            throws SerializerException
+    {
+        log.debug("recreateRolesGroupsUsers");
+
+        JSGroups groups = null;
+        JSRoles roles = null;
+
+        groups = snapshot.getGroups();
+
+        Iterator _it = groups.iterator();
+        while (_it.hasNext())
+        {
+            String name = ((JSGroup) _it.next()).getName();
+
+            try
+            {
+                if (!(groupManager.groupExists(name)))
+                    groupManager.addGroup(name);
+                Group group = groupManager.getGroup(name);
+                refs.groupMap.put(name, group.getPrincipal());
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "Group",
+                        e.getMessage() }));
+            }
+        }
+        log.debug("recreateGroups - done");
+        log.debug("processing roles");
+
+        roles = snapshot.getRoles();
+
+        _it = roles.iterator();
+        while (_it.hasNext())
+        {
+            String name = ((JSRole) _it.next()).getName();
+
+            try
+            {
+                if (!(roleManager.roleExists(name)))
+                    roleManager.addRole(name);
+                Role role = roleManager.getRole(name);
+                refs.roleMap.put(name, role.getPrincipal());
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "Role",
+                        e.getMessage() }));
+            }
+        }
+        log.debug("recreateRoles - done");
+        log.debug("processing users");
+
+        /** determine whether passwords can be reconstructed or not */
+        int passwordEncoding = compareCurrentSecurityProvider(snapshot);
+        JSUsers users = null;
+        users = snapshot.getUsers();
+
+        _it = users.iterator();
+        while (_it.hasNext())
+        {
+
+            JSUser jsuser = (JSUser) _it.next();
+
+            try
+            {
+                User user = null;
+                if (userManager.userExists(jsuser.getName()))
+                {
+                    user = userManager.getUser(jsuser.getName());
+                }
+                if ((isSettingSet(settings, JetspeedSerializer.KEY_OVERWRITE_EXISTING)) || (user == null))
+                {
+                    if (user == null) // create new one
+                    {
+                        String password = recreatePassword(jsuser.getPassword());
+                        log.debug("add User " + jsuser.getName() + " with password " + password);
+                        userManager.importUser(jsuser.getName(), password,
+                                (passwordEncoding == JetspeedSerializer.PASSTHRU_REQUIRED));
+                        log.debug("add User done ");
+                        user = userManager.getUser(jsuser.getName());
+                    }
+                    try
+                    {
+                        userManager.setPasswordEnabled(jsuser.getName(), jsuser.getPwEnabled());
+                        userManager.setPasswordUpdateRequired(jsuser.getName(), jsuser.getPwRequiredUpdate());
+                        java.sql.Date d = jsuser.getPwExpirationDate();
+                        if (d != null)
+                            userManager.setPasswordExpiration(jsuser.getName(), d);
+                    }
+                    catch (Exception e)
+                    {
+                        // most likely caused by protected users (like "guest")
+                        log.debug("setting userinfo for " + jsuser.getName() + " failed because of "
+                                + e.getLocalizedMessage());
+                    }
+
+                    // credentials
+                    Subject subject = user.getSubject();
+
+                    ArrayList listTemp = jsuser.getPrivateCredentials();
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            subject.getPrivateCredentials().add(_itTemp.next());
+                        }
+                    }
+                    listTemp = jsuser.getPublicCredentials();
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            subject.getPublicCredentials().add(_itTemp.next());
+                        }
+                    }
+                    JSUserGroups jsUserGroups = jsuser.getGroupString();
+                    if (jsUserGroups != null)
+                        listTemp = getTokens(jsUserGroups.toString());
+                    else
+                        listTemp = null;
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            groupManager.addUserToGroup(jsuser.getName(), (String) _itTemp.next());
+                        }
+                    }
+                    JSUserRoles jsUserRoles = jsuser.getRoleString();
+                    if (jsUserRoles != null)
+                        listTemp = getTokens(jsUserRoles.toString());
+                    else
+                        listTemp = null;
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            roleManager.addRoleToUser(jsuser.getName(), (String) _itTemp.next());
+                        }
+                    }
+                    JSUserAttributes attributes = jsuser.getUserInfo();
+                    if (attributes != null)
+                    {
+                        Preferences userAttributes = user.getUserAttributes();
+                        HashMap map = attributes.getMyMap();
+                        if (map != null)
+                        {
+                            Iterator _itTemp = map.keySet().iterator();
+                            while (_itTemp.hasNext())
+                            {
+                                String userAttrName = (String) _itTemp.next();
+                                // if ( userAttributes.get(userAttrName,
+                                // "").equals("")
+                                String userAttrValue = (String) map.get(userAttrName);
+                                userAttributes.put(userAttrName, userAttrValue);
+                            }
+                        }
+
+                    }
+
+                    JSNVPElements jsNVP = jsuser.getPreferences();
+                    if ((jsNVP != null) && (jsNVP.getMyMap() != null))
+                    {
+                        Preferences preferences = user.getPreferences();
+                        Iterator _itTemp = jsNVP.getMyMap().keySet().iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            String prefKey = (String) _itTemp.next();
+                            String prefValue = (String) (jsNVP.getMyMap().get(prefKey));
+                            preferences.put(prefKey, prefValue);
+                        }
+                    }
+
+                    refs.userMap.put(jsuser.getName(), getUserPrincipal(user));
+
+                }
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+                throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "User",
+                        e.getMessage() }));
+            }
+        }
+        log.debug("recreateUsers - done");
+    }
+
+    /**
+     * recreates all permissions from the current snapshot
+     * 
+     * @throws SerializerException
+     */
+    private void recreatePermissions(Refs refs, JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        log.debug("recreatePermissions - started");
+
+        Iterator list = null;
+        try
+        {
+            list = snapshot.getPermissions().iterator();
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "Permissions",
+                    e.getMessage() }));
+        }
+
+        while (list.hasNext())
+        {
+            JSPermission _js = (JSPermission) list.next();
+            PortalResourcePermission perm = getPermissionForType(_js);
+            if ((perm != null) && (perm instanceof PortalResourcePermission))
+            {
+                try
+                {
+                    pm.addPermission(perm);
+                    ArrayList listTemp = null;
+                    JSUserGroups jsUserGroups = _js.getGroupString();
+                    if (jsUserGroups != null)
+                        listTemp = getTokens(jsUserGroups.toString());
+                    else
+                        listTemp = null;
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            Principal p = (Principal) refs.groupMap.get((String) _itTemp.next());
+                            if (p != null)
+                                pm.grantPermission(p, perm);
+                        }
+                    }
+                    JSUserRoles jsUserRoles = _js.getRoleString();
+                    if (jsUserRoles != null)
+                        listTemp = getTokens(jsUserRoles.toString());
+                    else
+                        listTemp = null;
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            Principal p = (Principal) refs.roleMap.get((String) _itTemp.next());
+                            if (p != null)
+                                pm.grantPermission(p, perm);
+                        }
+                    }
+                    JSUserUsers jsUserUsers = _js.getUserString();
+                    if (jsUserUsers != null)
+                        listTemp = getTokens(jsUserUsers.toString());
+                    else
+                        listTemp = null;
+                    if ((listTemp != null) && (listTemp.size() > 0))
+                    {
+                        Iterator _itTemp = listTemp.iterator();
+                        while (_itTemp.hasNext())
+                        {
+                            Principal p = (Principal) refs.userMap.get((String) _itTemp.next());
+                            if (p != null)
+                                pm.grantPermission(p, perm);
+                        }
+                    }
+
+                }
+                catch (Exception e)
+                {
+                    throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED
+                            .create(new String[] { "Permissions", e.getMessage() }));
+                }
+            }
+        }
+        log.debug("recreatePermissions - done");
+    }
+
+    private PortalResourcePermission getPermissionForType(JSPermission _js)
+    {
+        PortalResourcePermission newPermission = null; 
+        if ((_js.getType() == null) || (_js.getType() == JSPermission.TYPE_UNKNOWN))
+            return null;
+        try
+        {
+        if (_js.getType().equals(JSPermission.TYPE_FOLDER))
+            newPermission = new FolderPermission(_js.getResource(),_js.getActions());
+        else if (_js.getType().equals(JSPermission.TYPE_FRAGMENT))
+            newPermission = new FragmentPermission(_js.getResource(),_js.getActions());
+            else if (_js.getType().equals(JSPermission.TYPE_PAGE))
+                newPermission = new PagePermission(_js.getResource(),_js.getActions());
+                else if (_js.getType().equals(JSPermission.TYPE_PORTAL))
+                    newPermission = new PortletPermission(_js.getResource(),_js.getActions());
+                    else return null;
+            return newPermission;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return null;
+        }
+    }
+    
+    /**
+     * Establish whether incoming passwords are "clear" text or whether they are
+     * to be decoded. That however depends on whether the passwords were encoded
+     * with the current active provider or not.
+     * 
+     * @return
+     */
+    protected int compareCurrentSecurityProvider(JSSnapshot snapshot)
+    {
+        String _fileEncryption = snapshot.getEncryption();
+        if ((_fileEncryption == null) || (_fileEncryption.length() == 0))
+            return JetspeedSerializer.NO_DECODING; // passwords are in clear
+                                                    // text
+
+        if (_fileEncryption.equals(getEncryptionString()))
+            return JetspeedSerializer.PASSTHRU_REQUIRED;
+        else
+            return JetspeedSerializer.NO_DECODING;
+    }
+
+    private String getEncryptionString()
+    {
+        if (pcp == null)
+        {
+            System.err.println("Error!!! PasswordCredentialProvider not available");
+            return ENCODING_STRING;
+        }
+        try
+        {
+            PasswordCredential credential = pcp.create(JETSPEED, ENCODING_STRING);
+            if ((credential != null) && (credential.getPassword() != null))
+                return new String(credential.getPassword());
+            else
+                return ENCODING_STRING;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            return ENCODING_STRING;
+        }
+    }
+
+    protected String recreatePassword(char[] savedPassword)
+    {
+        if (savedPassword == null)
+            return null;
+        return new String(savedPassword);
+    }
+
+    private Principal getUserPrincipal(User user)
+    {
+        Subject subject = user.getSubject();
+        // get the user principal
+        Set principals = subject.getPrincipals();
+        Iterator list = principals.iterator();
+        while (list.hasNext())
+        {
+            BasePrincipal principal = (BasePrincipal) list.next();
+            String path = principal.getFullPath();
+            if (path.startsWith("/user/"))
+                return principal;
+        }
+        return null;
+    }
+
+    /**
+     * Collect all the roles, groups and users from the current environment.
+     * Include the current SecurityProvider to understand, whether the password
+     * collected can be used upon import
+     * 
+     * @throws SerializerException
+     */
+    private void exportRolesGroupsUsers(Refs refs, JSSnapshot snapshot, Map settings, Log log)
+            throws SerializerException
+    {
+        /** set the security provider info in the snapshot file */
+        snapshot.setEncryption(getEncryptionString());
+        /** get the roles */
+
+        Iterator list = null;
+        try
+        {
+            list = roleManager.getRoles("");
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "Role",
+                    e.getMessage() }));
+        }
+        while (list.hasNext())
+        {
+            try
+            {
+                Role role = (Role) list.next();
+                JSRole _tempRole = (JSRole) getObjectBehindPrinicpal(refs.roleMap,
+                        (BasePrincipal) (role.getPrincipal()));
+                if (_tempRole == null)
+                {
+                    _tempRole = createJSRole(role);
+                    refs.roleMap.put(_tempRole.getName(), _tempRole);
+                    snapshot.getRoles().add(_tempRole);
+                }
+
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "Role", e.getMessage() }));
+            }
+        }
+
+        /** get the groups */
+        try
+        {
+            list = groupManager.getGroups("");
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "Group",
+                    e.getMessage() }));
+        }
+        while (list.hasNext())
+        {
+
+            try
+            {
+                Group group = (Group) list.next();
+                JSGroup _tempGroup = (JSGroup) getObjectBehindPrinicpal(refs.groupMap, (BasePrincipal) (group
+                        .getPrincipal()));
+                if (_tempGroup == null)
+                {
+                    _tempGroup = createJSGroup(group);
+                    refs.groupMap.put(_tempGroup.getName(), _tempGroup);
+                    snapshot.getGroups().add(_tempGroup);
+                }
+
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "Group", e.getMessage() }));
+            }
+        }
+
+        /** users */
+        try
+        {
+            list = userManager.getUsers("");
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "User",
+                    e.getMessage() }));
+        }
+        while (list.hasNext())
+        {
+
+            try
+            {
+                User _user = (User) list.next();
+                JSUser _tempUser = createJSUser(refs, _user);
+                refs.userMap.put(_tempUser.getName(), _tempUser);
+                snapshot.getUsers().add(_tempUser);
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "User", e.getMessage() }));
+            }
+
+        }
+        return;
+
+    }
+
+    /**
+     * extract all permissions from the current environment
+     * 
+     * @throws SerializerException
+     */
+    private void exportPermissions(Refs refs, JSSnapshot snapshot, Map settings, Log log) throws SerializerException
+    {
+        Object o = null;
+
+        Iterator list = null;
+        try
+        {
+            list = pm.getPermissions().iterator();
+        }
+        catch (Exception e)
+        {
+            throw new SerializerException(SerializerException.GET_EXISTING_OBJECTS.create(new String[] { "Permissions",
+                    e.getMessage() }));
+        }
+
+        while (list.hasNext())
+        {
+            try
+            {
+                JSPermission _js = new JSPermission();
+
+                InternalPermission p = (InternalPermission) list.next();
+                _js.setResource(p.getName());
+                _js.setActions(p.getActions());
+                _js.setId(p.getPermissionId());
+                _js.setType(_js.getTypeForClass(p.getClassname()));
+
+                Iterator list2 = p.getPrincipals().iterator();
+                while (list2.hasNext())
+                {
+                    o = list2.next();
+                    InternalPrincipal principal = (InternalPrincipal) o;
+                    String path = principal.getFullPath();
+                    if (path.startsWith("/role/"))
+                    {
+                        JSRole _tempRole = (JSRole) this.getObjectBehindPath(refs.roleMap, removeFromString(path,
+                                "/role/"));
+                        if (_tempRole != null)
+                        {
+                            _js.addRole(_tempRole);
+                        }
+
+                    }
+                    else
+                    {
+                        if (path.startsWith("/group/"))
+                        {
+                            JSGroup _tempGroup = (JSGroup) this.getObjectBehindPath(refs.groupMap, removeFromString(
+                                    path, "/group/"));
+                            if (_tempGroup != null)
+                            {
+                                _js.addGroup(_tempGroup);
+                            }
+
+                        }
+                        else
+                        {
+                            if (path.startsWith("/user/"))
+                            {
+                                JSUser _tempUser = (JSUser) this.getObjectBehindPath(refs.userMap, removeFromString(
+                                        path, "/user/"));
+                                if (_tempUser != null)
+                                {
+                                    _js.addUser(_tempUser);
+                                }
+
+                            }
+
+                        }
+
+                    }
+                }
+                refs.permissionMap.put(_js.getType(), _js);
+                snapshot.getPermissions().add(_js);
+
+            }
+            catch (Exception e)
+            {
+                throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+                        "Permissions", e.getMessage() }));
+            }
+        }
+        return;
+
+    }
+
+    /**
+     * simple lookup for principal object from a map
+     * 
+     * @param map
+     * @param _fullPath
+     * @return
+     */
+
+    private Object getObjectBehindPrinicpal(Map map, BasePrincipal _principal)
+    {
+        return getObjectBehindPath(map, _principal.getFullPath());
+    }
+
+    /**
+     * simple lookup for object from a map
+     * 
+     * @param map
+     * @param _fullPath
+     * @return
+     */
+    protected final Object getObjectBehindPath(Map map, String _fullPath)
+    {
+        return map.get(_fullPath);
+    }
+
+    /**
+     * remove a given sequence from the beginning of a string
+     */
+    protected final String removeFromString(String base, String excess)
+    {
+        return base.replaceFirst(excess, "").trim();
+    }
+
+    /**
+     * create a serializable wrapper for role
+     * 
+     * @param role
+     * @return
+     */
+    private JSRole createJSRole(Role role)
+    {
+        JSRole _role = new JSRole();
+        _role.setName(role.getPrincipal().getName());
+        return _role;
+    }
+
+    /**
+     * create a wrapper JSGroup object
+     */
+    private JSGroup createJSGroup(Group group)
+    {
+        JSGroup _group = new JSGroup();
+        _group.setName(group.getPrincipal().getName());
+        return _group;
+    }
+
+    /**
+     * Add the credentials to the JSUser object.
+     * <p>
+     * If the credential provided is a PasswordCredential, userid and password
+     * are extracted and set explcitely
+     * 
+     * @param isPublic
+     *            public or private credential
+     * @param newUser
+     *            the JS user object reference
+     * @param credential
+     *            the credential object
+     */
+
+    private void addJSUserCredentials(boolean isPublic, JSUser newUser, Object credential)
+    {
+        if (credential == null)
+            return;
+        if (credential instanceof PasswordCredential)
+        {
+            PasswordCredential pw = (PasswordCredential) credential;
+            newUser.setUserCredential(pw.getUserName(), pw.getPassword(), pw.getExpirationDate(), pw.isEnabled(), pw
+                    .isExpired(), pw.isUpdateRequired());
+            return;
+        }
+        else if (isPublic)
+            newUser.addPublicCredential(credential);
+        else
+            newUser.addPrivateCredential(credential);
+    }
+
+    /**
+     * create a new JSUser object
+     * 
+     * @param user
+     * @return a new JSUser object
+     */
+    private JSUser createJSUser(Refs refs, User user)
+    {
+        JSUser _newUser = new JSUser();
+
+        Subject subject = user.getSubject();
+        // get the user principal
+        Set principals = subject.getPrincipals();
+        Iterator list = principals.iterator();
+        while (list.hasNext())
+        {
+            BasePrincipal principal = (BasePrincipal) list.next();
+            String path = principal.getFullPath();
+            if (path.startsWith("/role/"))
+            {
+                JSRole _tempRole = (JSRole) this.getObjectBehindPath(refs.roleMap, principal.getName());
+                if (_tempRole != null)
+                {
+                    _newUser.addRole(_tempRole);
+                }
+
+            }
+            else
+            {
+                if (path.startsWith("/group/"))
+                {
+                    JSGroup _tempGroup = (JSGroup) this.getObjectBehindPath(refs.groupMap, principal.getName());
+                    if (_tempGroup != null)
+                    {
+                        _newUser.addGroup(_tempGroup);
+                    }
+
+                }
+                else if (path.startsWith("/user/"))
+                    _newUser.setPrincipal(principal);
+
+            }
+
+        }
+        // System.out.println("User Public Credentials");
+        Set credentials = subject.getPublicCredentials();
+        list = credentials.iterator();
+        while (list.hasNext())
+        {
+            Object credential = list.next();
+            addJSUserCredentials(true, _newUser, credential);
+        }
+        // System.out.println("User Private Credentials");
+        credentials = subject.getPrivateCredentials();
+        list = credentials.iterator();
+        while (list.hasNext())
+        {
+            Object credential = list.next();
+            addJSUserCredentials(false, _newUser, credential);
+        }
+
+        Preferences preferences = user.getPreferences();
+        _newUser.setPreferences(preferences);
+        preferences = user.getUserAttributes();
+        _newUser.setUserInfo(preferences);
+        // TODO: HJB, fix preferences...userinfo doesn't return values in
+        // prefs_property_value (in fact preferences.keys() is []
+        return _newUser;
+    }
+}

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/branches/J2-M2-REDUX/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Apr 30 16:47:12 2007
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message