Package org.springframework.security.providers

Examples of org.springframework.security.providers.UsernamePasswordAuthenticationToken


     * Test for the Authenticate method.
     */
    @Test
    public void testAuthenticate()
    {
        final UsernamePasswordAuthenticationToken auth =
            context.mock(UsernamePasswordAuthenticationToken.class);
        final UserDetailsService uds = context.mock(UserDetailsService.class);
        final UserDetails ud = context.mock(UserDetails.class);
        final UserDetailsChecker checker = context.mock(UserDetailsChecker.class);

View Full Code Here


    /**
     * {@inheritDoc}
     */
    public Authentication authenticate(final Authentication authentication)
    {
        UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;
        UserDetails currentUserDets = userDetailsService.loadUserByUsername(userToken.getName());
        userDetailsChecker.check(currentUserDets);
        return new UsernamePasswordAuthenticationToken(currentUserDets, userToken.getCredentials(),
                currentUserDets.getAuthorities());
    }
View Full Code Here

                .loadUserByUsername((String) parentAuthResult.getName());
       
        detailsChecker.check(details);
       
        //return new Authentication object with UserDetails populated.
        return new UsernamePasswordAuthenticationToken(details,
                parentAuthResult.getCredentials(), parentAuthResult.getAuthorities());

    }
View Full Code Here

        if (username != null && !username.isEmpty() && !loginWithFilter) {
            try {
                if (password == null) {
                    password = hash;
                }
                Authentication request = new UsernamePasswordAuthenticationToken(username, password);
                Authentication result = authenticationManager.authenticate(request);
                SecurityContextHolder.getContext().setAuthentication(result);

                // generate new session to avoid session fixation vulnerability
                HttpSession session = httpRequest.getSession(false);
View Full Code Here

                username = token.substring(0, delim);
                password = token.substring(delim + 1);
            }

            if (authenticationIsRequired(username)) {
                UsernamePasswordAuthenticationToken authRequest =
                        new UsernamePasswordAuthenticationToken(username, password);
                authRequest.setDetails(authenticationDetailsSource.buildDetails(request));

                Authentication authResult;

                try {
                    authResult = authenticationManager.authenticate(authRequest);
View Full Code Here

                            (loginHash != null && loginHash.trim().equalsIgnoreCase(master.getLoginHash())))) {
                        currentUser = directoryManager.getUserByUsername(loginAs);
                        if (currentUser != null) {
                            WorkflowUserDetails user = new WorkflowUserDetails(currentUser);
                           
                            auth = new UsernamePasswordAuthenticationToken(user, user.getUsername(), user.getAuthorities());
                            super.setDetails(request, (UsernamePasswordAuthenticationToken) auth);
                        } else {
                            LogUtil.info(getClass().getName(), "Authentication for user " + loginAs + ": " + false);
           
                            WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                            workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + loginAs + ": " + false);
                       
                            throw new BadCredentialsException("");
                        }
                    }
                }
            } else {
                if (loginHash != null) {
                    password = loginHash;
                }
                if (password != null) {
                    // use existing authentication manager
                    try {
                        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username.trim(), password.trim());
                        super.setDetails(request, authRequest);

                        auth = getAuthenticationManager().authenticate(authRequest);

                        // no direct way in Spring Security 2, so use reflection to clear password in token
View Full Code Here

        GrantedAuthority[] authorities = gaList.toArray(new GrantedAuthority[gaList.size()]);

        // return result
        User user = directoryManager.getUserByUsername(username);
        UserDetails details = new WorkflowUserDetails(user);
        UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(details, password, authorities);
        result.setDetails(details);
        return result;
    }
View Full Code Here

            throw new AuthenticationFailedException();
        }
        final UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication) ftpAuthRequest;
        final String principal = upa.getUsername();
        final String credentials = upa.getPassword();
        org.springframework.security.Authentication gsAuth = new UsernamePasswordAuthenticationToken(
                principal, credentials);
        try {
            gsAuth = authManager.authenticate(gsAuth);
        } catch (org.springframework.security.AuthenticationException authEx) {
            throw new AuthenticationFailedException(authEx);
        }

        try {
            // gather the user
            BaseUser user = getUserByName(principal);
            user.setPassword(credentials);
            // is the user enabled?
            if (!user.getEnabled()) {
                throw new AuthenticationFailedException();
            }

            // scary message for admins if the username/password has not
            // been changed
            if (DEFAULT_USER.equals(user.getName()) && DEFAULT_PASSWORD.equals(credentials)) {
                LOGGER.log(Level.SEVERE, "The default admin/password combination has not been "
                        + "modified, this makes the embedded FTP server an "
                        + "open file host for everybody to use!!!");
            }

            final File dataRoot = dataDir.findOrCreateDataRoot();

            // enable only admins and non anonymous users
            boolean isGSAdmin = false;
            for (GrantedAuthority authority : gsAuth.getAuthorities()) {
                final String userRole = authority.getAuthority();
                if (ADMIN_ROLE.equals(userRole)) {
                    isGSAdmin = true;
                    break;
                }
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.