portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r726729 - in /portals/jetspeed-2/portal/trunk/components: jetspeed-security/src/main/java/org/apache/jetspeed/serializer/ jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/
Date Mon, 15 Dec 2008 16:28:28 GMT
Author: woonsan
Date: Mon Dec 15 08:28:27 2008
New Revision: 726729

URL: http://svn.apache.org/viewvc?rev=726729&view=rev
Log:
Improves to allow other principal types.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java?rev=726729&r1=726728&r2=726729&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
Mon Dec 15 08:28:27 2008
@@ -89,14 +89,19 @@
         
         public HashMap<String, Principal> getPrincipalMap(String principalTypeName)
         {
+            HashMap<String, Principal> principalMap = null;
+            
             if (principalMapByType.containsKey(principalTypeName))
             {
-                return principalMapByType.get(principalTypeName);
+                principalMap = principalMapByType.get(principalTypeName);
             }
             else
             {
-                return principalMapByType.put(principalTypeName, new HashMap<String, Principal>());
+                principalMap = new HashMap<String, Principal>();
+                principalMapByType.put(principalTypeName, principalMap);
             }
+            
+            return principalMap;
         }
     }
     
@@ -110,14 +115,19 @@
         
         public HashMap<String, JSPrincipal> getPrincipalMap(String principalTypeName)
         {
+            HashMap<String, JSPrincipal> jsPrincipalMap = null;
+            
             if (principalMapByType.containsKey(principalTypeName))
             {
-                return principalMapByType.get(principalTypeName);
+                jsPrincipalMap = principalMapByType.get(principalTypeName);
             }
             else
             {
-                return principalMapByType.put(principalTypeName, new HashMap<String, JSPrincipal>());
+                jsPrincipalMap = new HashMap<String, JSPrincipal>();
+                principalMapByType.put(principalTypeName, jsPrincipalMap);
             }
+            
+            return jsPrincipalMap;
         }
     }
 
@@ -313,6 +323,48 @@
         
         log.debug("recreateRoles - done");
         
+        log.debug("processing general principals");
+        
+        JetspeedPrincipalManager principalManager = null;
+        
+        for (JSPrincipal jsPrincipal : snapshot.getPrincipals())
+        {
+            String typeName = jsPrincipal.getType();
+            String name = jsPrincipal.getName();
+            
+            try
+            {
+                JetspeedPrincipalType type = this.principalManagerProvider.getPrincipalType(typeName);
+                principalManager = this.principalManagerProvider.getManager(type);
+                JetspeedPrincipal principal = null;
+                
+                if (!(principalManager.principalExists(name)))
+                {
+                    principal = principalManager.newPrincipal(name, jsPrincipal.isMapped());
+                    JSSecurityAttributes jsSecAttrs = jsPrincipal.getSecurityAttributes();
+                    if (jsSecAttrs != null)
+                    {
+                        for (JSNVPElement elem : jsSecAttrs.getValues())
+                        {
+                            principal.getSecurityAttributes().getAttribute(elem.getKey(),
true).setStringValue(elem.getValue());
+                        }
+                    }
+                    principalManager.addPrincipal(principal, null);
+                }
+                
+                principal = principalManager.getPrincipal(name);
+                refs.getPrincipalMap(typeName).put(name, principal);
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+                throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new
String[] { typeName,
+                        e.getMessage() }), e);
+            }
+        }
+        
+        log.debug("recreate general principals - done");
+        
         log.debug("processing users");
 
         /** determine whether passwords can be reconstructed or not */
@@ -781,6 +833,38 @@
                         "User", e.getMessage() }), e);
             }
         }
+        
+        for (Map.Entry<String, JetspeedPrincipalType> entry : this.principalManagerProvider.getPrincipalTypeMap().entrySet())
+        {
+            String typeName = entry.getKey();
+            
+            if (!JetspeedPrincipalType.USER.equals(typeName) && !JetspeedPrincipalType.GROUP.equals(typeName)
&& !JetspeedPrincipalType.ROLE.equals(typeName))
+            {
+                JetspeedPrincipalType type = this.principalManagerProvider.getPrincipalType(typeName);
+                JetspeedPrincipalManager principalManager = this.principalManagerProvider.getManager(type);
+                
+                for (JetspeedPrincipal principal : principalManager.getPrincipals(""))
+                {
+                    try
+                    {
+                        Map refsMap = refs.getPrincipalMap(typeName);
+                        JSPrincipal _tempPrincipal = (JSPrincipal) getObjectBehindPrinicpal(refsMap,
principal);
+                        if (_tempPrincipal == null)
+                        {
+                            _tempPrincipal = createJSPrincipal(principal);
+                            refsMap.put(_tempPrincipal.getName(), _tempPrincipal);
+                            snapshot.getPrincipals().add(_tempPrincipal);
+                        }
+    
+                    }
+                    catch (Exception e)
+                    {
+                        throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new
String[] {
+                                typeName, e.getMessage() }));
+                    }
+                }
+            }
+        }
     }
 
     private void exportJetspeedPrincipalAssociations(ExportRefs refs, JSSnapshot snapshot,
Map settings, Log log) throws SecurityException, SerializerException

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java?rev=726729&r1=726728&r2=726729&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
Mon Dec 15 08:28:27 2008
@@ -96,6 +96,7 @@
             try
             {
                 JSPrincipal p = (JSPrincipal) o;
+                p.setType(xml.getAttribute("type", ""));
                 p.setName(StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "")));
                 p.mapped = xml.getAttribute("mapped", false);
                 p.enabled = xml.getAttribute("enabled", false);

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java?rev=726729&r1=726728&r2=726729&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java
Mon Dec 15 08:28:27 2008
@@ -62,6 +62,8 @@
     
     private JSUsers oldUsers;
     
+    private JSPrincipals principals;
+    
     private JSPrincipalAssociations principalAssociations;
 
     private JSPermissions permissions;
@@ -97,6 +99,7 @@
         oldGroups = new JSGroups();
         users = new JSPrincipals(JetspeedPrincipalType.USER);
         oldUsers = new JSUsers();
+        principals = new JSPrincipals();
         principalAssociations = new JSPrincipalAssociations();
         permissions = new JSPermissions();
         rules = new JSProfilingRules();
@@ -294,6 +297,14 @@
         return oldUsers;
     }
     
+    /**
+     * @return Returns the jetspeed principals.
+     */
+    public JSPrincipals getPrincipals()
+    {
+        return principals;
+    }
+    
     public void setPrincipalAssociations(JSPrincipalAssociations principalAssociations)
     {
         this.principalAssociations = principalAssociations;
@@ -548,6 +559,10 @@
                 {
                     xml.add(g.getUsers());
                 }
+                if ( !g.getPrincipals().isEmpty() )
+                {
+                    xml.add(g.getPrincipals());
+                }
                 if ( !g.getPrincipalAssociations().isEmpty() )
                 {
                     xml.add(g.getPrincipalAssociations());
@@ -637,6 +652,10 @@
                         {
                             g.users = jsps;
                         }
+                        else if (principalType != null && !"".equals(principalType))
+                        {
+                            g.principals = jsps;
+                        }
                     }
                     else if (o1 instanceof JSPrincipalAssociations)
                         g.principalAssociations = (JSPrincipalAssociations) o1;



---------------------------------------------------------------------
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