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.core.auth;
020
021import org.junit.*;
022import pt.ua.dicoogle.server.users.HashService;
023import pt.ua.dicoogle.server.users.User;
024import pt.ua.dicoogle.server.users.UsersStruct;
025import pt.ua.dicoogle.server.users.UsersXML;
026import pt.ua.dicoogle.server.web.auth.Authentication;
027import pt.ua.dicoogle.server.web.auth.LoggedIn;
028
029import static org.junit.Assert.assertEquals;
030import static pt.ua.dicoogle.server.web.servlets.webui.WebUIServlet.camelize;
031
032/**
033 * Created by bastiao on 23/01/16.
034 */
035public class TestUsers {
036
037    @Test
038    @Ignore // needs isolation
039    public void testUsers() {
040
041        UsersStruct users = UsersStruct.getInstance();
042        UsersXML usersXML = new UsersXML();
043        users = usersXML.getXML();
044
045        String username = "nat";
046        boolean admin = false;
047        String passPlainText = "123";
048        String passHash = HashService.getSHA1Hash(passPlainText);             //password Hash
049        String hash = HashService.getSHA1Hash(username + admin + passHash);
050        System.out.println(hash);
051        System.out.println(passHash);
052        User u = new User("nat",hash, admin);
053        users.addUser(u);
054
055
056        for (String uu : users.getUsernames())
057        {
058            System.out.println(users.getUser(uu));
059        }
060
061        Authentication auth = Authentication.getInstance();
062        try {
063            LoggedIn loggedIn = auth.login("nat", "123");
064            System.out.println(loggedIn.getUserName());
065            System.out.println(loggedIn.isAdmin());
066        }
067        catch(Exception e)
068        {
069            System.out.println("Error in the test");
070        }
071
072    }
073
074}