Search in sources :

Example 1 with URIPath

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

the class RequestHandler method buildRequest.

private Request buildRequest(HttpExchange exchange) {
    String requestMethod = exchange.getRequestMethod();
    URIPath path = new URIPath(exchange.getRequestURI().getPath());
    URIQuery query = new URIQuery(exchange.getRequestURI().getRawQuery());
    byte[] requestBody = readRequestBody(exchange);
    WebUser user = getWebUser(exchange);
    Map<String, String> headers = getRequestHeaders(exchange);
    return new Request(requestMethod, path, query, user, headers, requestBody);
}
Also used : URIPath(com.djrapitops.plan.delivery.web.resolver.request.URIPath) Request(com.djrapitops.plan.delivery.web.resolver.request.Request) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery)

Example 2 with URIPath

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

the class PlayerPageResolver method canAccess.

@Override
public boolean canAccess(Request request) {
    URIPath path = request.getPath();
    WebUser user = request.getUser().orElse(new WebUser(""));
    boolean isOwnPage = path.getPart(1).map(nameOrUUID -> {
        // name matches user
        if (user.getName().equalsIgnoreCase(nameOrUUID))
            return true;
        return // uuid matches user
        uuidUtility.getNameOf(nameOrUUID).map(user.getName()::equalsIgnoreCase).orElse(// uuid or name don't match
        false);
    }).orElse(// No name or UUID given
    true);
    return user.hasPermission("page.player.other") || user.hasPermission("page.player.self") && isOwnPage;
}
Also used : URIPath(com.djrapitops.plan.delivery.web.resolver.request.URIPath) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Request(com.djrapitops.plan.delivery.web.resolver.request.Request) Html(com.djrapitops.plan.delivery.rendering.html.Html) UUID(java.util.UUID) Singleton(javax.inject.Singleton) Response(com.djrapitops.plan.delivery.web.resolver.Response) StringUtils(org.apache.commons.lang3.StringUtils) ResponseFactory(com.djrapitops.plan.delivery.webserver.ResponseFactory) Inject(javax.inject.Inject) PluginSettings(com.djrapitops.plan.settings.config.paths.PluginSettings) Resolver(com.djrapitops.plan.delivery.web.resolver.Resolver) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) Optional(java.util.Optional) UUIDUtility(com.djrapitops.plan.identification.UUIDUtility) URIPath(com.djrapitops.plan.delivery.web.resolver.request.URIPath) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser)

Aggregations

Request (com.djrapitops.plan.delivery.web.resolver.request.Request)2 URIPath (com.djrapitops.plan.delivery.web.resolver.request.URIPath)2 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)2 Html (com.djrapitops.plan.delivery.rendering.html.Html)1 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)1 Response (com.djrapitops.plan.delivery.web.resolver.Response)1 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)1 ResponseFactory (com.djrapitops.plan.delivery.webserver.ResponseFactory)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 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 StringUtils (org.apache.commons.lang3.StringUtils)1