Package com.music.model.persistent

Examples of com.music.model.persistent.User


    @Transactional
    public void connect(Long userId, SocialAuthentication auth) {
        List<SocialAuthentication> existingAuths = userDao.getSocialAuthentications(auth.getProviderId(), auth.getProviderUserId());

        if (existingAuths.isEmpty()) {
            User user = userDao.getById(User.class, userId);
            auth.setUser(user);
            userDao.persist(auth);
        } else {
            SocialAuthentication existingAuth = existingAuths.get(0);
            existingAuth.setExpirationTime(auth.getExpirationTime());
View Full Code Here


        return userDao.getByPropertyValue(User.class, "email", email);
    }

    @Transactional
    public User completeUserRegistration(String email, String username, String names, Connection<?> connection, boolean loginAutomatically, boolean receiveDailyDigest) {
        User user = new User();
        user.setEmail(email);
        user.setNames(names);
        user.setUsername(username);
        user.setLoginAutomatically(loginAutomatically);
        user.setRegistrationTime(new DateTime());
        user.setReceiveDailyDigest(receiveDailyDigest);
        user = userDao.persist(user);
        if (connection != null) {
            SocialAuthentication auth = JpaConnectionRepository.connectionToAuth(connection);
            auth.setUser(user);
            userDao.persist(auth);
View Full Code Here

        return user;
    }

    @Transactional
    public void unsubscribe(long id, String hash) {
        User user = userDao.getById(User.class, id);
        if (hash.equals(SecurityUtils.hmac(user.getEmail(), hmacKey))) {
            user.setReceiveDailyDigest(false);
            userDao.persist(user);
        }
    }
View Full Code Here

    /**
     * http://jaspan.com/improved_persistent_login_cookie_best_practice
     */
    @Transactional(rollbackFor=StaleStateException.class)
    public User rememberMeLogin(String token, String series) {
        User existingLogin = userDao.getLoginFromAuthToken(token, series);
        if (existingLogin == null) {
            User loginBySeries = userDao.getByPropertyValue(User.class, "loginSeries", series);
            // if a login series exists, assume the previous token was stolen, so deleting all persistent logins.
            // An exception is a request made within a few seconds from the last login time
            // which may mean request from the same browser that is not yet aware of the renewed cookie
            if (loginBySeries != null && new Period(loginBySeries.getLastLoginTime(), new DateTime()).getSeconds() < 5) {
                logger.info("Assuming login cookies theft; deleting all sessions for user " + loginBySeries);
                loginBySeries.setLoginSeries(null);
                loginBySeries.setLoginToken(null);
                userDao.persist(loginBySeries);
            } else if (logger.isDebugEnabled()) {
                logger.debug("No existing login found for token=" + token + ", series=" + series);
            }
            return null;
View Full Code Here

                    series = cookie.getValue();
                }
            }

            if (authToken != null && series != null) {
                User user = userService.rememberMeLogin(authToken, series);
                if (user != null) {
                    adapter.signIn(user, response, false);
                }
            }
        }
View Full Code Here

    @Inject
    private UserService userService;

    @Override
    public String signIn(String userId, Connection<?> connection, NativeWebRequest request) {
        User user = userService.getUser(Long.parseLong(userId));
        signIn(user, (HttpServletResponse) request.getNativeResponse(), true);
        HttpSession session = ((HttpServletRequest) request.getNativeRequest()).getSession();
        String redirectUri = (String) session.getAttribute(AuthenticationController.REDIRECT_AFTER_LOGIN);
        if (redirectUri != null) {
            return redirectUri;
View Full Code Here

    public String socialSignupPage(@RequestParam(required=false) String email, NativeWebRequest request, Model model) {
        ProviderSignInAttempt attempt = (ProviderSignInAttempt) request.getAttribute(ProviderSignInAttempt.class.getName(), RequestAttributes.SCOPE_SESSION);
        if (attempt == null && StringUtils.isEmpty(email)) {
            return "redirect:/";
        }
        User user = new User();
        if (attempt != null) {
            Object api = attempt.getConnection().getApi();
            if (api instanceof Facebook) {
                FacebookProfile profile = ((Facebook) api).userOperations().getUserProfile();
                user.setEmail(profile.getEmail());
                user.setNames(profile.getName());
                user.setUsername(profile.getUsername());
            } else if (api instanceof Twitter) {
                TwitterProfile profile = ((Twitter) api).userOperations().getUserProfile();
                user.setNames(profile.getName());
                user.setUsername(profile.getScreenName());
            }
        } else {
            user.setEmail(email);
            model.addAttribute("type", "Persona");
        }
        model.addAttribute("user", user);
        return "socialSignup";
    }
View Full Code Here

        }

        // if the session has expired for a fb/tw registration (i.e. attempt is null), do not proceed - otherwise inconsistent data is stored
        ProviderSignInAttempt attempt = (ProviderSignInAttempt) request.getAttribute(ProviderSignInAttempt.class.getName(), RequestAttributes.SCOPE_SESSION);
        if (attempt != null) {
            User user = userService.completeUserRegistration(email, username, names, attempt.getConnection(), loginAutomatically, receiveDailyDigest);
            signInAdapter.signIn(user, (HttpServletResponse) request.getNativeResponse(), true);
        } else if ("Persona".equals(type)){
            User user = userService.completeUserRegistration(email, username, names, null, loginAutomatically, receiveDailyDigest);
            signInAdapter.signIn(user, (HttpServletResponse) request.getNativeResponse(), true);
        }
        String redirectUri = (String) session.getAttribute(REDIRECT_AFTER_LOGIN);
        if (redirectUri != null) {
            return "redirect:" + redirectUri;
View Full Code Here

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("assertion", assertion);
        params.add("audience", request.getScheme() + "://" + request.getServerName() + ":" + (request.getServerPort() == 80 ? "" : request.getServerPort()));
        PersonaVerificationResponse response = restTemplate.postForObject("https://verifier.login.persona.org/verify", params, PersonaVerificationResponse.class);
        if (response.getStatus().equals("okay")) {
            User user = userService.getUserByEmail(response.getEmail());
            if (user == null && userRequestedAuthentication) {
                return "/socialSignUp?email=" + response.getEmail();
            } else if (user != null){
                if (userRequestedAuthentication || user.isLoginAutomatically()) {
                    signInAdapter.signIn(user, httpResponse, true);
                    return "/";
                } else {
                    return "";
                }
View Full Code Here

TOP

Related Classes of com.music.model.persistent.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.