Fix Concurrent SSO requests fail with primary key violation
@@ -671,6 +671,7 @@ public class DefaultAuthenticationRequestHandler implements AuthenticationReques
String subject = context.getSequenceConfig().getAuthenticatedUser().getAuthenticatedSubjectIdentifier();
String inboundAuth = context.getCallerPath().substring(1);
int appId = context.getSequenceConfig().getApplicationConfig().getApplicationID();
+ int maxRetryTime = 3;
for (AuthenticatedIdPData authenticatedIdPData : context.getCurrentAuthenticatedIdPs().values()) {
AuthenticatedUser user = authenticatedIdPData.getUser();
@@ -695,14 +696,31 @@ public class DefaultAuthenticationRequestHandler implements AuthenticationReques
}
}
}
+ storeAppSessionData(sessionContextKey, subject, appId, inboundAuth, maxRetryTime);
+ }
+
+ /**
+ * Method to store app session data. If an error occurs, it tries maximum times and throws an error.
+ *
+ * @param sessionContextKey Context of the authenticated session.
+ * @param subject Username in application
+ * @param appId ID of the application.
+ * @param inboundAuth Protocol of authentication.
+ * @param maxRetryTime Protocol used in app.
+ * @throws UserSessionException If storing app session data fails.
+ */
+ private void storeAppSessionData(String sessionContextKey, String subject, int appId, String inboundAuth,
+ int maxRetryTime) throws UserSessionException {
+ for (int retryTimes = 0; retryTimes < maxRetryTime; ++retryTimes){
try {
- // AppId is the auto generated id for the applications and it should be a positive integer.
if (appId > 0) {
UserSessionStore.getInstance().storeAppSessionData(sessionContextKey, subject, appId, inboundAuth);
}
- } catch (DataAccessException e) {
- throw new UserSessionException("Error while storing Application session data in the database.", e);
+ return;
+ } catch (DataAccessException ignored) {
+ }
}
+ throw new UserSessionException("Error while storing Application session data in the database.");
}
/**
