Add session rollback handling in Connection.java, improve resource management, and refine debug logging in LoginController.
This commit is contained in:
parent
d73f057596
commit
56f4ccf40e
|
|
@ -95,8 +95,9 @@ public class LoginController implements LoginApi {
|
||||||
public ResponseEntity<UsernameDto> getUsername() {
|
public ResponseEntity<UsernameDto> getUsername() {
|
||||||
log.debug("Loading username for logged in user");
|
log.debug("Loading username for logged in user");
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
log.debug("Loaded authentication for logged in user {}", authentication);
|
||||||
if (authentication == null || !(authentication.getPrincipal() instanceof OAuth2ResourceServerProperties.Jwt)) {
|
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();
|
return ResponseEntity.status(401).build();
|
||||||
}
|
}
|
||||||
Jwt jwt = (Jwt) authentication.getPrincipal();
|
Jwt jwt = (Jwt) authentication.getPrincipal();
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,20 @@ public class Connection {
|
||||||
sqlSessionFactory = createSqlSessionFactory(settings, addMappers);
|
sqlSessionFactory = createSqlSessionFactory(settings, addMappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (SqlSession session = sqlSessionFactory.openSession()) {
|
SqlSession session = null;
|
||||||
|
try {
|
||||||
|
session = sqlSessionFactory.openSession();
|
||||||
consumer.accept(session);
|
consumer.accept(session);
|
||||||
|
session.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (session != null) {
|
||||||
|
session.rollback();
|
||||||
|
}
|
||||||
log.error("Failed to run query", e);
|
log.error("Failed to run query", e);
|
||||||
|
} finally {
|
||||||
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user