Search in sources :

Example 6 with WebUser

use of com.djrapitops.plan.delivery.web.resolver.request.WebUser in project Plan by plan-player-analytics.

the class ServerPageResolver method canAccess.

@Override
public boolean canAccess(Request request) {
    String firstPart = request.getPath().getPart(0).orElse("");
    WebUser permissions = request.getUser().orElse(new WebUser(""));
    boolean forServerPage = "server".equalsIgnoreCase(firstPart) && permissions.hasPermission("page.server");
    boolean forNetworkPage = "network".equalsIgnoreCase(firstPart) && permissions.hasPermission("page.network");
    return forServerPage || forNetworkPage;
}
Also used : WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser)

Example 7 with WebUser

use of com.djrapitops.plan.delivery.web.resolver.request.WebUser in project Plan by plan-player-analytics.

the class UserJSONResolver method getResponse.

private Response getResponse(Request request) {
    if (!webServer.get().isAuthRequired()) {
        return Response.builder().setStatus(404).setJSONContent("{}").build();
    }
    WebUser user = request.getUser().orElseThrow(() -> new WebUserAuthException(FailReason.NO_USER_PRESENT));
    Map<String, Object> json = new HashMap<>();
    json.put("username", user.getUsername());
    json.put("linkedTo", user.getName());
    json.put("permissions", user.getPermissions());
    return Response.builder().setJSONContent(json).build();
}
Also used : HashMap(java.util.HashMap) WebUserAuthException(com.djrapitops.plan.exceptions.WebUserAuthException) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser)

Aggregations

WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)7 WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)3 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)2 URIPath (com.djrapitops.plan.delivery.web.resolver.request.URIPath)2 UUID (java.util.UUID)2 Html (com.djrapitops.plan.delivery.rendering.html.Html)1 NoAuthResolver (com.djrapitops.plan.delivery.web.resolver.NoAuthResolver)1 BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)1 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)1 ResponseFactory (com.djrapitops.plan.delivery.webserver.ResponseFactory)1 WebServer (com.djrapitops.plan.delivery.webserver.WebServer)1 RootJSONResolver (com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver)1 Server (com.djrapitops.plan.identification.Server)1 UUIDUtility (com.djrapitops.plan.identification.UUIDUtility)1 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)1 PluginSettings (com.djrapitops.plan.settings.config.paths.PluginSettings)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1