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.rGUI.server; 020 021import java.rmi.RemoteException; 022import java.rmi.server.ServerNotActiveException; 023import java.rmi.server.UnicastRemoteObject; 024import java.rmi.server.RemoteServer; 025 026import pt.ua.dicoogle.rGUI.interfaces.ILogin; 027 028import javax.rmi.ssl.SslRMIServerSocketFactory; 029import pt.ua.dicoogle.rGUI.MultihomeSslRMIClientSocketFactory; 030import pt.ua.dicoogle.rGUI.interfaces.IAdmin; 031import pt.ua.dicoogle.rGUI.interfaces.IUser; 032 033import pt.ua.dicoogle.server.users.User; 034import pt.ua.dicoogle.server.users.UserSessions; 035import pt.ua.dicoogle.server.users.UsersStruct; 036import pt.ua.dicoogle.server.users.UsersXML; 037 038/** 039 * Login of users and administrator 040 * 041 * @author Samuel Campos <samuelcampos@ua.pt> 042 */ 043@Deprecated 044public class Login implements ILogin { 045 046 private static Login instance = null; 047 048 private UsersStruct users; 049 private UserSessions sessions; 050 051 public static synchronized Login getInstance() { 052 if (instance == null) { 053 instance = new Login(); 054 } 055 056 return instance; 057 } 058 059 private Login() { 060 new UsersXML().getXML(); // read XML with users and set the UsersStruct object (singleton) 061 062 sessions = UserSessions.getInstance(); 063 users = UsersStruct.getInstance(); 064 } 065 066 /* 067 * Public remote interface methods 068 */ 069 @Override 070 public IAdmin LoginAdmin(String username, String passwordHash) throws RemoteException { 071 User user = users.getUser(username); 072 String adminHost = ""; 073 074 if (user != null && user.verifyPassword(passwordHash) && user.isAdmin()) { 075 076 try { 077 adminHost = RemoteServer.getClientHost(); 078 } catch (ServerNotActiveException ex){ } 079 080 if (sessions.adminLogin(user, adminHost) != -1) { 081 AdminFeatures admin = AdminFeatures.getInstance(); 082 admin.setUser(user); 083 return (IAdmin) UnicastRemoteObject.exportObject(admin, 0, new MultihomeSslRMIClientSocketFactory(), new SslRMIServerSocketFactory()); 084 } 085 else{ 086 return null; 087 } 088 } 089 090 sessions.loginFailed(username, adminHost, true); 091 return null; 092 } 093 094 @Override 095 public IUser LoginUser(String username, String passwordHash) throws RemoteException { 096 User user = users.getUser(username); 097 String userHost = ""; 098 099 try { 100 userHost = RemoteServer.getClientHost(); 101 } catch (ServerNotActiveException ex){ } 102 103 if (user != null && user.verifyPassword(passwordHash)){ 104 105 IUser userStub = null; 106 107 UserFeatures userF = new UserFeatures(user); 108 sessions.userLogin(user, userHost, userF); 109 110 userStub = (IUser) UnicastRemoteObject.exportObject(userF, 0, new MultihomeSslRMIClientSocketFactory(), new SslRMIServerSocketFactory()); 111 112 return userStub; 113 } 114 115 sessions.loginFailed(username, userHost, false); 116 117 return null; 118 } 119}