portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1101700 - /portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java
Date Wed, 11 May 2011 00:52:30 GMT
Author: ate
Date: Wed May 11 00:52:30 2011
New Revision: 1101700

URL: http://svn.apache.org/viewvc?rev=1101700&view=rev
Log:
JS2-1251: provide better control and logging feedback from DefaultJetspeedSecuritySynchronizer:
- additional synchronizer logger to allow logging to dedicated synchronizer logfile
- support for continue or abort on synchronization errors
- synchronizing feedback after configurable batch chunk size
- allow setting synchronizing state from extended implementations 

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java?rev=1101700&r1=1101699&r2=1101700&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.java
Wed May 11 00:52:30 2011
@@ -48,10 +48,13 @@ import org.apache.jetspeed.security.spi.
  */
 public class DefaultJetspeedSecuritySynchronizer implements JetspeedSecuritySynchronizer
 {
-    private static final Logger logger = LoggerFactory.getLogger(DefaultJetspeedSecuritySynchronizer.class);
+    protected static final Logger logger = LoggerFactory.getLogger(JetspeedSecuritySynchronizer.class);
+    protected static final Logger feedbackLogger = LoggerFactory.getLogger(DefaultJetspeedSecuritySynchronizer.class);
     
-    JetspeedPrincipalManagerProvider principalManagerProvider;
-    SecurityEntityManager securityEntityManager;
+    protected JetspeedPrincipalManagerProvider principalManagerProvider;
+    protected SecurityEntityManager securityEntityManager;
+    protected boolean abortOnError = true;
+    protected int feedbackAfterSyncCount = 500;
 
     /**
      * @param principalManagerProvider
@@ -62,24 +65,27 @@ public class DefaultJetspeedSecuritySync
         this.principalManagerProvider = principalManagerProvider;
         this.securityEntityManager = securityEntityManager;
     }
+    
+    public void setAbortOnError(boolean abort)
+    {
+        this.abortOnError = abort;
+    }
+    
+    public void setFeedbackAfterSyncCount(int count)
+    {
+        this.feedbackAfterSyncCount = count;
+    }
 
     public synchronized void synchronizeAll() throws SecurityException
     {
         setSynchronizing(true);
         try
         {
-            if (logger.isDebugEnabled())
-            {
-                logger.debug("Synchronizing all entities");
-            }
+            feedbackLogger.info("Synchronizing all entities");
             final Map<String,Set<String>> processing = new HashMap<String,Set<String>>();
             final Map<String,Map<String,String>> processed = new HashMap<String,Map<String,String>>();

-            for (String type : securityEntityManager.getSupportedEntityTypes())
+            for (final String type : securityEntityManager.getSupportedEntityTypes())
             {
-                if (logger.isDebugEnabled())
-                {
-                    logger.debug("Synchronizing all "+type+" entities");
-                }
                 BaseEntitySearchResultHandler handler = new BaseEntitySearchResultHandler()
                 {
                     @Override
@@ -87,6 +93,10 @@ public class DefaultJetspeedSecuritySync
                     {
                         try
                         {
+                            if (feedbackAfterSyncCount > 0 && index % feedbackAfterSyncCount
== 0)
+                            {
+                                feedbackLogger.info("Synchronizing {}s - processed: {}",
type, index);
+                            }
                             synchronizeEntity(entity, processing, processed);
                         }
                         catch (SecurityException e)
@@ -97,12 +107,16 @@ public class DefaultJetspeedSecuritySync
                         return true;
                     }
                 };
+                feedbackLogger.info("Synchronizing all {}s", type);
                 securityEntityManager.getAllEntities(type,handler);
                 if (handler.getFeedback() != null)
                 {
+                    feedbackLogger.error("Synchronizing {}s aborted. Processed: {}", type,
handler.getSize());
                     throw (SecurityException)handler.getFeedback();
                 }
+                feedbackLogger.info("Synchronizing {}s done. Processed: {}", type, handler.getSize());
             }
+            feedbackLogger.info("Synchronizing all entities done.");
         }
         finally
         {
@@ -110,7 +124,7 @@ public class DefaultJetspeedSecuritySync
         }
     }
 
-    public synchronized void synchronizePrincipalsByType(String type) throws SecurityException
+    public synchronized void synchronizePrincipalsByType(final String type) throws SecurityException
     {
         setSynchronizing(true);
         try
@@ -124,21 +138,35 @@ public class DefaultJetspeedSecuritySync
                 {
                     try
                     {
+                        if (feedbackAfterSyncCount > 0 && index % feedbackAfterSyncCount
== 0)
+                        {
+                            feedbackLogger.info("Synchronizing {}s - processed: {}", type,
index);
+                        }
                         synchronizeEntity(entity, processing, processed);
                     }
                     catch (SecurityException e)
                     {
-                        setFeedback(e);
-                        return false;
+                        if (abortOnError)
+                        {
+                            feedbackLogger.error("Failed to synchronize {}: {}", type, entity.getInternalId());
+                            setFeedback(e);
+                            return false;
+                        }
+                        feedbackLogger.warn("Failed to synchronize {}: {}", type, entity.getInternalId());
+                        logger.error("Failed to synchronize "+type+": "+entity, e);
+                        return true;
                     }
                     return true;
                 }
             };
+            feedbackLogger.info("Synchronizing {}s", type);
             securityEntityManager.getAllEntities(type, handler);
             if (handler.getFeedback() != null)
             {
+                feedbackLogger.error("Synchronizing {}s aborted. Processed: {}", type, handler.getSize());
                 throw (SecurityException)handler.getFeedback();
             }
+            feedbackLogger.info("Synchronizing {}s done. Processed: {}", type, handler.getSize());
         }
         finally
         {
@@ -151,10 +179,7 @@ public class DefaultJetspeedSecuritySync
         setSynchronizing(true);
         try
         {
-            if (logger.isDebugEnabled())
-            {
-                logger.debug("Synchronizing UserPrincipal("+name+")");
-            }
+            feedbackLogger.debug("Synchronizing UserPrincipal({})", name);
             Entity userEntity = securityEntityManager.getEntity(JetspeedPrincipalType.USER,
name);
             if (userEntity != null)
             {
@@ -184,10 +209,7 @@ public class DefaultJetspeedSecuritySync
             String principalName = processed.get(entity.getType()).get(entity.getId());
             return principalName != null ? getJetspeedPrincipal(entity.getType(),principalName)
: null;
         }
-        if (logger.isDebugEnabled())
-        {
-            logger.debug("Synchronizing entity "+entity.getType()+" id: "+entity.getId());
-        }
+        feedbackLogger.debug("Synchronizing entity {} id: {}",entity.getType(),entity.getId());
         // synchronize and collect Entity from relations first
         Set<JetspeedPrincipalAssociationReference> toAssociations = synchronizeEntityFromRelations(entity,
processing, processed);
         // create or update entity itself including all its from associations
@@ -287,7 +309,7 @@ public class DefaultJetspeedSecuritySync
         }
         else if (!principal.isMapped())
         {
-            logger.debug("Found "+principal.getType().getName()+" principal: "+principal.getName()+"
is not mapped therefore not synchronized!");
+            feedbackLogger.warn("Found {} principal: {} is not mapped therefore not synchronized!",
principal.getType().getName(),principal.getName());
             return null;
         }
         else
@@ -328,10 +350,7 @@ public class DefaultJetspeedSecuritySync
                         SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName());
                         if (principalAttr != null)
                         {
-                            if (logger.isDebugEnabled())
-                            {
-                                logger.debug("Removing attribute "+principalAttr.getName()+"
for principal "+principal.getName()+".");
-                            }
+                            feedbackLogger.debug("Removing attribute {} for principal {}",
principalAttr.getName(), principal.getName());
                             principalAttrs.removeAttribute(principalAttr.getName());
                             updated = true;
                         }
@@ -340,9 +359,10 @@ public class DefaultJetspeedSecuritySync
                 else if (syncAll)
                 {
                     SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(),
true);
-                    if (logger.isDebugEnabled())
+                    if (feedbackLogger.isDebugEnabled())
                     {
-                        logger.debug("Adding attribute "+principalAttr.getName()+" for principal
"+principal.getName()+". Value: "+attr.getValue());
+                        feedbackLogger.debug("Adding attribute {} for principal {}. Value:
{}", 
+                                             new String[] {principalAttr.getName(), principal.getName(),
attr.getValue()});
                     }
                     principalAttr.setStringValue(attr.getValue());
                     updated = true;
@@ -352,9 +372,10 @@ public class DefaultJetspeedSecuritySync
                     SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(),
true);
                     if (!StringUtils.equals(principalAttr.getStringValue(), attr.getValue()))
                     {
-                        if (logger.isDebugEnabled())
+                        if (feedbackLogger.isDebugEnabled())
                         {
-                            logger.debug("Updating attribute "+principalAttr.getName()+"
for principal "+principal.getName()+". Old value: "+(principalAttr.getStringValue())+" new
value: "+attr.getValue());
+                            feedbackLogger.debug("Attribute attribute {} for principal {}.
Old value: {}, new value: {}", 
+                                                 new String[] {principalAttr.getName(), principal.getName(),
(principalAttr.getStringValue()), attr.getValue()});
                         }
                         principalAttr.setStringValue(attr.getValue());
                         updated = true;
@@ -364,16 +385,10 @@ public class DefaultJetspeedSecuritySync
         }
         if (updated)
         {
-            if (logger.isDebugEnabled())
-            {
-                logger.debug("Storing attribute changes for principal "+principal.getName());
-            }
+            feedbackLogger.debug("Storing attribute changes for principal {}", principal.getName());
             principalManager.updatePrincipal(principal);
         }
-        if (logger.isDebugEnabled())
-        {
-            logger.debug("Synchronized entity "+entity.getType()+" id: "+entity.getId()+"
mapped attributes");
-        }
+        feedbackLogger.debug("Synchronized entity {} id: {} mapped attributes", entity.getType(),
entity.getId());
         return principal;
     }
 
@@ -387,7 +402,7 @@ public class DefaultJetspeedSecuritySync
         throw new SecurityException(SecurityException.UNKNOWN_PRINCIPAL_TYPE.create(principalType));
     }
 
-    private void setSynchronizing(boolean sync)
+    protected void setSynchronizing(boolean sync)
     {
         SynchronizationStateAccess.setSynchronizing(sync ? Boolean.TRUE : Boolean.FALSE);
     }



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