Line data Source code
1 : // Copyright (C) 2015 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.httpd.auth.oauth; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.extensions.registration.DynamicItem; 19 : import com.google.gerrit.httpd.HttpLogoutServlet; 20 : import com.google.gerrit.httpd.WebSession; 21 : import com.google.gerrit.server.config.AuthConfig; 22 : import com.google.gerrit.server.config.CanonicalWebUrl; 23 : import com.google.gerrit.server.group.GroupAuditService; 24 : import com.google.inject.Inject; 25 : import com.google.inject.Provider; 26 : import com.google.inject.Singleton; 27 : import java.io.IOException; 28 : import javax.servlet.http.HttpServletRequest; 29 : import javax.servlet.http.HttpServletResponse; 30 : 31 : @Singleton 32 : class OAuthLogoutServlet extends HttpLogoutServlet { 33 : private static final long serialVersionUID = 1L; 34 : 35 : private final Provider<OAuthSession> oauthSession; 36 : 37 : @Inject 38 : OAuthLogoutServlet( 39 : AuthConfig authConfig, 40 : DynamicItem<WebSession> webSession, 41 : @CanonicalWebUrl @Nullable Provider<String> urlProvider, 42 : GroupAuditService audit, 43 : Provider<OAuthSession> oauthSession) { 44 0 : super(authConfig, webSession, urlProvider, audit); 45 0 : this.oauthSession = oauthSession; 46 0 : } 47 : 48 : @Override 49 : protected void doLogout(HttpServletRequest req, HttpServletResponse rsp) throws IOException { 50 0 : super.doLogout(req, rsp); 51 0 : if (req.getSession(false) != null) { 52 0 : oauthSession.get().logout(); 53 : } 54 0 : } 55 : }