@@ -0,0 +1,3314 @@
+/*-%0A * ========================LICENSE_START=================================%0A * restheart-security%0A * %25%25%0A * Copyright (C) 2018 - 2020 SoftInstigate%0A * %25%25%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A * %0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A * =========================LICENSE_END==================================%0A */%0Apackage org.restheart.security.plugins.interceptors;%0A%0Aimport org.restheart.exchange.MongoRequest;%0Aimport org.restheart.exchange.MongoResponse;%0Aimport org.restheart.graphql.GraphQLAppDeserializer;%0A%0Aimport static org.restheart.plugins.InterceptPoint.RESPONSE;%0A%0Aimport org.restheart.plugins.ConfigurationScope;%0Aimport org.restheart.plugins.InjectConfiguration;%0Aimport org.restheart.plugins.InjectMongoClient;%0Aimport org.restheart.plugins.MongoInterceptor;%0Aimport org.restheart.plugins.RegisterPlugin;%0Aimport org.restheart.utils.HttpStatus;%0A%0Aimport static org.restheart.plugins.security.TokenManager.ACCESS_CONTROL_EXPOSE_HEADERS;%0A%0Aimport java.util.Map;%0A%0Aimport com.mongodb.MongoClient;%0A%0A/**%0A * helper interceptor to add token headers to Access-Control-Expose-Headers to%0A * handle CORS request%0A *%0A * @author Andrea Di Cesare %3Candrea@softinstigate.com%3E%0A */%0A@RegisterPlugin(name=%22graphAppDefinitionChecker%22,%0A        description = %22checks the GraphQL Application Definition%22,%0A        interceptPoint = RESPONSE,%0A        enabledByDefault = true%0A)%0Apublic class GraphAppDefinitionChecker implements MongoInterceptor %7B%0A    private String db = null;%0A    private String coll = null;%0A    private MongoClient mclient = null;%0A%0A    @InjectMongoClient%0A    public void mc(MongoClient mclient) %7B%0A        this.mclient = mclient;%0A    %7D%0A%0A    @InjectConfiguration(scope = ConfigurationScope.ALL)%0A    public void conf(Map%3CString, Object%3E args) %7B%0A        args.get(%22plugins-args%22); //// find a graphql%0A%0A        this.db = %22restheart%22;%0A        this.coll = %22apps%22;%0A    %7D%0A%0A    @Override%0A    public void handle(MongoRequest request, MongoResponse response) throws Exception %7B%0A        var appDef = response.getDbOperationResult().getNewData();%0A%0A        try %7B%0A            if (GraphQLAppDeserializer.fromBsonDocument(appDef) == null) %7B%0A                response.rollback(this.mclient);%0A                response.setStatusCode(HttpStatus.SC_BAD_REQUEST);%0A            %7D%0A        %7D catch(Throwable t) %7B%0A            response.rollback(this.mclient);%0A            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public boolean resolve(MongoRequest request, MongoResponse response) %7B%0A        return this.db.equals(request.getDBName())%0A            && this.coll.equals(request.getCollectionName())%0A            && response.getDbOperationResult() != null%0A            && response.getDbOperationResult().getNewData() != null;%0A    %7D%0A%7D%0A

Add GraphAppDefinitionChecker