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 ));
@@ -26,6 +31,14 @@ String setRoles(String roles) {
26
31
Query setRoles = em .createNativeQuery (SET_ROLES );
27
32
setRoles .setParameter (1 , roles == null ? "" : roles );
28
33
Object [] row = (Object []) setRoles .getSingleResult ();
34
+
35
+ if (Log .isDebugEnabled ()) { // enabe with: `quarkus.log.category."io.hyperfoil.tools.horreum.server.RoleManager".level=DEBUG`
36
+ try {
37
+ Log .debugv ("Setting roles {0} (replacing {1}) on transaction {2}" , roles , row [0 ], txManager .getTransaction ());
38
+ } catch (SystemException e ) {
39
+ Log .debugv ("Setting roles {0} (replacing {1}), but obtaining current transaction failed due to {2}" , roles , row [0 ], e .getMessage ());
40
+ }
41
+ }
29
42
return (String ) row [0 ];
30
43
}
31
44
0 commit comments