hotfix: merge <<< HEAD ---- >>> SHA1 messages stood on the code somehow
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user