Incluidas clases para permitir el login de diferentes tipos de usuaario.

* POJO para usuario logeado.
* Hash para claves de usuarios
* Métodos EJB para login
This commit is contained in:
mgarcianun
2019-12-06 00:18:20 +01:00
parent 96c514f8a5
commit 32ce0a7eb6
8 changed files with 218 additions and 14 deletions

View File

@@ -8,10 +8,17 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PrimaryHealthCareCenterTO;
import common.HashUtils;
import jpa.AdministratorJPA;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PatientJPA;
import jpa.PrimaryHealthCareCenterJPA;
import jpa.SpecialistDoctorJPA;
import managedbean.common.UserType;
/**
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
@@ -83,4 +90,44 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
return allCAPs;
}
public LoggedUserTO login(String id, String pwd) {
LoggedUserTO usr = null;
// First try to login as Admin
AdministratorJPA adm = entman.find(AdministratorJPA.class, id);
if (adm != null) {
usr = new LoggedUserTO(adm.getEmail(), "", adm.getPassword(), UserType.ADMINISTRADOR);
} else {
Integer iId = Integer.valueOf(id);
// Try to login Patient
PatientJPA pat = entman.find(PatientJPA.class, iId);
if (pat != null) {
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), UserType.PATIENT);
} else {
FamilyDoctorJPA fdoc = entman.find(FamilyDoctorJPA.class, iId);
if (fdoc != null) {
usr = new LoggedUserTO(fdoc.getId().toString(), fdoc.getName(), fdoc.getPassword(), UserType.FAMILY_DOCTOR);
} else {
SpecialistDoctorJPA sdoc = entman.find(SpecialistDoctorJPA.class, iId);
if (sdoc != null) {
usr = new LoggedUserTO(sdoc.getId().toString(), sdoc.getName(), sdoc.getPassword(), UserType.SPECIALIST_DOCTOR);
}
}
}
}
if (usr != null) {
// Comprobamos el password
if (usr.getPassword().equals(HashUtils.hashMD5(pwd)) == false) {
// Bad Password, devolvemos null!
usr = null;
}
}
return usr;
}
}