Move permissions check from UserActor to ActorAttributeHandler to make the async conversion easier
This commit is contained in:
parent
fddb61b00e
commit
a0188e2d8c
@ -9,26 +9,16 @@ import net.frozenorb.apiv3.unsorted.Permissions;
|
|||||||
public final class UserActor implements Actor {
|
public final class UserActor implements Actor {
|
||||||
|
|
||||||
@Getter private final User user;
|
@Getter private final User user;
|
||||||
// We use Boolean here so we can have null = not calculated;
|
private boolean authorized;
|
||||||
// Currently having this cached isn't important as we only check
|
|
||||||
// this once, but later on when we have non-logged in routes
|
|
||||||
// this will be important.
|
|
||||||
private Boolean cachedAuthorized = null;
|
|
||||||
|
|
||||||
public UserActor(User user) {
|
public UserActor(User user, boolean authorized) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.authorized = authorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthorized() {
|
public boolean isAuthorized() {
|
||||||
if (cachedAuthorized != null) {
|
return authorized;
|
||||||
return cachedAuthorized;
|
|
||||||
} else {
|
|
||||||
// TODO: THIS IS KINDA BLOCKING
|
|
||||||
boolean authorized = user.hasPermissionAnywhere(Permissions.SIGN_API_REQUEST);
|
|
||||||
cachedAuthorized = authorized;
|
|
||||||
return authorized;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ import net.frozenorb.apiv3.APIv3;
|
|||||||
import net.frozenorb.apiv3.actor.actors.*;
|
import net.frozenorb.apiv3.actor.actors.*;
|
||||||
import net.frozenorb.apiv3.model.Server;
|
import net.frozenorb.apiv3.model.Server;
|
||||||
import net.frozenorb.apiv3.model.User;
|
import net.frozenorb.apiv3.model.User;
|
||||||
|
import net.frozenorb.apiv3.unsorted.Permissions;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -47,7 +48,7 @@ public final class ActorAttributeHandler implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user != null && user.checkPassword(password)) {
|
if (user != null && user.checkPassword(password)) {
|
||||||
ctx.put("actor", new UserActor(user));
|
ctx.put("actor", new UserActor(user, user.hasPermissionAnywhere(Permissions.SIGN_API_REQUEST))); // TODO: BLOCKING
|
||||||
ctx.next();
|
ctx.next();
|
||||||
} else {
|
} else {
|
||||||
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + username + ".");
|
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + username + ".");
|
||||||
|
Loading…
Reference in New Issue
Block a user