/*
   * Find the Subject identifier among federated claims
   */
  public static String getFederatedSubjectFromClaims(
      AuthenticationContext context, String otherDialect) throws FrameworkException {
    String value;
    boolean useLocalClaimDialect = context.getExternalIdP().useDefaultLocalIdpDialect();
    String userIdClaimURI = context.getExternalIdP().getUserIdClaimUri();
    Map<ClaimMapping, String> claimMappings = context.getSubject().getUserAttributes();

    if (useLocalClaimDialect) {
      Map<String, String> extAttributesValueMap =
          FrameworkUtils.getClaimMappings(claimMappings, false);
      Map<String, String> mappedAttrs = null;
      try {
        mappedAttrs =
            ClaimMetadataHandler.getInstance()
                .getMappingsMapFromOtherDialectToCarbon(
                    otherDialect, extAttributesValueMap.keySet(), context.getTenantDomain(), true);
      } catch (ClaimMetadataException e) {
        throw new FrameworkException("Error while loading claim mappings.", e);
      }

      String spUserIdClaimURI = mappedAttrs.get(userIdClaimURI);
      value = extAttributesValueMap.get(spUserIdClaimURI);
    } else {
      ClaimMapping claimMapping = new ClaimMapping();
      Claim claim = new Claim();
      claim.setClaimUri(userIdClaimURI);
      claimMapping.setRemoteClaim(claim);
      value = claimMappings.get(claimMapping);
    }
    return value;
  }
  /*
   * Find the Subject identifier among federated claims
   */
  public static String getFederatedSubjectFromClaims(
      IdentityProvider identityProvider, Map<ClaimMapping, String> claimMappings) {

    String userIdClaimURI = identityProvider.getClaimConfig().getUserClaimURI();
    ClaimMapping claimMapping = new ClaimMapping();
    Claim claim = new Claim();
    claim.setClaimUri(userIdClaimURI);
    claimMapping.setRemoteClaim(claim);
    claimMapping.setLocalClaim(claim);
    return claimMappings.get(claimMapping);
  }