Package com.jappstart.model.auth

Examples of com.jappstart.model.auth.UserAccount


        if (binding.hasErrors()) {
            return "create";
        }

        final UserAccount user = new UserAccount(register.getUsername());
        user.setDisplayName(register.getDisplayName());
        user.setEmail(register.getEmail());
        user.setPassword(passwordEncoder.encodePassword(
            register.getPassword(), user.getSalt()));

        try {
            userDetailsService.addUser(user, locale);
        } catch (DuplicateUserException e) {
            binding.addError(new FieldError(REGISTER, "username",
View Full Code Here


    @RequestMapping(value = "/login/validate", method = RequestMethod.POST)
    @ResponseBody
    public final Map<String, Boolean> validate(
        @RequestBody final Map<String, String> request) {
        final Map<String, Boolean> response = new HashMap<String, Boolean>();
        final UserAccount user =
            userDetailsService.getUser(request.get("username"));

        response.put("found", user != null);

        return response;
View Full Code Here

    @Transactional
    public final void createNewToken(final PersistentRememberMeToken token) {
        final Query query = entityManager.createQuery(
            "SELECT u FROM UserAccount u WHERE username = :username");
        query.setParameter("username", token.getUsername());
        final UserAccount user = (UserAccount) query.getSingleResult();

        if (user.getPersistentUser() == null) {
            user.setPersistentUser(
                new PersistentUser(user.getKey(), token.getUsername()));
        }

        if (user.getPersistentUser().getPersistentLogins() == null) {
            user.getPersistentUser().setPersistentLogins(
                new ArrayList<PersistentLogin>());
        }

        user.getPersistentUser().getPersistentLogins().add(
            createPersistentLogin(user.getPersistentUser().getKey(), token));

        entityManager.persist(user);

        memcacheService.put(user.getUsername(), user,
            Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
    }
View Full Code Here

     */
    @Override
    public final UserDetails loadUserByUsername(final String username) {
        final List<GrantedAuthority> authorities =
            new ArrayList<GrantedAuthority>();
        UserAccount user = (UserAccount) memcacheService.get(username);

        if (user == null) {
            final Query query = entityManager.createQuery(
                "SELECT u FROM UserAccount u WHERE username = :username");
            query.setParameter(USERNAME, username);

            try {
                user = (UserAccount) query.getSingleResult();

                memcacheService.put(username, user,
                    Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
            } catch (NoResultException e) {
                throw new UsernameNotFoundException("Username not found.", e);
            }
        }

        authorities.add(new SimpleGrantedAuthority(user.getRole()));

        return new EnhancedUser(user.getUsername(), user.getEmail(),
            user.getDisplayName(), user.getPassword(), user.getSalt(),
            user.isEnabled(), user.isAccountNonExpired(),
            user.isCredentialsNonExpired(), user.isAccountNonLocked(),
            authorities);
    }
View Full Code Here

     * @param username the username
     * @return the user account
     */
    @Override
    public final UserAccount getUser(final String username) {
        UserAccount user = (UserAccount) memcacheService.get(username);

        if (user == null) {
            final Query query = entityManager.createQuery(
                "SELECT u FROM UserAccount u WHERE username = :username");
            query.setParameter(USERNAME, username);
View Full Code Here

     * @param locale the locale
     */
    @Override
    @Transactional
    public final void addUser(final UserAccount user, final Locale locale) {
        final UserAccount cachedUser = (UserAccount) memcacheService.get(
            user.getUsername());

        if (cachedUser != null) {
            throw new DuplicateUserException();
        }
View Full Code Here

        final Query query = entityManager.createQuery(
            "SELECT u FROM UserAccount u WHERE activationKey = :key");
        query.setParameter("key", key);

        try {
            final UserAccount user = (UserAccount) query.getSingleResult();
            user.setEnabled(true);

            entityManager.persist(user);

            memcacheService.put(user.getUsername(), user,
                Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));

            return true;
        } catch (NoResultException e) {
            return false;
View Full Code Here

     * @param username the username
     * @return true if sent; false otherwise
     */
    @Override
    public final boolean isActivationEmailSent(final String username) {
        UserAccount user = (UserAccount) memcacheService.get(username);

        if (user == null) {
            final Query query = entityManager.createQuery(SELECT_USER);
            query.setParameter(USERNAME, username);

            try {
                user = (UserAccount) query.getSingleResult();

                memcacheService.put(username, user,
                    Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
            } catch (NoResultException e) {
                throw new UsernameNotFoundException("Username not found.", e);
            }
        }

        return user.isActivationEmailSent();
    }
View Full Code Here

    public final void activationEmailSent(final String username) {
        final Query query = entityManager.createQuery(SELECT_USER);
        query.setParameter(USERNAME, username);

        try {
            final UserAccount user = (UserAccount) query.getSingleResult();
            user.setActivationEmailSent(true);

            entityManager.persist(user);

            memcacheService.put(user.getUsername(), user,
                Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
        } catch (NoResultException e) {
            throw new UsernameNotFoundException("Username not found.", e);
        }
    }
View Full Code Here

TOP

Related Classes of com.jappstart.model.auth.UserAccount

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.