Package eu.scape_project.pw.idp.model

Examples of eu.scape_project.pw.idp.model.IdpUser


    @Test
    public void activateUser_actionTokenOK_userIsActivated_success() throws UserNotFoundException {
        // -- set up --
        EntityManager em = mock(EntityManager.class);
        IdpUser user = mock(IdpUser.class);
        when(em.find(IdpUser.class, user.getId())).thenReturn(user);
        userManager.setEntityManager(em);

        // -- test --
        userManager.activateUser(user);
View Full Code Here


    }

    @Test
    public void initiateResetPassword_success() {
        // -- set up --
        IdpUser user = mock(IdpUser.class);
        List<IdpUser> userList = new ArrayList<IdpUser>();
        userList.add(user);

        EntityManager em = mock(EntityManager.class);
        userManager.setEntityManager(em);
View Full Code Here

    @Test
    public void resetPassword_success() throws UserNotFoundException, CannotSendMailException {
        // -- set up --
        EntityManager em = mock(EntityManager.class);
        IdpUser user = mock(IdpUser.class);
        when(user.getPlainPassword()).thenReturn("password");
        when(em.find(IdpUser.class, user.getId())).thenReturn(user);
        userManager.setEntityManager(em);

        // -- test --
        userManager.resetPassword(user);
View Full Code Here

        when(query.setParameter(anyString(), anyObject())).thenReturn(parameterQuery);
        when(parameterQuery.getSingleResult()).thenThrow(new NoResultException());
        userManager.setEntityManager(em);

        // -- test --
        IdpUser submittedUser = new IdpUser();
        submittedUser.setFirstName("firstname");
        submittedUser.setFirstName("lastname");
        submittedUser.setEmail("email");
        submittedUser.setUsername("username");
        submittedUser.setPlainPassword("password");
        userManager.addUser(submittedUser);

        // -- assert --
        verify(em).persist(submittedUser);
        assertTrue(submittedUser.getActionToken().length() > 1);
        assertEquals("authenticated", submittedUser.getRoles().get(0).getRoleName());
    }
View Full Code Here

        authenticatedRole.setRoleName("authenticated");
        when(parameterQuery.getSingleResult()).thenReturn(authenticatedRole);
        userManager.setEntityManager(em);

        // -- test --
        IdpUser submittedUser = new IdpUser();
        submittedUser.setFirstName("firstname");
        submittedUser.setFirstName("lastname");
        submittedUser.setEmail("email");
        submittedUser.setUsername("username");
        submittedUser.setPlainPassword("password");
        userManager.addUser(submittedUser);

        // -- assert --
        verify(em).persist(submittedUser);
        assertTrue(submittedUser.getActionToken().length() > 1);
        assertEquals("authenticated", submittedUser.getRoles().get(0).getRoleName());
    }
View Full Code Here

     *            the user to activate
     * @throws UserNotFoundException
     *             if the user could not be found
     */
    public void activateUser(IdpUser user) throws UserNotFoundException {
        IdpUser foundUser = em.find(IdpUser.class, user.getId());
        if (foundUser == null) {
            log.error("Error activating user. User {} not found.", user.getUsername());
            throw new UserNotFoundException("Error activating user. User " + user.getUsername() + "not found.");
        }
        foundUser.setStatus(IdpUserState.ACTIVE);
        foundUser.setActionToken("");
        em.persist(foundUser);
        log.info("Activated user with username {}.", foundUser.getUsername());
    }
View Full Code Here

     */
    public void resetPassword(IdpUser user) throws UserNotFoundException {

        // We have to find the user because if we use em.merge(user)
        // user.plainPassword will be deleted (because it is transient).
        IdpUser foundUser = em.find(IdpUser.class, user.getId());
        if (foundUser == null) {
            log.error("Error resetting password. User not found {}.", user.getUsername());
            throw new UserNotFoundException("Error resetting password. User not found " + user.getUsername());
        }
        foundUser.setPlainPassword(user.getPlainPassword());
        foundUser.setActionToken("");
        foundUser.setStatus(IdpUserState.ACTIVE);
        em.persist(foundUser);

        log.info("Reset password for user " + user.getUsername());
    }
View Full Code Here

    /**
     * Initializes the instance for use.
     */
    @PostConstruct
    public void init() {
        user = new IdpUser();
        Configuration config = configurationLoader.load();

        reCaptcha = ReCaptchaFactory.newReCaptcha(config.getString("recaptcha.publickey"),
            config.getString("recaptcha.privatekey"), false);
        addUserSuccessful = false;
View Full Code Here

        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();
        String serverString = request.getServerName() + ":" + request.getServerPort();

        try {
            IdpUser user = userManager.getUserByIdentifier(userIdentifier);
            userManager.initiateResetPassword(user);
            userManager.sendPasswordResetMail(user, serverString);
            facesMessages
                .addInfo("A mail with password recovery information has been sent to the email address provided when you created the account.");
        } catch (UserNotFoundException e) {
View Full Code Here

            EntityManager em = emf.createEntityManager();

            TypedQuery<IdpUser> q = em.createQuery(
                "SELECT u FROM IdpUser u WHERE username = :username and status = :status", IdpUser.class);
            q.setParameter("username", userPrincipal.getName()).setParameter("status", IdpUserState.ACTIVE);
            IdpUser user = q.getSingleResult();

            for (String attributeKey : attributeKeys) {
                Object object = null;

                if (attributeKey.equals("username")) {
                    object = user.getUsername();
                } else if (attributeKey.equals("firstName")) {
                    object = user.getFirstName();
                } else if (attributeKey.equals("lastName")) {
                    object = user.getLastName();
                } else if (attributeKey.equals("email")) {
                    object = user.getEmail();
                }

                if (object != null) {
                    attributes.put(attributeKey, object);
                }
View Full Code Here

TOP

Related Classes of eu.scape_project.pw.idp.model.IdpUser

Copyright © 2018 www.massapicom. 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.