diff --git a/src/main/java/net/frozenorb/apiv3/actor/actors/UserActor.java b/src/main/java/net/frozenorb/apiv3/actor/actors/UserActor.java index 49dd451..0d40b1d 100644 --- a/src/main/java/net/frozenorb/apiv3/actor/actors/UserActor.java +++ b/src/main/java/net/frozenorb/apiv3/actor/actors/UserActor.java @@ -9,26 +9,16 @@ import net.frozenorb.apiv3.unsorted.Permissions; public final class UserActor implements Actor { @Getter private final User user; - // We use Boolean here so we can have null = not calculated; - // 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; + private boolean authorized; - public UserActor(User user) { + public UserActor(User user, boolean authorized) { this.user = user; + this.authorized = authorized; } @Override public boolean isAuthorized() { - if (cachedAuthorized != null) { - return cachedAuthorized; - } else { - // TODO: THIS IS KINDA BLOCKING - boolean authorized = user.hasPermissionAnywhere(Permissions.SIGN_API_REQUEST); - cachedAuthorized = authorized; - return authorized; - } + return authorized; } @Override diff --git a/src/main/java/net/frozenorb/apiv3/handler/ActorAttributeHandler.java b/src/main/java/net/frozenorb/apiv3/handler/ActorAttributeHandler.java index cf5a30d..31e3dae 100644 --- a/src/main/java/net/frozenorb/apiv3/handler/ActorAttributeHandler.java +++ b/src/main/java/net/frozenorb/apiv3/handler/ActorAttributeHandler.java @@ -7,6 +7,7 @@ import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.actor.actors.*; import net.frozenorb.apiv3.model.Server; import net.frozenorb.apiv3.model.User; +import net.frozenorb.apiv3.unsorted.Permissions; import net.frozenorb.apiv3.util.ErrorUtils; import java.util.Base64; @@ -47,7 +48,7 @@ public final class ActorAttributeHandler implements Handler { } 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(); } else { ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + username + ".");