diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java index 252cb78..a8c666d 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java @@ -95,8 +95,9 @@ public class LoginController implements LoginApi { public ResponseEntity getUsername() { log.debug("Loading username for logged in user"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - + log.debug("Loaded authentication for logged in user {}", authentication); if (authentication == null || !(authentication.getPrincipal() instanceof OAuth2ResourceServerProperties.Jwt)) { + log.debug("Loaded authentication for logged in user is null or not a jwt"); return ResponseEntity.status(401).build(); } Jwt jwt = (Jwt) authentication.getPrincipal(); diff --git a/database/src/main/java/com/alttd/altitudeweb/setup/Connection.java b/database/src/main/java/com/alttd/altitudeweb/setup/Connection.java index c6057d8..b5f2eab 100644 --- a/database/src/main/java/com/alttd/altitudeweb/setup/Connection.java +++ b/database/src/main/java/com/alttd/altitudeweb/setup/Connection.java @@ -97,10 +97,20 @@ public class Connection { sqlSessionFactory = createSqlSessionFactory(settings, addMappers); } - try (SqlSession session = sqlSessionFactory.openSession()) { + SqlSession session = null; + try { + session = sqlSessionFactory.openSession(); consumer.accept(session); + session.commit(); } catch (Exception e) { + if (session != null) { + session.rollback(); + } log.error("Failed to run query", e); + } finally { + if (session != null) { + session.close(); + } } }).start(); }