public static String verifyNameIDFormat(String nameIDFormat,SPSSODescriptorElement spsso,IDPSSODescriptorElement idpsso) throws SAML2Exception {
  List spNameIDFormatList=spsso.getNameIDFormat();
  List idpNameIDFormatList=null;
  if (idpsso != null) {
    idpNameIDFormatList=idpsso.getNameIDFormat();
  }
  if ((nameIDFormat == null) || (nameIDFormat.length() == 0)) {
    if ((idpNameIDFormatList == null) || (idpNameIDFormatList.isEmpty())) {
      if ((spNameIDFormatList == null) || (spNameIDFormatList.isEmpty())) {
        return SAML2Constants.PERSISTENT;
      }
 else {
        return (String)spNameIDFormatList.get(0);
      }
    }
 else {
      if ((spNameIDFormatList == null) || (spNameIDFormatList.isEmpty())) {
        return (String)idpNameIDFormatList.get(0);
      }
 else {
        nameIDFormat=null;
        for (Iterator iter=spNameIDFormatList.iterator(); iter.hasNext(); ) {
          String spNameIDFormat=(String)iter.next();
          if (idpNameIDFormatList.contains(spNameIDFormat)) {
            nameIDFormat=spNameIDFormat;
            break;
          }
        }
        if (nameIDFormat == null) {
          throw new SAML2Exception(bundle.getString("unsupportedNameIDFormatIDPSP"));
        }
      }
    }
  }
 else {
    if (nameIDFormat.equals("persistent") || nameIDFormat.equals("transient")) {
      nameIDFormat=SAML2Constants.NAMEID_FORMAT_NAMESPACE + nameIDFormat;
    }
    if ((spNameIDFormatList != null) && (!spNameIDFormatList.isEmpty()) && (!spNameIDFormatList.contains(nameIDFormat))) {
      if (debug.messageEnabled()) {
        debug.message("SAML2Utils.verifyNameIDFormat: " + "NameIDFormat not supported by SP: " + nameIDFormat);
      }
      Object[] args={nameIDFormat};
      throw new SAML2Exception(BUNDLE_NAME,"unsupportedNameIDFormatSP",args);
    }
    if ((idpNameIDFormatList != null) && (!idpNameIDFormatList.isEmpty()) && (!idpNameIDFormatList.contains(nameIDFormat))) {
      if (debug.messageEnabled()) {
        debug.message("SAML2Utils.verifyNameIDFormat: " + "NameIDFormat not supported by IDP: " + nameIDFormat);
      }
      Object[] args={nameIDFormat};
      throw new SAML2Exception(BUNDLE_NAME,"unsupportedNameIDFormatIDP",args);
    }
  }
  return nameIDFormat;
}

public static String verifyNameIDFormat ( String nameIDFormat , SPSSODescriptorElement spsso , IDPSSODescriptorElement idpsso ) throws SAML2Exception { List spNameIDFormatList = spsso . getNameIDFormat ( ) ; List idpNameIDFormatList = null ; if ( idpsso != null ) { idpNameIDFormatList = idpsso . getNameIDFormat ( ) ; } if ( ( nameIDFormat == null ) || ( nameIDFormat . length ( ) == 0 ) ) { if ( ( idpNameIDFormatList == null ) || ( idpNameIDFormatList . isEmpty ( ) ) ) { if ( ( spNameIDFormatList == null ) || ( spNameIDFormatList . isEmpty ( ) ) ) { return SAML2Constants . PERSISTENT ; } else { return ( String ) spNameIDFormatList . get ( 0 ) ; } } else { if ( ( spNameIDFormatList == null ) || ( spNameIDFormatList . isEmpty ( ) ) ) { return ( String ) idpNameIDFormatList . get ( 0 ) ; } else { nameIDFormat = null ; for ( Iterator iter = spNameIDFormatList . iterator ( ) ; iter . hasNext ( ) ; ) { String spNameIDFormat = ( String ) iter . next ( ) ; if ( idpNameIDFormatList . contains ( spNameIDFormat ) ) { nameIDFormat = spNameIDFormat ; break ; } } if ( nameIDFormat == null ) { throw new SAML2Exception ( bundle . getString ( "unsupportedNameIDFormatIDPSP" ) ) ; } } } } else { if ( nameIDFormat . equals ( "persistent" ) || nameIDFormat . equals ( "transient" ) ) { nameIDFormat = SAML2Constants . NAMEID_FORMAT_NAMESPACE + nameIDFormat ; } if ( ( spNameIDFormatList != null ) && ( ! spNameIDFormatList . isEmpty ( ) ) && ( ! spNameIDFormatList . contains ( nameIDFormat ) ) ) { if ( debug . messageEnabled ( ) ) { debug . message ( "SAML2Utils.verifyNameIDFormat: " + "NameIDFormat not supported by SP: " + nameIDFormat ) ; } Object [ ] args = { nameIDFormat } ; throw new SAML2Exception ( BUNDLE_NAME , "unsupportedNameIDFormatSP" , args ) ; } if ( ( idpNameIDFormatList != null ) && ( ! idpNameIDFormatList . isEmpty ( ) ) && ( ! idpNameIDFormatList . contains ( nameIDFormat ) ) ) { if ( debug . messageEnabled ( ) ) { debug . message ( "SAML2Utils.verifyNameIDFormat: " + "NameIDFormat not supported by IDP: " + nameIDFormat ) ; } Object [ ] args = { nameIDFormat } ; throw new SAML2Exception ( BUNDLE_NAME , "unsupportedNameIDFormatIDP" , args ) ; } } return nameIDFormat ; }
verifies specified name id format and returns it . if specified name id format is empty , returns name id foramt supported by both idp and sp .
