Search in sources :

Example 1 with SecurityUserCandidat

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);
        }
    }
}
Also used : SecurityUserCandidat(fr.univlorraine.ecandidat.services.security.SecurityUserCandidat) Langue(fr.univlorraine.ecandidat.entities.ecandidat.Langue)

Example 2 with SecurityUserCandidat

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;
}
Also used : Locale(java.util.Locale) MainUI(fr.univlorraine.ecandidat.MainUI) SecurityUserCandidat(fr.univlorraine.ecandidat.services.security.SecurityUserCandidat)

Example 3 with SecurityUserCandidat

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>());
    }
}
Also used : SecurityUserCandidat(fr.univlorraine.ecandidat.services.security.SecurityUserCandidat) Candidat(fr.univlorraine.ecandidat.entities.ecandidat.Candidat) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SecurityUserCandidat(fr.univlorraine.ecandidat.services.security.SecurityUserCandidat) SecurityUser(fr.univlorraine.ecandidat.services.security.SecurityUser) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ArrayList(java.util.ArrayList)

Example 4 with SecurityUserCandidat

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);
    }
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SecurityUserCandidat(fr.univlorraine.ecandidat.services.security.SecurityUserCandidat) SecurityUser(fr.univlorraine.ecandidat.services.security.SecurityUser) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ArrayList(java.util.ArrayList) SecurityContext(org.springframework.security.core.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

SecurityUserCandidat (fr.univlorraine.ecandidat.services.security.SecurityUserCandidat)4 SecurityUser (fr.univlorraine.ecandidat.services.security.SecurityUser)2 ArrayList (java.util.ArrayList)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 MainUI (fr.univlorraine.ecandidat.MainUI)1 Candidat (fr.univlorraine.ecandidat.entities.ecandidat.Candidat)1 Langue (fr.univlorraine.ecandidat.entities.ecandidat.Langue)1 Locale (java.util.Locale)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1