Line data Source code
1 : // Copyright (C) 2014 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.restapi.config; 16 : 17 : import static com.google.gerrit.common.data.GlobalCapability.FLUSH_CACHES; 18 : import static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER; 19 : 20 : import com.google.gerrit.extensions.annotations.RequiresAnyCapability; 21 : import com.google.gerrit.extensions.common.Input; 22 : import com.google.gerrit.extensions.restapi.AuthException; 23 : import com.google.gerrit.extensions.restapi.Response; 24 : import com.google.gerrit.extensions.restapi.RestModifyView; 25 : import com.google.gerrit.server.config.CacheResource; 26 : import com.google.gerrit.server.permissions.GlobalPermission; 27 : import com.google.gerrit.server.permissions.PermissionBackend; 28 : import com.google.gerrit.server.permissions.PermissionBackendException; 29 : import com.google.inject.Inject; 30 : import com.google.inject.Singleton; 31 : 32 : @RequiresAnyCapability({FLUSH_CACHES, MAINTAIN_SERVER}) 33 : @Singleton 34 : public class FlushCache implements RestModifyView<CacheResource, Input> { 35 : 36 : public static final String WEB_SESSIONS = "web_sessions"; 37 : 38 : private final PermissionBackend permissionBackend; 39 : 40 : @Inject 41 138 : public FlushCache(PermissionBackend permissionBackend) { 42 138 : this.permissionBackend = permissionBackend; 43 138 : } 44 : 45 : @Override 46 : public Response<String> apply(CacheResource rsrc, Input input) 47 : throws AuthException, PermissionBackendException { 48 1 : if (WEB_SESSIONS.equals(rsrc.getName())) { 49 1 : permissionBackend.currentUser().check(GlobalPermission.MAINTAIN_SERVER); 50 : } 51 : 52 1 : rsrc.getCache().invalidateAll(); 53 1 : return Response.ok(); 54 : } 55 : }