Search in sources :

Example 6 with WebUserAuthException

use of com.djrapitops.plan.exceptions.WebUserAuthException 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

WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)6 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)3 User (com.djrapitops.plan.delivery.domain.auth.User)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 NoAuthResolver (com.djrapitops.plan.delivery.web.resolver.NoAuthResolver)1 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)1 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)1 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)1 WebServer (com.djrapitops.plan.delivery.webserver.WebServer)1 RootJSONResolver (com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver)1 PassEncryptException (com.djrapitops.plan.exceptions.PassEncryptException)1 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 Server (com.djrapitops.plan.identification.Server)1 Database (com.djrapitops.plan.storage.database.Database)1 HashMap (java.util.HashMap)1