Package org.acegisecurity.providers

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken


     * loginContext.login() method fail.
     */
    public Authentication authenticate(Authentication auth)
            throws AuthenticationException {
        if (auth instanceof UsernamePasswordAuthenticationToken) {
            UsernamePasswordAuthenticationToken request = (UsernamePasswordAuthenticationToken) auth;

            try {
                //Create the LoginContext object, and pass our InternallCallbackHandler
                LoginContext loginContext = new LoginContext(loginContextName,
                        new InternalCallbackHandler(auth));

                //Attempt to login the user, the LoginContext will call our InternalCallbackHandler at this point.
                loginContext.login();

                //create a set to hold the authorities, and add any that have already been applied.
                Set authorities = new HashSet();

                if (request.getauthorities() != null) {
                    authorities.addAll(Arrays.asList(request.getauthorities()));
                }

                //get the subject principals and pass them to each of the AuthorityGranters
                Set principals = loginContext.getSubject().getPrincipals();

                for (Iterator iterator = principals.iterator();
                     iterator.hasNext();) {
                    Principal principal = (Principal) iterator.next();

                    for (int i = 0; i < AuthorityGranters.length; i++) {
                        AuthorityGranter granter = AuthorityGranters[i];
                        Set roles = granter.grant(principal);

                        //If the granter doesn't wish to grant any authorities, it should return null.
                        if ((roles != null) && !roles.isEmpty()) {
                            for (Iterator roleIterator = roles.iterator();
                                 roleIterator.hasNext();) {
                                String role = roleIterator.next().toString();
                                authorities.add(new JaasGrantedAuthority(role,
                                        principal));
                            }
                        }
                    }
                }

                //Convert the authorities set back to an array and apply it to the token.
                JaasAuthenticationToken result = new JaasAuthenticationToken(request
                        .getPrincipal(), request.getCredentials(),
                        (GrantedAuthority[]) authorities.toArray(
                                new GrantedAuthority[authorities.size()]), loginContext);

                //Publish the success event
                publishSuccessEvent(result);
View Full Code Here


             * @throws CredentialsExpiredException If the target user
             *         credentials are expired.
             */
            protected Authentication attemptSwitchUser(
                HttpServletRequest request) throws AuthenticationException {
                UsernamePasswordAuthenticationToken targetUserRequest = null;

                String username = request.getParameter(ACEGI_SECURITY_SWITCH_USERNAME_KEY);

                if (username == null) {
                    username = "";
View Full Code Here

                     * @see SwitchUserGrantedAuthority
                     */
                    private UsernamePasswordAuthenticationToken createSwitchUserToken(
                        HttpServletRequest request, String username,
                        UserDetails targetUser) {
                        UsernamePasswordAuthenticationToken targetUserRequest;

                        // grant an additional authority that contains the original Authentication object
                        // which will be used to 'exit' from the current switched user.
                        Authentication currentAuth = SecurityContextHolder.getContext()
                                                                          .getAuthentication();
                        GrantedAuthority switchauthority = new SwitchUserGrantedAuthority(ROLE_PREVIOUS_ADMINISTRATOR,
                                currentAuth);

                        // get the original authorities
                        List orig = Arrays.asList(targetUser.getauthorities());

                        // add the new switch user authority
                        List newAuths = new ArrayList(orig);
                        newAuths.add(switchauthority);

                        GrantedAuthority[] authorities = {};
                        authorities = (GrantedAuthority[]) newAuths.toArray(authorities);

                        // create the new authentication token
                        targetUserRequest = new UsernamePasswordAuthenticationToken(targetUser,
                                targetUser.getPassword(), authorities);

                        // set details
                        targetUserRequest.setDetails(new WebAuthenticationDetails(
                                request));

                        return targetUserRequest;
                    }
View Full Code Here

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

        // log user in automatically
        Authentication auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword());
        try {
            ApplicationContext ctx =
                WebApplicationContextUtils.getWebApplicationContext(getSession().getServletContext());
            if (ctx != null) {
                ProviderManager authenticationManager = (ProviderManager) ctx.getBean("authenticationManager");
View Full Code Here

        }
        return subject;
    }

    protected void authenticate(Subject subject, String login, String password) {
        Authentication token = new UsernamePasswordAuthenticationToken(login, password);
        token = authenticationManager.authenticate(token);
    }
View Full Code Here

        if (password == null) {
            password = "";
        }

        Authentication request = new UsernamePasswordAuthenticationToken(username.toString(), password.toString());
        Authentication response = null;

        try {
            response = authenticationManager.authenticate(request);
        } catch (AuthenticationException failed) {
View Full Code Here

            }

            ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("clientContext.xml");
            ClientApplication client = new ClientApplication(beanFactory);

            client.invokeContactManager(new UsernamePasswordAuthenticationToken(username, password), nrOfCalls);
            System.exit(0);
        }
    }
View Full Code Here

        }

        if (identity == null) {
            super.log.debug("creating usernamepassword token");

            Authentication request = new UsernamePasswordAuthenticationToken(username, password);
            Authentication response = null;

            try {
                if (super.log.isDebugEnabled()) {
                    super.log.debug("attempting authentication");
View Full Code Here

        if (credentials == null) {
            credentials = "";
        }

        Authentication request = new UsernamePasswordAuthenticationToken(username, credentials);
        Authentication response = null;

        try {
            response = authenticationManager.authenticate(request);
        } catch (AuthenticationException failed) {
View Full Code Here

        if (credentials == null) {
            credentials = "";
        }

        Authentication request = new UsernamePasswordAuthenticationToken(username, credentials);
        Authentication response = null;

        try {
            response = authenticationManager.authenticate(request);
        } catch (AuthenticationException failed) {
View Full Code Here

TOP

Related Classes of org.acegisecurity.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.