Package org.acegisecurity.providers

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken


     *
     * @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       
        ArrayList orig = new ArrayList();
        for (int i = 0; i < targetUser.getAuthorities().length; i++) {
      orig.add(targetUser.getAuthorities()[i]);
    }

        // Allow subclasses to change the authorities to be granted
        if (switchUserAuthorityChanger != null) {
            switchUserAuthorityChanger.modifyGrantedAuthorities(targetUser, currentAuth, orig);
        }

        // 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(authenticationDetailsSource.buildDetails((HttpServletRequest) request));

        return targetUserRequest;
    }
View Full Code Here


     * @return Integer
     */
    private Integer getAuthenticatedExecutingUser() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if(securityContext != null) {
            UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) securityContext.getAuthentication();
            if(authentication != null) {
                Object detail = authentication.getDetails();
                if(detail != null && detail instanceof AuthenticatedUserVo) {
                    return ((AuthenticatedUserVo)detail).getUserId();
                }
            }
        }
View Full Code Here

     * @return Integer
     */
    private Integer getAuthenticatedExecutingUser() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if(securityContext != null) {
            UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) securityContext.getAuthentication();
            if(authentication != null) {
                Object detail = authentication.getDetails();
                if(detail != null && detail instanceof AuthenticatedUserVo) {
                    return ((AuthenticatedUserVo)detail).getUserId();
                }
            }
        }
View Full Code Here

             userDetails = jtrac.loadUserByUsername(authentication.getName());
        } catch(AuthenticationException ae) { // catch just to log, then re-throw as-is
            logger.debug("ldap user not allocated to any Spaces within JTrac");
            throw ae;
        }
        return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities());    
    }
View Full Code Here

     * @param loginName The login name of the user
     * @param password The password of the user
     * @return Returns the User object or null in case of an Exception.
     */
    public User authenticate(String loginName, String password) {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
                loginName, password);
        AuthenticationManager am = (AuthenticationManager) applicationContext.getBean("authenticationManager");
        try {
            Authentication authentication = am.authenticate(token);
            return (User) authentication.getPrincipal();
View Full Code Here

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

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

  // TODO: replace with User#impersonate once we are requiring 1.419+ as core
  private Authentication impersonateUser(User u) {
        try {
            UserDetails d = Hudson.getInstance().getSecurityRealm().loadUserByUsername(u.getId());
            return new UsernamePasswordAuthenticationToken(d.getUsername(), "", d.getAuthorities());
        } catch (AuthenticationException e) {
            // TODO: use the stored GrantedAuthorities
            return new UsernamePasswordAuthenticationToken(
                u.getId(), "", new GrantedAuthority[]{SecurityRealm.AUTHENTICATED_AUTHORITY});
        }
    }
View Full Code Here

        } else {
            // If password is null, set to blank to avoid a NPE.
            password = "";
        }

        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
                password);

        // Allow subclasses to set the "details" property
        setDetails(request, authRequest);
View Full Code Here

        Assert.notNull(this.authenticationManager, "authenticationManager is required");
    }

    public GrantedAuthority[] attemptAuthentication(String username,
        String password) throws RemoteAuthenticationException {
        UsernamePasswordAuthenticationToken request = new UsernamePasswordAuthenticationToken(username,
                password);

        try {
            return authenticationManager.authenticate(request).getauthorities();
        } catch (AuthenticationException authEx) {
View Full Code Here

        String username = authentication.getPrincipal().toString();
        String password = authentication.getCredentials().toString();
        GrantedAuthority[] authorities = remoteAuthenticationManager
            .attemptAuthentication(username, password);

        return new UsernamePasswordAuthenticationToken(username, password,
            authorities);
    }
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.