targetUserRequest.setDetails(new WebAuthenticationDetails( request));
targetUserRequest.setDetails(new WebAuthenticationDetails( request, false));
                    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;                    }