Package org.springframework.security.authentication

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


            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

        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

    @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

  @When("user <username> authenticates with password <password>")
  @Alias("user $username authenticates with password $password")
  public void userAuthenticates(@Named(value="username") String username, @Named(value="password") String password) {
    try {
      auth = manager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
      authException = null;
    } catch (AuthenticationException e) {
      auth = null;
      authException = e;
    }
View Full Code Here

                (String)storedRequest.get("clientId"), null, true, new HashSet((List)storedRequest.get("scope")),
                null, null, null, null);

        DBObject userAuthorization = (DBObject)source.get("userAuthentication");
        Object principal = getPrincipalObject(userAuthorization.get("principal"));
        Authentication userAuthentication = new UsernamePasswordAuthenticationToken(principal,
                userAuthorization.get("credentials"), getAuthorities((List) userAuthorization.get("authorities")));

        return new OAuth2Authentication(oAuth2Request,  userAuthentication );
    }
View Full Code Here

     * @param username the username to use, must not be {@code null}.
     * @param password the password to use, must not be {@code null}.
     * @throws AuthenticationException if authentication fails.
     */
    public void login(String username, String password) throws AuthenticationException {
        login(new UsernamePasswordAuthenticationToken(username, password));
    }
View Full Code Here

            this.authorities = Arrays.asList(authorities);
            return this;
        }

        public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
            UsernamePasswordAuthenticationToken authentication =
                    new UsernamePasswordAuthenticationToken(this.username, this.credentials, this.authorities);
            save(authentication,request);
            return request;
        }
View Full Code Here

            this.userDetailsServiceBeanId = userDetailsServiceBeanId;
            return this;
        }

        public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
            UsernamePasswordAuthenticationToken authentication = authentication(request.getServletContext());
            save(authentication,request);
            return request;
        }
View Full Code Here

        private UsernamePasswordAuthenticationToken authentication(ServletContext servletContext) {
            ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
            UserDetailsService userDetailsService = userDetailsService(context);
            UserDetails userDetails = userDetailsService.loadUserByUsername(this.username);
            return new UsernamePasswordAuthenticationToken(
                    userDetails, userDetails.getPassword(), userDetails.getAuthorities());
        }
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

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.