Skip to content

Commit

Permalink
Add debug log to RoleManager
Browse files Browse the repository at this point in the history
  • Loading branch information
barreiro committed Jun 19, 2024
1 parent a45eb45 commit 7e541d1
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import java.util.ArrayList;
import java.util.List;

import io.quarkus.logging.Log;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;

import io.quarkus.security.identity.SecurityIdentity;
import jakarta.transaction.SystemException;
import jakarta.transaction.TransactionManager;

@ApplicationScoped
public class RoleManager {
static final String SET_ROLES = "SELECT current_setting('horreum.userroles', true), set_config('horreum.userroles', ?, false)";
static final String SET_TOKEN = "SELECT set_config('horreum.token', ?, false)";
static final CloseMe NOOP = () -> {};

@Inject
EntityManager em;
@Inject EntityManager em;

@Inject TransactionManager txManager;

String setRoles(Iterable<String> roles) {
return setRoles(String.join(",", roles));
Expand All @@ -26,6 +31,14 @@ String setRoles(String roles) {
Query setRoles = em.createNativeQuery(SET_ROLES);
setRoles.setParameter(1, roles == null ? "" : roles);
Object[] row = (Object[]) setRoles.getSingleResult();

if (Log.isDebugEnabled()) { // enabe with: `quarkus.log.category."io.hyperfoil.tools.horreum.server.RoleManager".level=DEBUG`
try {
Log.debugv("Setting roles {0} (replacing {1}) on transaction {2}", roles, row[0], txManager.getTransaction());
} catch (SystemException e) {
Log.debugv("Setting roles {0} (replacing {1}), but obtaining current transaction failed due to {2}", roles, row[0], e.getMessage());
}
}
return (String) row[0];
}

Expand Down

0 comments on commit 7e541d1

Please sign in to comment.