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 12013b2 commit ddc7468
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@

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));
}

String setRoles(String roles) {
if (Log.isDebugEnabled()) {
try {
Log.debugv("Setting roles {0} on transaction {1}", roles, txManager.getTransaction());
} catch (SystemException e) {
Log.debugv("Setting roles {0}, but obtaining current transaction failed due to {1}", roles, e.getMessage());
}
}
Query setRoles = em.createNativeQuery(SET_ROLES);
setRoles.setParameter(1, roles == null ? "" : roles);
Object[] row = (Object[]) setRoles.getSingleResult();
Expand Down

0 comments on commit ddc7468

Please sign in to comment.