|
2 | 2 |
|
3 | 3 | import java.util.ArrayList;
|
4 | 4 | import java.util.List;
|
| 5 | + |
| 6 | +import io.quarkus.logging.Log; |
5 | 7 | import jakarta.enterprise.context.ApplicationScoped;
|
6 | 8 | import jakarta.inject.Inject;
|
7 | 9 | import jakarta.persistence.EntityManager;
|
8 | 10 | import jakarta.persistence.Query;
|
9 | 11 |
|
10 | 12 | import io.quarkus.security.identity.SecurityIdentity;
|
| 13 | +import jakarta.transaction.SystemException; |
| 14 | +import jakarta.transaction.TransactionManager; |
11 | 15 |
|
12 | 16 | @ApplicationScoped
|
13 | 17 | public class RoleManager {
|
14 | 18 | static final String SET_ROLES = "SELECT current_setting('horreum.userroles', true), set_config('horreum.userroles', ?, false)";
|
15 | 19 | static final String SET_TOKEN = "SELECT set_config('horreum.token', ?, false)";
|
16 | 20 | static final CloseMe NOOP = () -> {};
|
17 | 21 |
|
18 |
| - @Inject |
19 |
| - EntityManager em; |
| 22 | + @Inject EntityManager em; |
| 23 | + |
| 24 | + @Inject TransactionManager txManager; |
20 | 25 |
|
21 | 26 | String setRoles(Iterable<String> roles) {
|
22 | 27 | return setRoles(String.join(",", roles));
|
23 | 28 | }
|
24 | 29 |
|
25 | 30 | String setRoles(String roles) {
|
| 31 | + if (Log.isDebugEnabled()) { // enabe with: `quarkus.log.category."io.hyperfoil.tools.horreum.server.RoleManager".level=DEBUG` |
| 32 | + try { |
| 33 | + Log.debugv("Setting roles {0} on transaction {1}", roles, txManager.getTransaction()); |
| 34 | + } catch (SystemException e) { |
| 35 | + Log.debugv("Setting roles {0}, but obtaining current transaction failed due to {1}", roles, e.getMessage()); |
| 36 | + } |
| 37 | + } |
26 | 38 | Query setRoles = em.createNativeQuery(SET_ROLES);
|
27 | 39 | setRoles.setParameter(1, roles == null ? "" : roles);
|
28 | 40 | Object[] row = (Object[]) setRoles.getSingleResult();
|
|
0 commit comments