hotfix: merge <<< HEAD ---- >>> SHA1 messages stood on the code somehow

This commit is contained in:
2025-11-14 19:55:18 +01:00
parent 3a194f2616
commit 18c2f0f00b
5 changed files with 23 additions and 43 deletions

View File

@@ -30,16 +30,26 @@ public abstract class AbstractAuthGuard<U, R extends Enum<R> & IUserRole> {
}
int userId = JWTManager.getInstance().extractUserId(token);
String roleStr = JWTManager.getInstance().extractRole(token);
R role;
try {
role = parseRole(roleStr);
} catch (Exception e) {
JsonUtil.sendJson(ctx, ApiStatus.UNAUTHORIZED, "Invalid role");
return;
}
ctx.put("userId", userId);
ctx.put("role", role);
getUserEntity(userId, ctx, entity -> {
if (entity == null) {
JsonUtil.sendJson(ctx, ApiStatus.UNAUTHORIZED, "User not found");
return;
}
R userRole = extractRoleFromEntity(entity);
if (allowedRoles.length == 0 || hasPermission(entity, userRole, allowedRoles)) {
if (allowedRoles.length == 0 || isRoleAllowed(role, allowedRoles)) {
ctx.put("userEntity", entity);
ctx.next();
} else {
@@ -49,18 +59,8 @@ public abstract class AbstractAuthGuard<U, R extends Enum<R> & IUserRole> {
};
}
<<<<<<< HEAD
protected boolean isRoleAllowed(R role, R... allowedRoles) {
for (R allowed : allowedRoles) {
if (role == allowed) return true;
=======
protected R extractRoleFromEntity(U user) {
try {
return (R) user.getClass().getMethod("getRole").invoke(user);
} catch (Exception e) {
return null;
>>>>>>> refs/remotes/origin/dev
}
for (R allowed : allowedRoles) if (role == allowed) return true; return false;
}
protected String extractToken(RoutingContext ctx) {