001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle 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
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020package pt.ua.dicoogle.server.web.servlets.accounts;
021
022import java.io.IOException;
023import javax.servlet.ServletException;
024import javax.servlet.http.HttpServlet;
025import javax.servlet.http.HttpServletRequest;
026import javax.servlet.http.HttpServletResponse;
027import pt.ua.dicoogle.server.web.auth.Authentication;
028import pt.ua.dicoogle.server.web.auth.Session;
029import pt.ua.dicoogle.server.web.utils.ResponseUtil;
030
031/**
032 *
033 * @author Frederico Silva <fredericosilva@ua.pt>
034 */
035public class LogoutServlet extends HttpServlet{
036    
037    private static final String TOKEN_HEADERNAME = "Authorization";
038
039    @Deprecated
040    @Override
041    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
042        this.doPost(req, resp);
043    }
044
045    @Override
046    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
047        boolean logout = Session.logout(req);
048        String token = req.getHeader(TOKEN_HEADERNAME);
049        if (token != null && !token.equals("")) {
050            Authentication.getInstance().logout(token);
051        }
052        ResponseUtil.simpleResponse(resp,"success", logout);
053    }
054    
055}