Package org.jamesdbloom.domain

Examples of org.jamesdbloom.domain.User


    public void setupFixture() throws Exception {
        mockMvc = webAppContextSetup(webApplicationContext)
                .addFilters(springSecurityFilter)
                .alwaysDo(print()).build();

        user = new User(uuid, "user", "user@email.com", passwordEncoder.encode("password"));
        userDAO.save(user);
        csrfToken = (CsrfToken) mockMvc.perform(get("/").secure(true).session(session)).andReturn().getRequest().getAttribute("_csrf");
    }
View Full Code Here


                // then
                .andExpect(redirectedUrl("/message"))
                .andExpect(flash().attributeExists("message"))
                .andExpect(flash().attribute("title", "Password Updated"));

        User actualUser = userDAO.findByEmail(expectedUser.getEmail());
        assertTrue(passwordEncoder.matches("NewPassword123", actualUser.getPassword()));
    }
View Full Code Here

    @Test
    public void shouldSendRegistrationEmail() throws Exception {
        // given
        String token = "token";
        String email = "to@email.com";
        User user = new User()
                .withEmail(email)
                .withOneTimeToken(token);

        String hostName = "hostName";
        int port = 666;
View Full Code Here

    @Test
    public void shouldSendUpdatePasswordEmail() throws Exception {
        // given
        String token = "token";
        String email = "to@email.com";
        User user = new User()
                .withEmail(email)
                .withOneTimeToken(token);

        String hostName = "hostName";
        int port = 666;
View Full Code Here

        HttpServletRequest request = mock(HttpServletRequest.class);
        when(request.getHeader("Host")).thenReturn(hostName);
        when(request.getLocalPort()).thenReturn(port);

        // when
        URL actual = emailService.createUrl(new User().withEmail("to@email.com").withOneTimeToken("token"), request);

        // then
        assertEquals("https://" + hostName + ":" + port + "/updatePassword?email=to%40email.com&oneTimeToken=token", actual.toString());
    }
View Full Code Here

        HttpServletRequest request = mock(HttpServletRequest.class);
        when(request.getHeader("Host")).thenReturn(hostName);
        when(request.getLocalPort()).thenReturn(666);

        // when
        URL actual = emailService.createUrl(new User().withEmail("to@email.com").withOneTimeToken("token"), request);

        // then
        assertEquals("https://" + hostName + "/updatePassword?email=to%40email.com&oneTimeToken=token", actual.toString());
    }
View Full Code Here

    }

    @Transactional
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    public String updatePassword(String email, String password, String passwordConfirm, String oneTimeToken, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) throws UnsupportedEncodingException {
        User user = userDAO.findByEmail(email);
        if (hasInvalidToken(user, oneTimeToken, request, redirectAttributes)) {
            return "redirect:/message";
        }
        boolean passwordFormatError = !PASSWORD_MATCHER.matcher(String.valueOf(password)).matches();
        boolean passwordsMatchError = !String.valueOf(password).equals(passwordConfirm);
        if (passwordFormatError || passwordsMatchError) {
            model.addAttribute("passwordPattern", User.PASSWORD_PATTERN);
            model.addAttribute("environment", environment);
            model.addAttribute("email", email);
            model.addAttribute("oneTimeToken", oneTimeToken);
            List<String> errors = new ArrayList<>();
            if (passwordFormatError) {
                errors.add("validation.user.password");
            }
            if (passwordsMatchError) {
                errors.add("validation.user.passwordNonMatching");
            }
            model.addAttribute("validationErrors", errors);
            logger.info("Validation error while trying to update password for " + email + "\n" + errors);
            return "updatePassword";
        }
        user.setPassword(passwordEncoder.encode(password));
        userDAO.save(user);

        redirectAttributes.addFlashAttribute("message", "Your password has been updated");
        redirectAttributes.addFlashAttribute("title", "Password Updated");
        logger.info("Password updated for " + email);
View Full Code Here

    }

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String registerForm(HttpServletRequest request, Model model) {
        setupModel(model);
        model.addAttribute("user", new User());
        CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
        if (csrfToken != null) {
            model.addAttribute("csrfParameterName", csrfToken.getParameterName());
            model.addAttribute("csrfToken", csrfToken.getToken());
        }
View Full Code Here

    private SpringSecurityUserContext springSecurityUserContext;

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
        User user;
        if (token.getPrincipal() instanceof User) {
            user = (User) token.getPrincipal();
        } else {
            user = credentialValidation.validateUsernameAndPassword(token.getName(), (CharSequence) token.getCredentials());
        }
        springSecurityUserContext.setCurrentUser(user);
        return new UsernamePasswordAuthenticationToken(user, user.getPassword(), AuthorityUtils.createAuthorityList("USER"));
    }
View Full Code Here

    private UserDAO userDAO;
    @Resource
    private Environment environment;

    public User validateUsernameAndPassword(String username, CharSequence password) {
        User user = userDAO.findByEmail(decodeURL(username));
        if (!credentialsMatch(password, user)) {
            logger.info(environment.getProperty("validation.user.invalidCredentials"));
            throw new BadCredentialsException(environment.getProperty("validation.user.invalidCredentials"));
        }
        return user;
View Full Code Here

TOP

Related Classes of org.jamesdbloom.domain.User

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.