You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by tr...@apache.org on 2015/10/02 20:10:27 UTC

svn commit: r1706459 - in /jackrabbit/oak/trunk/oak-auth-external/src: main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/ test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/

Author: tripod
Date: Fri Oct  2 18:10:27 2015
New Revision: 1706459

URL: http://svn.apache.org/viewvc?rev=1706459&view=rev
Log:
OAK-3311 Potential NPE in syncAllExternalUsers() aborts the process

Modified:
    jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImpl.java
    jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModuleTestBase.java

Modified: jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImpl.java?rev=1706459&r1=1706458&r2=1706459&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImpl.java (original)
+++ jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImpl.java Fri Oct  2 18:10:27 2015
@@ -159,9 +159,7 @@ public class SyncMBeanImpl implements Sy
                     SyncResult r = context.sync(userId);
                     systemSession.save();
                     result.add(getJSONString(r));
-                } catch (SyncException e) {
-                    log.warn("Error while syncing user {}", userId, e);
-                } catch (RepositoryException e) {
+                } catch (Exception e) {
                     log.warn("Error while syncing user {}", userId, e);
                 }
             }
@@ -186,9 +184,8 @@ public class SyncMBeanImpl implements Sy
                             SyncResult r = context.sync(id.getId());
                             systemSession.save();
                             list.add(getJSONString(r));
-                        } catch (SyncException e) {
-                            list.add(getJSONString(id, e));
-                        } catch (RepositoryException e) {
+                        } catch (Exception e) {
+                            log.error("Error while syncing user {}", id, e);
                             list.add(getJSONString(id, e));
                         }
                     }
@@ -224,9 +221,8 @@ public class SyncMBeanImpl implements Sy
                 } catch (ExternalIdentityException e) {
                     log.warn("error while fetching the external identity {}", externalId, e);
                     list.add(getJSONString(ref, e));
-                } catch (SyncException e) {
-                    list.add(getJSONString(ref, e));
-                } catch (RepositoryException e) {
+                } catch (Exception e) {
+                    log.error("Error while syncing user {}", ref, e);
                     list.add(getJSONString(ref, e));
                 }
             }
@@ -247,10 +243,18 @@ public class SyncMBeanImpl implements Sy
                     try {
                         SyncResult r = context.sync(user);
                         systemSession.save();
+                        if (r.getIdentity() == null) {
+                            r = new DefaultSyncResultImpl(
+                                    new DefaultSyncedIdentity(user.getId(), user.getExternalId(), false, -1),
+                                    SyncResult.Status.NO_SUCH_IDENTITY
+                            );
+                            log.warn("sync failed. {}", r.getIdentity());
+                        } else {
+                            log.info("synced {}", r.getIdentity());
+                        }
                         list.add(getJSONString(r));
-                    } catch (SyncException e) {
-                        list.add(getJSONString(user.getExternalId(), e));
-                    } catch (RepositoryException e) {
+                    } catch (Exception e) {
+                        log.error("Error while syncing user {}", user, e);
                         list.add(getJSONString(user.getExternalId(), e));
                     }
                 }
@@ -271,17 +275,19 @@ public class SyncMBeanImpl implements Sy
                 while (iter.hasNext()) {
                     SyncedIdentity id = iter.next();
                     if (isMyIDP(id)) {
-                        ExternalIdentityRef exIdRef = id.getExternalIdRef();
-                        ExternalIdentity extId = (exIdRef == null) ? null : idp.getIdentity(exIdRef);
-                        if (extId == null) {
-                            list.add(id.getId());
+                        try {
+                            ExternalIdentityRef ref = id.getExternalIdRef();
+                            ExternalIdentity extId = ref == null ? null : idp.getIdentity(ref);
+                            if (extId == null) {
+                                list.add(id.getId());
+                            }
+                        } catch (Exception e) {
+                            log.error("Error while fetching external identity {}", id, e);
                         }
                     }
                 }
             } catch (RepositoryException e) {
                 log.error("Error while listing orphaned users", e);
-            } catch (ExternalIdentityException e) {
-                log.error("Error while fetching external identity", e);
             }
             return list.toArray(new String[list.size()]);
         }
@@ -298,9 +304,7 @@ public class SyncMBeanImpl implements Sy
                     SyncResult r = context.sync(userId);
                     systemSession.save();
                     result.add(getJSONString(r));
-                } catch (SyncException e) {
-                    log.warn("Error while syncing user {}", userId, e);
-                } catch (RepositoryException e) {
+                } catch (Exception e) {
                     log.warn("Error while syncing user {}", userId, e);
                 }
             }

Modified: jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModuleTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModuleTestBase.java?rev=1706459&r1=1706458&r2=1706459&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModuleTestBase.java (original)
+++ jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModuleTestBase.java Fri Oct  2 18:10:27 2015
@@ -36,6 +36,7 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalIDPManagerImpl;
 import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalLoginModule;
 import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncManagerImpl;
+import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.jmx.SynchronizationMBean;
 import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.junit.After;
@@ -58,6 +59,10 @@ public abstract class ExternalLoginModul
 
     protected ExternalIdentityProvider idp;
 
+    protected SyncManager syncManager;
+
+    protected ExternalIdentityProviderManager idpManager;
+
     protected DefaultSyncConfig syncConfig;
 
     @Before
@@ -123,8 +128,10 @@ public abstract class ExternalLoginModul
 
         // register non-OSGi managers
         whiteboard = oak.getWhiteboard();
-        whiteboard.register(SyncManager.class, new SyncManagerImpl(whiteboard), Collections.emptyMap());
-        whiteboard.register(ExternalIdentityProviderManager.class, new ExternalIDPManagerImpl(whiteboard), Collections.emptyMap());
+        syncManager = new SyncManagerImpl(whiteboard);
+        whiteboard.register(SyncManager.class, syncManager, Collections.emptyMap());
+        idpManager = new ExternalIDPManagerImpl(whiteboard);
+        whiteboard.register(ExternalIdentityProviderManager.class, idpManager, Collections.emptyMap());
 
         return oak;
     }
@@ -133,6 +140,14 @@ public abstract class ExternalLoginModul
 
     protected abstract void destroyIDP(ExternalIdentityProvider idp);
 
+    protected SynchronizationMBean createMBean() {
+        // todo: how to retrieve JCR repository here? maybe we should base the sync mbean on oak directly.
+        // JackrabbitRepository repository =  null;
+        // return new SyncMBeanImpl(repository, syncManager, "default", idpManager, idp.getName());
+
+        throw new UnsupportedOperationException("creating the mbean is not supported yet.");
+    }
+
     protected void setSyncConfig(DefaultSyncConfig cfg) {
         if (syncHandlerReg != null) {
             syncHandlerReg.unregister();