Package com.porterhead.rest.user.domain

Examples of com.porterhead.rest.user.domain.User


        return token;
    }

    @Transactional
    public VerificationToken sendEmailRegistrationToken(String userId) {
        User user = ensureUserIsLoaded(userId);
        VerificationToken token = new VerificationToken(user,
                VerificationToken.VerificationTokenType.emailRegistration,
                config.getEmailRegistrationTokenExpiryTimeInMinutes());
        user.addVerificationToken(token);
        userRepository.save(user);
        emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user,
                token, getConfig().getHostNameUrl()));
        return token;
    }
View Full Code Here


     */
    @Transactional
    public VerificationToken sendLostPasswordToken(LostPasswordRequest lostPasswordRequest) {
        validate(lostPasswordRequest);
        VerificationToken token = null;
        User user = userRepository.findByEmailAddress(lostPasswordRequest.getEmailAddress());
        if (user != null) {
            token = user.getActiveLostPasswordToken();
            if (token == null) {
                token = new VerificationToken(user, VerificationToken.VerificationTokenType.lostPassword,
                        config.getLostPasswordTokenExpiryTimeInMinutes());
                user.addVerificationToken(token);
                userRepository.save(user);
            }
            emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user, token, getConfig().getHostNameUrl()));
        }

View Full Code Here

    }

    @Transactional
    public VerificationToken generateEmailVerificationToken(String emailAddress) {
        Assert.notNull(emailAddress);
        User user = userRepository.findByEmailAddress(emailAddress);
        if (user == null) {
            throw new UserNotFoundException();
        }
        if (user.isVerified()) {
            throw new AlreadyVerifiedException();
        }
        //if token still active resend that
        VerificationToken token = user.getActiveEmailVerificationToken();
        if (token == null) {
            token = sendEmailVerificationToken(user);
        } else {
            emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user, token, getConfig().getHostNameUrl()));
        }
View Full Code Here

        VerificationToken token = loadToken(base64EncodedToken);
        if (token.isVerified()) {
            throw new AlreadyVerifiedException();
        }
        token.setVerified(true);
        User user = token.getUser();
        try {
            user.setHashedPassword(user.hashPassword(passwordRequest.getPassword()));
        } catch (Exception e) {
            throw new AuthenticationException();
        }
        //set user to verified if not already and authenticated role
        user.setVerified(true);
        if (user.hasRole(Role.anonymous)) {
            user.setRole(Role.authenticated);
        }
        userRepository.save(user);
        return token;
    }
View Full Code Here

    public ApplicationConfig getConfig() {
        return this.config;
    }

    private User ensureUserIsLoaded(String userIdentifier) {
        User user = null;
        if (StringUtil.isValidUuid(userIdentifier)) {
            user = userRepository.findByUuid(userIdentifier);
        } else {
            user = userRepository.findByEmailAddress(userIdentifier);
        }
View Full Code Here

                userIds.add(user.getUser().getUuid().toString());
            }
            return userIds;
        }
        //First time connected so create a User account or find one that is already created with the email address
        User user = findUserFromSocialProfile(connection);
        String userId;
        if(user == null) {
          userId = userService.createUser(Role.authenticated).getUserId();
        } else {
           userId = user.getUuid().toString();
        }
        //persist the Connection
        createConnectionRepository(userId).addConnection(connection);
        userIds.add(userId);
View Full Code Here

  public ConnectionRepository createConnectionRepository(String userId) {
    if (userId == null) {
      throw new IllegalArgumentException("userId cannot be null");
    }
        User user = userRepository.findByUuid(userId);
        if(user == null) {
            throw new IllegalArgumentException("User not Found");
        }
    return new JpaConnectionRepository(socialUserRepository, userRepository, user, connectionFactoryLocator, textEncryptor);
  }
View Full Code Here

        }
    return new JpaConnectionRepository(socialUserRepository, userRepository, user, connectionFactoryLocator, textEncryptor);
  }

    private User findUserFromSocialProfile(Connection connection) {
        User user = null;
        UserProfile profile = connection.fetchUserProfile();
        if(profile != null && StringUtils.hasText(profile.getEmail())) {
           user = userRepository.findByEmailAddress(profile.getEmail());
        }
        return user;
View Full Code Here

                hashedToken = token[1];
                //make sure date and nonce is valid
                validateRequestDate(context.getRequestDateString());
                validateNonce(context.getNonceToken());

                User user = userRepository.findByUuid(userId);
                if (user != null) {
                    externalUser = new ExternalUser(user);
                    if (!isAuthorized(user, context, hashedToken)) {
                        throw new AuthorizationException("Request rejected due to an authorization failure");
                    }
View Full Code Here

        String token = securityContext.getAuthorizationToken();
        ExternalUser externalUser = null;
        if(token == null) {
            return externalUser;
        }
        User user =  userRepository.findBySession(token);
        if(user == null) {
            throw new AuthorizationException("Session token not valid");
        }
        AuthorizationToken authorizationToken = user.getAuthorizationToken();
            if (authorizationToken.getToken().equals(token)) {
                externalUser = new ExternalUser(user);
            }
        return externalUser;
    }
View Full Code Here

TOP

Related Classes of com.porterhead.rest.user.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.