001package org.nuxeo.elasticsearch.http.readonly;
002
003/*
004 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
005 *
006 * All rights reserved. This program and the accompanying materials
007 * are made available under the terms of the GNU Lesser General Public License
008 * (LGPL) version 2.1 which accompanies this distribution, and is available at
009 * http://www.gnu.org/licenses/lgpl-2.1.html
010 *
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * Contributors:
017 *     Benoit Delbosc
018 */
019
020import javax.validation.constraints.NotNull;
021
022import org.nuxeo.ecm.core.api.NuxeoPrincipal;
023
024/**
025 * Rewrite a Document get request to add security.
026 *
027 * @since 7.3
028 */
029public class DocRequestFilter {
030    private final NuxeoPrincipal principal;
031
032    private final String indices;
033
034    private final String types;
035
036    private final String documentId;
037
038    private final String rawQuery;
039
040    public DocRequestFilter(NuxeoPrincipal principal, String indices, String types, String documentId, String rawQuery) {
041        this.principal = principal;
042        this.indices = indices;
043        this.types = types;
044        this.documentId = documentId;
045        this.rawQuery = rawQuery;
046    }
047
048    protected @NotNull String getUrl() {
049        String url = "/" + indices + "/" + types + "/" + documentId;
050        if (rawQuery != null) {
051            url += "?" + rawQuery;
052        }
053        return url;
054    }
055
056    @Override
057    public String toString() {
058        return "Get Doc url: " + getUrl() + " user: " + principal;
059    }
060
061    public String getCheckAccessUrl() {
062        return "/" + indices + "/" + types + "/" + documentId + "?fields=ecm:acl";
063    }
064}