Package org.springframework.security.providers

Examples of org.springframework.security.providers.UsernamePasswordAuthenticationToken


    public void changePassword(String oldPassword, String newPassword) {

        User user = getCurrentUser();

        Authentication oldAuth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), oldPassword);
        authMgr.authenticate(oldAuth);

        createPassWord(user, newPassword);

        log.debug("password changed, saving");
        save(user);

        log.debug("remove from cache");
        userCache.removeUserFromCache(user.getUsername());

        log.debug("change security context");
        Authentication newAuthentication = new UsernamePasswordAuthenticationToken(
                user.getUsername(), newPassword);
        authMgr.authenticate(newAuthentication);
        SecurityContextHolder.getContext().setAuthentication(
                newAuthentication);
View Full Code Here


                return true;
            }

            user = userService.createUser(fullName, email, username, password1);

            Authentication token = new UsernamePasswordAuthenticationToken(username, password1);
            Authentication result = authenticationManager.authenticate(token);
            SecurityContext securityContext = new SecurityContextImpl();
            securityContext.setAuthentication(result);
            SecurityContextHolder.setContext(securityContext);
View Full Code Here

                    }
                }
            } else if (expectAllThreadsToUseIdenticalAuthentication) {
                // A global
                SecurityContextHolder.getContext()
                                     .setAuthentication(new UsernamePasswordAuthenticationToken("GLOBAL_USERNAME",
                        "pass"));

                for (int i = 0; i < threads.length; i++) {
                    if ((i % 2) == 0) {
                        // Don't inject auth into current thread;both current thread and child will have same authentication
View Full Code Here

        Thread t = new Thread(new Runnable() {
               public void run() {
                    if (injectAuthIntoCurrentThread) {
                        // Set authentication in this thread
                        SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(
                                expectedUsername, "pass"));

                        //System.out.println(threadIdentifier + " - set to " + SecurityContextHolder.getContext().getAuthentication());
                    } else {
                        //System.out.println(threadIdentifier + " - not set (currently " + SecurityContextHolder.getContext().getAuthentication() + ")");
View Full Code Here

    public void login() throws SpringSecurityException {
        final ApplicationContext appCtx = Application.instance().getApplicationContext();

        // Attempt login
        UsernamePasswordAuthenticationToken request = new UsernamePasswordAuthenticationToken(getUsername(),
                getPassword());

        Authentication result = null;

        try {
View Full Code Here

     * @return authentication token
     */
    public Authentication getAuthentication() {
        String username = loginDetails.getUsername().trim();
        String password = loginDetails.getPassword().trim();
        return new UsernamePasswordAuthenticationToken( username, password );
    }
View Full Code Here

  }

  private Authentication getAuthentication() {
    GrantedAuthority[] authorities = { new GrantedAuthorityImpl("ROLE_1"), new GrantedAuthorityImpl("ROLE_2"),
        new GrantedAuthorityImpl("ROLE_3") };
    return new UsernamePasswordAuthenticationToken("test", "", authorities);
  }
View Full Code Here

        if (roles != null && roles.length > 0) {
            GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
            for (int i = 0; i < roles.length; i++) {
                authorities[i] = new GrantedAuthorityImpl(roles[i]);
            }
            authToken = new UsernamePasswordAuthenticationToken(username, password, authorities);
        } else {
            authToken = new UsernamePasswordAuthenticationToken(username, password);
        }
        return authToken;
    }
View Full Code Here

  @SuppressWarnings("deprecation")
  private void authenticate(WSPasswordCallback passwordCallback){
    String userName = passwordCallback.getIdentifer();
    String password = passwordCallback.getPassword();
   
    Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
    try {
      authentication = authenticationManager.authenticate(authentication);
      if (authentication.isAuthenticated()) {
        // Set the security context
        SecurityContext securityContext = new SecurityContextImpl();
        securityContext.setAuthentication(authentication);
        SecurityContextHolder.setContext(securityContext);
      } else {
View Full Code Here

      }
      if(justRemove) {
        SecurityContextHolder.clearContext();
      }
      else {
        final UsernamePasswordAuthenticationToken token =
          new UsernamePasswordAuthenticationToken(newUsername, newPassword);
        token.setDetails(authentication.getDetails());
        SecurityContextHolder.getContext().setAuthentication(token);
      }
      log.info((justRemove ? "Removed" : "Reset") + " security context for user: " + originalUsername);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.providers.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.