fix for invalid exception occured in following usage:

    ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
    Authentication customAuthentication =
        new UsernamePasswordAuthenticationToken("ROLE_USER", authentication, authorities);
    customAuthentication.setAuthenticated(true);