/**
   * Creates the final <tt>Authentication</tt> object which will be returned from the
   * <tt>authenticate</tt> method.
   *
   * @param authentication the original authentication request token
   * @param user the <tt>UserDetails</tt> instance returned by the configured
   *     <tt>UserDetailsContextMapper</tt>.
   * @return the Authentication object for the fully authenticated user.
   */
  protected Authentication createSuccessfulAuthentication(
      final UsernamePasswordAuthenticationToken authentication,
      final ExtendedLdapUserDetailsImpl user) {

    logger.finest("CustomLdapAuthenticationProvider : createSuccessfulAuthentication");
    Object password =
        useAuthenticationRequestCredentials ? authentication.getCredentials() : user.getPassword();

    CustomAuthenticationToken customAuthToken =
        new CustomAuthenticationToken(user, password, user.getAuthorities(), user.getAuthGroups());
    customAuthToken.setDetails(authentication.getDetails());

    return customAuthToken;
  }
  protected Authentication createSuccesssAuthentication(
      Object principal,
      CustomAuthenticationToken authentication,
      List<GrantedAuthority> grantedAuthoritiesList) {

    CustomAuthenticationToken result =
        new CustomAuthenticationToken(
            principal,
            authentication.getCredentials(),
            (String) authentication.getCompany(),
            grantedAuthoritiesList);

    result.setDetails(authentication.getDetails());

    return result;
  }