Examples of Uzer


Examples of net.stinfoservices.pacifiq.server.model.Uzer

    }

    @Override
    @Transactional(readOnly = false)
    public Long saveUzer(UzerDTO dto, String oldPassword) throws Exception {
        Uzer uzer = uzerDAO.find(dto.getId());
        boolean passwordHasChanged = false;
        if (uzer == null) {
            uzer = new Uzer();
            // version 0 or 1 ? do use constant ?
            uzer.setVersion(0);
        } else {
            if (!uzer.getPassword().equals(dto.getPassword())) {
                passwordHasChanged = true;
                String oldPasswordEncrypted = EncryptionUtils.encrypt(EncryptionUtils.encrypt(oldPassword, MessageDigestAlgorithm.MD5),
                        MessageDigestAlgorithm.SHA_512);
                if (!uzer.getPassword().equals(oldPasswordEncrypted)) {
                    throw new CustomException(MessageFormat.format(
                            LocaleManager.getInstance(getSession()).getMessageResource(getClass()).getString("EXCEPTION_BAD_OLD_PASSWORD_FOR_USER"),
                            dto.getName()));
                }
            }
        }

        // before here, do save program link deletion...

        applyDiffUzer(uzer, dto);

        // Encrypts the user password before creating or changing it
        if (dto.getId() == null || passwordHasChanged) {
            uzer.setPassword(EncryptionUtils.encrypt(EncryptionUtils.encrypt(uzer.getPassword(), MessageDigestAlgorithm.MD5),
                    MessageDigestAlgorithm.SHA_512));
        }

        uzer = uzerDAO.save(uzer);

        // force program.programmanager, program.processmanager,
        // program.ecmmanager save
        List<Program> programsLinked = new ArrayList<Program>();
        if (uzer.getProgramsManaged() != null) {
            for (Program p : uzer.getProgramsManaged()) {
                programsLinked.add(p);
            }
        }
        if (uzer.getProcessesManaged() != null) {
            for (Program p : uzer.getProcessesManaged()) {
                programsLinked.add(p);
            }
        }
        if (uzer.getEcmManaged() != null) {
            for (Program p : uzer.getEcmManaged()) {
                programsLinked.add(p);
            }
        }
        List<Long> ids = new ArrayList<Long>();
        for (Program p : programsLinked) {
            if (!ids.contains(p.getId())) {
                programDAO.save(p);
                ids.add(p.getId());
            }
        }

        return uzer.getId();
    }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

        if (email == null) {
            return (null);
        }

        try {
            Uzer result = (Uzer) entityManager.createQuery("SELECT o FROM " + IModel.DATABASE_PRE + "Uzer o WHERE o.email = :email")
                    .setParameter("email", email).getSingleResult();

            return (result);
        } catch (Exception ex) {
            throw new CustomException(getClass(), "No user was found with the corresponding email address!", ex);
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

        if (email == null) {
            return (null);
        }

        try {
            Uzer result = (Uzer) entityManager
                    .createQuery(
                            "SELECT o FROM "
                                    + IModel.DATABASE_PRE
                                    + "Uzer o LEFT JOIN FETCH o.programsWithConsultationRights LEFT JOIN FETCH o.programsWithEditionRights LEFT JOIN FETCH o.profile WHERE o.email = :email")
                    .setParameter("email", email).getSingleResult();
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

        if (uzer == null) {
            return (null);
        }

        try {
            Uzer u = entityManager.merge(uzer);

            entityManager.persist(u);
            u = entityManager.find(Uzer.class, u.getId());
            LOGGER.info(MessageFormat.format(ResourceBundle.getBundle("system").getString("OBJECT_SAVED"), this.getClass().getSimpleName(),
                    u.getName()));

            return (u);
        } catch (Exception ex) {
            throw new CustomException(ex);
        }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

        if (uzer == null) {
            return;
        }

        try {
            Uzer nuzer = entityManager.merge(uzer);

            entityManager.remove(nuzer);
            LOGGER.info(MessageFormat.format(ResourceBundle.getBundle("system").getString("OBJECT_DELETED"), this.getClass().getSimpleName(),
                    nuzer.getName()));
        } catch (Exception ex) {
            throw new CustomException(ex);
        }
    }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

     * @return The logged user.
     * @throws Exception
     *             if an error occurs in the DAO while requesting the database.
     */
    private UzerDTO internalLogin(boolean encrypted, final String email, final String pwd) throws Exception {
        Uzer user = uzerDAO.findByEmailWithRightsAndProfile(email);

        if (user == null || pwd == null) {
            throw new CustomException(getClass(), LocaleManager.getInstance(getSession()).getMessageResource(getClass())
                    .getString("EXCEPTION_USERNAME_INVALID"), null);
        } else {
            String password = pwd;

            if (!encrypted) {
                password = EncryptionUtils.encrypt(EncryptionUtils.encrypt(password, MessageDigestAlgorithm.MD5), MessageDigestAlgorithm.SHA_512);
            }
            if (user.getPassword().equals(password)) {
                // security context
                final Collection<GrantedAuthority> authorities = getAuthorities(user);
                final User springUser = new User(email, password, authorities);
                final Authentication auth = new UsernamePasswordAuthenticationToken(springUser, password, authorities);
                final SecurityContext sc = new SecurityContextImpl();
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

     * @throws Exception
     */
    @Override
    public UzerDTO checkSessionValue(String encryptedEmail) throws Exception {
        List<Uzer> users = uzerDAO.findAll();
        Uzer user = null;

        for (Uzer u : users) {
            /**
             * see {@link net.stinfoservices.pacifiq.client.UserSession#setSession(String)}
             */
            // if (EncryptionUtils.matches(u.getEmail(), encryptedEmail, new MessageDigestAlgorithm[] {
            // EncryptionUtils.MessageDigestAlgorithm.SHA_512,
            // EncryptionUtils.MessageDigestAlgorithm.SHA_512 })) {
            if (EncryptionUtils.matches(u.getEmail(), encryptedEmail, EncryptionUtils.MessageDigestAlgorithm.NONE)) {
                user = u;

                break;
            }
        }
        if (user != null) {
            return (internalLogin(true, user.getEmail(), user.getPassword()));
        }

        return (null);
    }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

                    + "Profile p " + "where u.profile.id=p.id");
            for (Object o : q.getResultList()) {
                if (o instanceof Object[]) {
                    Object[] oo = (Object[]) o;
                    if (oo.length == 2 && oo[0] instanceof Uzer && oo[1] instanceof Profile) {
                        Uzer uzer = (Uzer) oo[0];
                        Profile profile = (Profile) oo[1];
                        result.add(new UzerProfile(uzer, profile));
                    }
                }
            }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

    @Test
    @DatabaseSetup(value = UPDATE_DATASET)
    @DatabaseTearDown(value = UPDATE_DATASET, type = DatabaseOperation.DELETE)
    @Override
    public void testFind() throws Exception {
        Uzer uzer = uzerDAO.find(1L);
        Uzer uzerc = new Uzer();
        Program program = new Program();
        Profile profile = new Profile();

        program.setId(1L);
        program.setName(PROGRAM_NAME);
        program.setVersion(1);
        profile.setId(1L);
        profile.setAdministrator(false);
        profile.setLicensesConsultation(false);
        profile.setLicensesEdition(false);
        profile.setProgramsConsultation(false);
        profile.setProgramsEdition(false);
        profile.setName(PROFILE_NAME);
        profile.setVersion(1);
        uzerc.setId(1L);
        uzerc.setEmail(UPDATED_USER_EMAIL);
        uzerc.setName(USER_NAME);
        uzerc.setFirstname(USER_FIRSTNAME);
        uzerc.setProfile(profile);
        uzerc.setVersion(2);
        assertNotNull(uzer);
        assertSame(2, uzer.getVersion());
        assertEquals(uzerc.getEmail(), uzer.getEmail());
        assertEquals(uzerc, uzer);
        assertNull(uzerDAO.find(2L));
        assertNull(uzerDAO.find(0L));
    }
View Full Code Here

Examples of net.stinfoservices.pacifiq.server.model.Uzer

    @DatabaseSetup(value = UPDATE_DATASET)
    @DatabaseTearDown(value = UPDATE_DATASET, type = DatabaseOperation.DELETE)
    @Override
    public void testFindAll() throws Exception {
        List<Uzer> uzers = uzerDAO.findAll();
        Uzer uzer = new Uzer();
        Program program = new Program();
        Profile profile = new Profile();

        program.setId(1L);
        program.setName(PROGRAM_NAME);
        program.setVersion(1);
        profile.setId(1L);
        profile.setAdministrator(false);
        profile.setLicensesConsultation(false);
        profile.setLicensesEdition(false);
        profile.setProgramsConsultation(false);
        profile.setProgramsEdition(false);
        profile.setName(PROFILE_NAME);
        profile.setVersion(1);
        uzer.setId(1L);
        uzer.setEmail(UPDATED_USER_EMAIL);
        uzer.setName(USER_NAME);
        uzer.setFirstname(USER_FIRSTNAME);
        uzer.setProfile(profile);
        uzer.setVersion(2);
        // We have to take into account the uzer used for authentication (in order to be able to request the DAOs)
        assertSame(2, uzers.size());
        assertNotNull(uzers.get(1));
        assertEquals(uzers.get(1), uzer);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.