use of fr.univlorraine.ecandidat.services.security.SecurityUserCandidat in project esup-ecandidat by EsupPortail.
the class I18nController method initLanguageUI.
/**
* Initialise la langue lors de l'arrivée sur l'UI
*/
public void initLanguageUI(final Boolean forceToReloadMenu) {
/* Mise a jour de la langue */
String langue = cacheController.getLangueDefault().getCodLangue();
SecurityUserCandidat user = userController.getSecurityUserCandidat();
if (user != null && user.getCodLangue() != null) {
langue = getCodeLangueActive(user.getCodLangue());
}
if (langue != null) {
changeLangueUI(langue, forceToReloadMenu);
} else {
Langue langueDefault = cacheController.getLangueDefault();
if (langueDefault != null) {
changeLangueUI(langueDefault.getCodLangue(), forceToReloadMenu);
}
}
}
use of fr.univlorraine.ecandidat.services.security.SecurityUserCandidat in project esup-ecandidat by EsupPortail.
the class I18nController method changeLangueUI.
/**
* Change la langue de l'UI
*
* @param codeLangue
* le code langage de la locale
* @param forceToReloadMenu
* si le menu doit être forcé à être rechargé-->cas du candidat en
* connexion interne
* @return true si la langue a été& changée
*/
private Boolean changeLangueUI(final String codeLangue, final Boolean forceToReloadMenu) {
if (codeLangue == null || UI.getCurrent() == null) {
return false;
}
Locale locale = UI.getCurrent().getLocale();
if (forceToReloadMenu || locale == null || locale.getLanguage() == null || (codeLangue != null && !codeLangue.equals(locale.getLanguage()))) {
SecurityUserCandidat user = userController.getSecurityUserCandidat();
if (user != null) {
user.setCodLangue(codeLangue);
}
((MainUI) UI.getCurrent()).setLocale(new Locale(codeLangue));
((MainUI) UI.getCurrent()).configReconnectDialogMessages();
((MainUI) UI.getCurrent()).constructMainMenu();
return true;
}
return false;
}
use of fr.univlorraine.ecandidat.services.security.SecurityUserCandidat in project esup-ecandidat by EsupPortail.
the class UserController method constructSecurityUserCandidat.
/**
* Créer un user Candidat
* @param cptMin
* le compte a minima cree
* @param username
* le username
* @return le user connecte
*/
private SecurityUser constructSecurityUserCandidat(final String username, final CompteMinima cptMin) {
Integer idCptMin = null;
String noDossierOPI = null;
Boolean cptMinValid = false;
Boolean mailValid = false;
if (cptMin != null && campagneController.isCampagneActiveCandidat(cptMin.getCampagne())) {
idCptMin = cptMin.getIdCptMin();
noDossierOPI = cptMin.getNumDossierOpiCptMin();
cptMinValid = cptMin.getTemValidCptMin();
mailValid = cptMin.getTemValidMailCptMin();
final List<GrantedAuthority> authoritiesListe = new ArrayList<>();
final SimpleGrantedAuthority sga = new SimpleGrantedAuthority(ConstanteUtils.ROLE_CANDIDAT);
authoritiesListe.add(sga);
final Candidat candidat = cptMin.getCandidat();
String codLangue = null;
if (candidat != null) {
codLangue = candidat.getLangue().getCodLangue();
}
return new SecurityUserCandidat(username, getDisplayNameCandidat(cptMin), authoritiesListe, idCptMin, noDossierOPI, cptMinValid, mailValid, codLangue);
} else {
return new SecurityUser(username, username, new ArrayList<GrantedAuthority>());
}
}
use of fr.univlorraine.ecandidat.services.security.SecurityUserCandidat in project esup-ecandidat by EsupPortail.
the class UserController method alimenteSecurityUserCptMin.
/**
* Alimente la session pour un compte local
* @param cptMin
* le compte a minima a connecter
*/
public void alimenteSecurityUserCptMin(final CompteMinima cptMin) {
final SecurityUser user = (SecurityUser) getCurrentUser();
if (user != null) {
final List<GrantedAuthority> authoritiesListe = new ArrayList<>();
final SimpleGrantedAuthority sga = new SimpleGrantedAuthority(ConstanteUtils.ROLE_CANDIDAT);
authoritiesListe.add(sga);
final SecurityUserCandidat securityUserCandidat = new SecurityUserCandidat(user.getUsername(), user.getDisplayName(), authoritiesListe, cptMin.getIdCptMin(), cptMin.getNumDossierOpiCptMin(), cptMin.getTemValidCptMin(), cptMin.getTemValidMailCptMin(), null);
final UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(securityUserCandidat, securityUserCandidat.getUsername(), securityUserCandidat.getAuthorities());
final Authentication authentication = authenticationManagerCandidat.authenticate(authRequest);
final SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
UI.getCurrent().getSession().getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, context);
}
}
Aggregations