Examples of UsernamePasswordAuthenticationToken


Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        @Override
        public boolean validate(PasswordValidationCallback.Request request)
                throws PasswordValidationCallback.PasswordValidationException {
            if (super.validate(request)) {
                UsernamePasswordAuthenticationToken authRequest =
                        new UsernamePasswordAuthenticationToken(user, user.getPassword());
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication success: " + authRequest.toString());
                }

                SecurityContextHolder.getContext().setAuthentication(authRequest);
                return true;
            }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            throw e;
        }


        // log user in automatically
        final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);

        // Send user an e-mail
        if (log.isDebugEnabled()) {
            log.debug("Sending user '" + user.getUsername() + "' an account information e-mail");
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        return userManager;
    }

    protected void login(final String username) {
        final User user = userManager.getUserByUsername(username);
        final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), "", user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

    System.out.println("userId----" + users.getUserId() + "---ip--"
        + Common.toIpAddr(request));
    userLoginList.setLoginIp(Common.toIpAddr(request));
    userLoginListService.add(userLoginList);
    // 实现 Authentication
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
        username, password);
    // 允许子类设置详细属性
    setDetails(request, authRequest);

    // 运行UserDetailsService的loadUserByUsername 再次封装Authentication
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

      if (users == null || !users.getUserPassword().equals(password)) {
        request.setAttribute("error", "用户或密码不正确!");
          return "/background/framework/login";
      }
      Authentication authentication = myAuthenticationManager
          .authenticate(new UsernamePasswordAuthenticationToken(username,password));
      SecurityContext securityContext = SecurityContextHolder.getContext();
      securityContext.setAuthentication(authentication);
      HttpSession session = request.getSession(true)
        session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext)
        // 当验证都通过后,把用户信息放在session里
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        saveMessage(request, getText("user.registered", user.getUsername(), locale));
        request.getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);

        // log user in automatically
        final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), password, user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);

        // Send user an e-mail
        if (log.isDebugEnabled()) {
            log.debug("Sending user '" + user.getUsername() + "' an account information e-mail");
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        saveMessage(getText("user.registered"));
        getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);

        // log user in automatically
        UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);

        // Send an account information e-mail
        mailMessage.setSubject(getText("signup.email.subject"));
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            boolean signupUser = resolver.isAnonymous(auth);
            if (auth != null && !signupUser) {
                UserManager userManager = (UserManager) target;
                User currentUser = getCurrentUser(auth, userManager);
                if (currentUser.getId().equals(user.getId())) {
                    auth = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities());
                    SecurityContextHolder.getContext().setAuthentication(auth);
                }
            }
        }
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        addMessage("user.registered");
        getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);

        // log user in automatically
        UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);

        // Send an account information e-mail
        message.setSubject(getText("signup.email.subject"));
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

    @Override
    public boolean authenticate(String username, String password) {
        boolean authenticated;
        try {
            Authentication authentication = authenticationManager.authenticate(
                    new UsernamePasswordAuthenticationToken(username, password));
            SecurityContextHolder.getContext().setAuthentication(authentication);
            //A hack to allow to track logged users without using SessionManagementFilter which is problematic in Wicket
            sessionRegistry.registerNewSession(getId(), authentication.getPrincipal());
            authenticated = authentication.isAuthenticated();
        } catch (AuthenticationException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.