Ensure proper user authentication even when DB temporarily not available, log the user id when exception inside application user builder
@@ -26,6 +26,7 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.persistence.PersistenceException;
import javax.servlet.http.HttpServletRequest;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -135,6 +136,8 @@ public class HttpHeaderApplicationUserBuilder implements ApplicationUserBuilder
// Build the user in pieces.
ApplicationUser applicationUser = createNewApplicationUser();
+ try
+ {
buildUserId(applicationUser, headerMap, headerNames.get(HTTP_HEADER_USER_ID), headerNames.get(HTTP_HEADER_USER_ID_SUFFIX));
buildFirstName(applicationUser, headerMap, headerNames.get(HTTP_HEADER_FIRST_NAME));
buildLastName(applicationUser, headerMap, headerNames.get(HTTP_HEADER_LAST_NAME));
@@ -147,6 +150,13 @@ public class HttpHeaderApplicationUserBuilder implements ApplicationUserBuilder
{
buildRoles(applicationUser, headerMap, headerNames.get(HTTP_HEADER_ROLES));
}
+ }
+ catch (PersistenceException persistenceException)
+ {
+ LOGGER.error(String.format("Error building application user %s", applicationUser.getUserId()), persistenceException);
+ throw persistenceException;
+ }
+
LOGGER.debug("Application user created successfully: " + applicationUser);
