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 */
019package pt.ua.dicoogle.server.web.auth;
020
021/**
022 * A wrapper for the LogggedIn objects that are used on webapps.
023 * Holds the LoggedIn object and a status of why the LoggedIn object has the current value.
024 *
025 * @author António Novo <antonio.novo@ua.pt>
026 */
027public class LoggedInStatus
028{
029        public static int S_NOINFORMATION = 0;
030        public static int S_INVALIDCREDENTIALS = 1;
031        public static int S_UNAUTHORIZEDACCESS = 2;
032        public static int S_ALREADYLOGGEDIN = 3;
033        public static int S_VALIDLOGIN = 4;
034
035        private LoggedIn login;
036        private int status;
037
038        public LoggedInStatus()
039        {
040                this.login = null;
041                this.status = S_NOINFORMATION;
042        }
043
044        public LoggedInStatus(LoggedIn login, int status)
045        {
046                this.login = login;
047                this.status = status;
048        }
049
050        /**
051         * @return the login
052         */
053        public LoggedIn getLogin()
054        {
055                return login;
056        }
057
058        /**
059         * @return the status
060         */
061        public int getStatus()
062        {
063                return status;
064        }
065
066        public boolean wasAlreadyLoggedIn()
067        {
068                return (status == S_ALREADYLOGGEDIN);
069        }
070
071        public boolean noInformationSupplied()
072        {
073                return (status == S_NOINFORMATION);
074        }
075
076        public boolean invalidCredentialsSupplied()
077        {
078                return (status == S_INVALIDCREDENTIALS);
079        }
080
081        public boolean loggedInSuccessfully()
082        {
083                return (status == S_VALIDLOGIN);
084        }
085
086        public boolean unAuthorizedAccess()
087        {
088                return (status == S_UNAUTHORIZEDACCESS);
089        }
090
091        public boolean isCurrentlyLoggedIn()
092        {
093                return (((status == S_ALREADYLOGGEDIN) || (status == S_VALIDLOGIN)) && (login != null));
094        }
095}