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 2014/04/07 07:03:49 UTC
svn commit: r1585380 -
/jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java
Author: tripod
Date: Mon Apr 7 05:03:49 2014
New Revision: 1585380
URL: http://svn.apache.org/r1585380
Log:
OAK-1679 LdapLoginTestBase#testConcurrentLoginSameGroup fails if conflict handling is enabled
fixed by retrying user synchronization a couple of times.
Modified:
jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java
Modified: jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java?rev=1585380&r1=1585379&r2=1585380&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java (original)
+++ jackrabbit/oak/branches/1.0/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModule.java Mon Apr 7 05:03:49 2014
@@ -59,6 +59,9 @@ public class ExternalLoginModule extends
private static final Logger log = LoggerFactory.getLogger(ExternalLoginModule.class);
+ // todo: make configurable
+ private static final int MAX_SYNC_ATTEMPTS = 50;
+
/**
* Name of the parameter that configures the name of the external identity provider.
*/
@@ -283,32 +286,39 @@ public class ExternalLoginModule extends
* @throws SyncException if an error occurs
*/
private void syncUser(@Nonnull ExternalUser user) throws SyncException {
- SyncContext context = null;
- try {
- Root root = getRoot();
- if (root == null) {
- throw new SyncException("Cannot synchronize user. root == null");
- }
- UserManager userManager = getUserManager();
- if (userManager == null) {
- throw new SyncException("Cannot synchronize user. userManager == null");
- }
- DebugTimer timer = new DebugTimer();
- context = syncHandler.createContext(idp, userManager, root);
- context.sync(user);
- timer.mark("sync");
- root.commit();
- timer.mark("commit");
- if (log.isDebugEnabled()) {
- log.debug("syncUser({}) {}", user.getId(), timer.getString());
- }
- } catch (CommitFailedException e) {
- throw new SyncException("User synchronization failed during commit.", e);
- } finally {
- if (context != null) {
- context.close();
+ Root root = getRoot();
+ if (root == null) {
+ throw new SyncException("Cannot synchronize user. root == null");
+ }
+ UserManager userManager = getUserManager();
+ if (userManager == null) {
+ throw new SyncException("Cannot synchronize user. userManager == null");
+ }
+
+ int numAttempt = 0;
+ while (numAttempt++ < MAX_SYNC_ATTEMPTS) {
+ SyncContext context = null;
+ try {
+ DebugTimer timer = new DebugTimer();
+ context = syncHandler.createContext(idp, userManager, root);
+ context.sync(user);
+ timer.mark("sync");
+ root.commit();
+ timer.mark("commit");
+ if (log.isDebugEnabled()) {
+ log.debug("syncUser({}) {}", user.getId(), timer.getString());
+ }
+ return;
+ } catch (CommitFailedException e) {
+ log.warn("User synchronization failed during commit: {}. (attempt {}/{})", e.toString(), numAttempt, MAX_SYNC_ATTEMPTS);
+ root.refresh();
+ } finally {
+ if (context != null) {
+ context.close();
+ }
}
}
+ throw new SyncException("User synchronization failed during commit after " + MAX_SYNC_ATTEMPTS + " attempts");
}
/**