<commit_before><?xml version="1.0" encoding="UTF-8"?>

<!-- BE SURE TO RE-GENERATE ALL SALT VALUES WHEN DEPLOYING THIS CONFIGURATION -->
<!-- BE SURE TO REPLACE ALL INSTANCES OF example.com WITH YOUR BASE SCOPE WHEN DEPLOYING THIS CONFIGURATION -->

<resolver:AttributeResolver xmlns:resolver="urn:mace:shibboleth:2.0:resolver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                            xmlns:pc="urn:mace:shibboleth:2.0:resolver:pc"    xmlns:ad="urn:mace:shibboleth:2.0:resolver:ad" 
                            xmlns:dc="urn:mace:shibboleth:2.0:resolver:dc"    xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
                            xmlns:sec="urn:mace:shibboleth:2.0:security" 
                            xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver classpath:/schema/shibboleth-2.0-attribute-resolver.xsd
                                                urn:mace:shibboleth:2.0:resolver:pc classpath:/schema/shibboleth-2.0-attribute-resolver-pc.xsd
                                                urn:mace:shibboleth:2.0:resolver:ad classpath:/schema/shibboleth-2.0-attribute-resolver-ad.xsd
                                                urn:mace:shibboleth:2.0:resolver:dc classpath:/schema/shibboleth-2.0-attribute-resolver-dc.xsd
                                                urn:mace:shibboleth:2.0:attribute:encoder classpath:/schema/shibboleth-2.0-attribute-encoder.xsd
                                                urn:mace:shibboleth:2.0:security classpath:/schema/shibboleth-2.0-security.xsd">

  <!-- Personal Details -->
  <resolver:AttributeDefinition id="transientId" xsi:type="ad:TransientId">
    <resolver:AttributeEncoder xsi:type="enc:SAML1StringNameIdentifier" nameFormat="urn:mace:shibboleth:1.0:nameIdentifier"/>
    <resolver:AttributeEncoder xsi:type="enc:SAML2StringNameID" nameFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:SAML2NameID" id="eduPersonTargetedID" nameIdFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" sourceAttributeID="storedID">
    <resolver:Dependency ref="VHRID" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1XMLObject" name="urn:oid:1.3.6.1.4.1.5923.192.168.127.12" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2XMLObject" name="urn:oid:1.3.6.1.4.1.5923.192.168.127.12" friendlyName="eduPersonTargetedID" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="auEduPersonSharedToken" xsi:type="ad:Simple" sourceAttributeID="shared_token">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:federation.org.au:attribute:auEduPersonSharedToken" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.27856.1.2.5" friendlyName="auEduPersonSharedToken" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="commonName" sourceAttributeID="cn">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:cn" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.3" friendlyName="cn" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="displayName" sourceAttributeID="display_name">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:displayName" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.16.840.1.113730.3.1.241" friendlyName="displayName" />
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="email" sourceAttributeID="email">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:mail" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:0.9.2342.19200300.100.1.3" friendlyName="mail" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="givenName" sourceAttributeID="given_name">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:givenName" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.42" friendlyName="givenName" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="surname" sourceAttributeID="surname">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:sn" />
     <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.4" friendlyName="sn" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="baseScope" xsi:type="ad:Simple" sourceAttributeID="baseScope"> 
    <resolver:Dependency ref="STATIC" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="organizationScope" xsi:type="ad:Simple" sourceAttributeID="org_scope"> 
    <resolver:Dependency ref="VHR" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="groupScope" xsi:type="ad:Simple" sourceAttributeID="group_scope"> 
    <resolver:Dependency ref="VHR" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition xsi:type="ad:Script" id="eduPersonAffiliation">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:eduPersonAffiliation" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1" friendlyName="eduPersonAffiliation" />

    <ad:Script>
      <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
                
        eduPersonAffiliation = new BasicAttribute("eduPersonAffiliation")

        if(edu_person_affiliation && edu_person_affiliation.getValues()) {
          affiliations = edu_person_affiliation.getValues().get(0).split(';');
          for ( i = 0; i < affiliations.length; i++ ){
              eduPersonAffiliation.getValues().add(affiliations[i]);
          }
        }
     ]]>
    </ad:Script>

  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Script" id="eduPersonScopedAffiliation">
    <resolver:Dependency ref="baseScope" />
    <resolver:Dependency ref="organizationScope" />
    <resolver:Dependency ref="groupScope" />
    <resolver:Dependency ref="VHR" />

    <resolver:AttributeEncoder xsi:type="enc:SAML1ScopedString" name="urn:mace:dir:attribute-def:eduPersonScopedAffiliation" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2ScopedString" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" friendlyName="eduPersonScopedAffiliation" />

     <ad:Script>
      <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
        
        scope = baseScope.getValues().get(0)
        if (organizationScope != null && organizationScope.getValues() != null && organizationScope.getValues().get(0) != null) {
          scope = organizationScope.getValues().get(0) + "." + scope
          if(groupScope != null && groupScope.getValues() != null && groupScope.getValues().get(0) != null)
            scope = groupScope.getValues().get(0) + "." + scope
        }
        
        eduPersonScopedAffiliation = new BasicAttribute("eduPersonScopedAffiliation")

        if(edu_person_affiliation && edu_person_affiliation.getValues()) {
          affiliations = edu_person_affiliation.getValues().get(0).split(';');
          for ( i = 0; i < affiliations.length; i++ ){
              eduPersonScopedAffiliation.getValues().add(new ScopedAttributeValue(affiliations[i], scope));
          }
        }
     ]]>
    </ad:Script>
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="eduPersonAssurance" sourceAttributeID="edu_person_assurance">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:eduPersonAssurance" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" friendlyName="eduPersonAssurance" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="eduPersonEntitlement" sourceAttributeID="edu_person_entitlement">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:eduPersonEntitlement" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.7" friendlyName="eduPersonEntitlement" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="telephoneNumber" sourceAttributeID="telephone_number">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:telephoneNumber" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.20" friendlyName="telephoneNumber" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="mobileNumber" sourceAttributeID="mobile_number">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:mobile" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:0.9.2342.19200300.100.1.41" friendlyName="mobile" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="postalAddress" sourceAttributeID="postal_address">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:postalAddress" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.16" friendlyName="postalAddress" />
  </resolver:AttributeDefinition>

  <!-- Organization Details -->
  <resolver:AttributeDefinition xsi:type="ad:Simple" id="organizationName" sourceAttributeID="display_name">
    <resolver:Dependency ref="VHRORG" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:o" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.10" friendlyName="o" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="organizationalUnit" sourceAttributeID="organizational_unit">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:ou" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.11" friendlyName="ou" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="homeOrganization" xsi:type="ad:Script">
    <resolver:Dependency ref="baseScope" />
    <resolver:Dependency ref="organizationScope" />
    <resolver:Dependency ref="groupScope" />
    <resolver:Dependency ref="VHR" />

    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:oid:1.3.6.1.4.1.25178.1.2.9" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.25178.1.2.9" friendlyName="homeOrganization" />

    <ad:Script>
    <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
        
        scope = baseScope.getValues().get(0)
        if (organizationScope != null && organizationScope.getValues() != null && organizationScope.getValues().get(0) != null) {
          scope = organizationScope.getValues().get(0) + "." + scope
          if(groupScope != null && groupScope.getValues() != null && groupScope.getValues().get(0) != null)
            scope = groupScope.getValues().get(0) + "." + scope
        }
        
        homeOrganization = new BasicAttribute("homeOrganization")
        homeOrganization.getValues().add(scope)
    ]]>
    </ad:Script>
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="homeOrganizationType" xsi:type="ad:Simple" sourceAttributeID="homeOrganizationType">
    <resolver:Dependency ref="STATIC" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:oid:1.3.6.1.4.1.25178.1.2.10" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.25178.1.2.10" friendlyName="homeOrganizationType" />
  </resolver:AttributeDefinition>

  <!-- Data Sources -->
  <resolver:DataConnector xsi:type="RelationalDatabase" xmlns="urn:mace:shibboleth:2.0:resolver:dc" id="VHR">
    <ContainerManagedConnection resourceName="java:comp/env/jdbc/VHR_IDP" />

    <QueryTemplate>
      <![CDATA[
        select  ms.login, ms.eptid_key, ms.cn, ms.display_name, ms.email, ms.edu_person_affiliation, 
                ms.edu_person_entitlement, ms.organizational_unit, ms.postal_address, ms.telephone_number,
                ms.shared_token, ms.edu_person_assurance, ms.given_name, ms.surname, ms.mobile_number, o.org_scope, g.group_scope
        from managed_subject as ms, organization as o, vhr_group as g 
        where ms.login='$requestContext.principalName' and ms.organization_id = o.id and ms.group_id = g.id;
      ]]>
    </QueryTemplate>

    <ResultCache elementTimeToLive="PT30M" />
  </resolver:DataConnector>

  <resolver:DataConnector xsi:type="RelationalDatabase" xmlns="urn:mace:shibboleth:2.0:resolver:dc" id="VHRORG">
    <ContainerManagedConnection resourceName="java:comp/env/jdbc/VHR_IDP" />

    <QueryTemplate>
      <![CDATA[
        select o.display_name, g.name 
        from managed_subject as ms, organization as o, vhr_group as g 
        where ms.login='$requestContext.principalName' and ms.organization_id = o.id and ms.group_id = g.id;
      ]]>
    </QueryTemplate>

    <ResultCache elementTimeToLive="PT30M" />
  </resolver:DataConnector>

  <resolver:DataConnector xsi:type="dc:StoredId" 
                          xmlns="urn:mace:shibboleth:2.0:resolver:dc"
                          id="VHRID"
                          sourceAttributeID="eptid_key"
                          generatedAttributeID="storedID"
                          salt="1234567890">
 
    <resolver:Dependency ref="VHR" />
    <!-- Error using ContainerManagedConnection is this mode so we use local connection -->
    <ApplicationManagedConnection jdbcDriver="com.mysql.jdbc.Driver"
                                   jdbcURL="jdbc:mysql://localhost:3306/virtualhome?useUnicode=yes&amp;characterEncoding=UTF-8"
                                   jdbcUserName="username"
                                   jdbcPassword="password" />
  </resolver:DataConnector>

  <resolver:DataConnector id="STATIC" xsi:type="dc:Static">
    <dc:Attribute id="homeOrganizationType">
      <dc:Value>urn:mace:terena.org:schac:homeOrganizationType:au:vho</dc:Value>
    </dc:Attribute>
    <dc:Attribute id="baseScope">
      <dc:Value>example.com</dc:Value>
    </dc:Attribute>
  </resolver:DataConnector>

  <resolver:PrincipalConnector xsi:type="pc:Transient" id="shibTransient" nameIDFormat="urn:mace:shibboleth:1.0:nameIdentifier"/>
  <resolver:PrincipalConnector xsi:type="pc:Transient" id="saml1Unspec" nameIDFormat="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"/>
  <resolver:PrincipalConnector xsi:type="pc:Transient" id="saml2Transient" nameIDFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>

</resolver:AttributeResolver>
<commit_msg>Conf: eduPersonEntitlement support multiple values<commit_after><?xml version="1.0" encoding="UTF-8"?>

<!-- BE SURE TO RE-GENERATE ALL SALT VALUES WHEN DEPLOYING THIS CONFIGURATION -->
<!-- BE SURE TO REPLACE ALL INSTANCES OF example.com WITH YOUR BASE SCOPE WHEN DEPLOYING THIS CONFIGURATION -->

<resolver:AttributeResolver xmlns:resolver="urn:mace:shibboleth:2.0:resolver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                            xmlns:pc="urn:mace:shibboleth:2.0:resolver:pc"    xmlns:ad="urn:mace:shibboleth:2.0:resolver:ad" 
                            xmlns:dc="urn:mace:shibboleth:2.0:resolver:dc"    xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
                            xmlns:sec="urn:mace:shibboleth:2.0:security" 
                            xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver classpath:/schema/shibboleth-2.0-attribute-resolver.xsd
                                                urn:mace:shibboleth:2.0:resolver:pc classpath:/schema/shibboleth-2.0-attribute-resolver-pc.xsd
                                                urn:mace:shibboleth:2.0:resolver:ad classpath:/schema/shibboleth-2.0-attribute-resolver-ad.xsd
                                                urn:mace:shibboleth:2.0:resolver:dc classpath:/schema/shibboleth-2.0-attribute-resolver-dc.xsd
                                                urn:mace:shibboleth:2.0:attribute:encoder classpath:/schema/shibboleth-2.0-attribute-encoder.xsd
                                                urn:mace:shibboleth:2.0:security classpath:/schema/shibboleth-2.0-security.xsd">

  <!-- Personal Details -->
  <resolver:AttributeDefinition id="transientId" xsi:type="ad:TransientId">
    <resolver:AttributeEncoder xsi:type="enc:SAML1StringNameIdentifier" nameFormat="urn:mace:shibboleth:1.0:nameIdentifier"/>
    <resolver:AttributeEncoder xsi:type="enc:SAML2StringNameID" nameFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:SAML2NameID" id="eduPersonTargetedID" nameIdFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" sourceAttributeID="storedID">
    <resolver:Dependency ref="VHRID" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" friendlyName="eduPersonTargetedID" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="auEduPersonSharedToken" xsi:type="ad:Simple" sourceAttributeID="shared_token">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:federation.org.au:attribute:auEduPersonSharedToken" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.27856.1.2.5" friendlyName="auEduPersonSharedToken" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="commonName" sourceAttributeID="cn">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:cn" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.3" friendlyName="cn" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="displayName" sourceAttributeID="display_name">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:displayName" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.16.840.1.113730.3.1.241" friendlyName="displayName" />
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="email" sourceAttributeID="email">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:mail" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:0.9.2342.19200300.100.1.3" friendlyName="mail" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="givenName" sourceAttributeID="given_name">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:givenName" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.42" friendlyName="givenName" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="surname" sourceAttributeID="surname">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:sn" />
     <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.4" friendlyName="sn" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="baseScope" xsi:type="ad:Simple" sourceAttributeID="baseScope"> 
    <resolver:Dependency ref="STATIC" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="organizationScope" xsi:type="ad:Simple" sourceAttributeID="org_scope"> 
    <resolver:Dependency ref="VHR" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="groupScope" xsi:type="ad:Simple" sourceAttributeID="group_scope"> 
    <resolver:Dependency ref="VHR" /> 
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition xsi:type="ad:Script" id="eduPersonAffiliation">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:eduPersonAffiliation" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1" friendlyName="eduPersonAffiliation" />

    <ad:Script>
      <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
                
        eduPersonAffiliation = new BasicAttribute("eduPersonAffiliation")

        if(edu_person_affiliation && edu_person_affiliation.getValues()) {
          affiliations = edu_person_affiliation.getValues().get(0).split(';');
          for ( i = 0; i < affiliations.length; i++ ){
              eduPersonAffiliation.getValues().add(affiliations[i]);
          }
        }
     ]]>
    </ad:Script>

  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Script" id="eduPersonScopedAffiliation">
    <resolver:Dependency ref="baseScope" />
    <resolver:Dependency ref="organizationScope" />
    <resolver:Dependency ref="groupScope" />
    <resolver:Dependency ref="VHR" />

    <resolver:AttributeEncoder xsi:type="enc:SAML1ScopedString" name="urn:mace:dir:attribute-def:eduPersonScopedAffiliation" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2ScopedString" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" friendlyName="eduPersonScopedAffiliation" />

     <ad:Script>
      <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
        
        scope = baseScope.getValues().get(0)
        if (organizationScope != null && organizationScope.getValues() != null && organizationScope.getValues().get(0) != null) {
          scope = organizationScope.getValues().get(0) + "." + scope
          if(groupScope != null && groupScope.getValues() != null && groupScope.getValues().get(0) != null)
            scope = groupScope.getValues().get(0) + "." + scope
        }
        
        eduPersonScopedAffiliation = new BasicAttribute("eduPersonScopedAffiliation")

        if(edu_person_affiliation && edu_person_affiliation.getValues()) {
          affiliations = edu_person_affiliation.getValues().get(0).split(';');
          for ( i = 0; i < affiliations.length; i++ ){
              eduPersonScopedAffiliation.getValues().add(new ScopedAttributeValue(affiliations[i], scope));
          }
        }
     ]]>
    </ad:Script>
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="eduPersonAssurance" sourceAttributeID="edu_person_assurance">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:eduPersonAssurance" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" friendlyName="eduPersonAssurance" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Script" id="eduPersonEntitlement">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:eduPersonEntitlement" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.7" friendlyName="eduPersonEntitlement" />

    <ad:Script>
      <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);

        eduPersonEntitlement = new BasicAttribute("eduPersonEntitlement")

        if(edu_person_entitlement && edu_person_entitlement.getValues() && 
            ( edu_person_entitlement.getValues().size() > 0 ) &&
            edu_person_entitlement.getValues().get(0) ) {
          entitlements = edu_person_entitlement.getValues().get(0).split(';');
          for ( i = 0; i < entitlements.length; i++ ){
              eduPersonEntitlement.getValues().add(entitlements[i]);
          }
        }
     ]]>
    </ad:Script>

  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="telephoneNumber" sourceAttributeID="telephone_number">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:telephoneNumber" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.20" friendlyName="telephoneNumber" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="mobileNumber" sourceAttributeID="mobile_number">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:mobile" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:0.9.2342.19200300.100.1.41" friendlyName="mobile" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="postalAddress" sourceAttributeID="postal_address">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:postalAddress" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.16" friendlyName="postalAddress" />
  </resolver:AttributeDefinition>

  <!-- Organization Details -->
  <resolver:AttributeDefinition xsi:type="ad:Simple" id="organizationName" sourceAttributeID="display_name">
    <resolver:Dependency ref="VHRORG" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:mace:dir:attribute-def:o" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.10" friendlyName="o" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition xsi:type="ad:Simple" id="organizationalUnit" sourceAttributeID="organizational_unit">
    <resolver:Dependency ref="VHR" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String"  name="urn:mace:dir:attribute-def:ou" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:2.5.4.11" friendlyName="ou" />
  </resolver:AttributeDefinition>

  <resolver:AttributeDefinition id="homeOrganization" xsi:type="ad:Script">
    <resolver:Dependency ref="baseScope" />
    <resolver:Dependency ref="organizationScope" />
    <resolver:Dependency ref="groupScope" />
    <resolver:Dependency ref="VHR" />

    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:oid:1.3.6.1.4.1.25178.1.2.9" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.25178.1.2.9" friendlyName="homeOrganization" />

    <ad:Script>
    <![CDATA[
        importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
        
        scope = baseScope.getValues().get(0)
        if (organizationScope != null && organizationScope.getValues() != null && organizationScope.getValues().get(0) != null) {
          scope = organizationScope.getValues().get(0) + "." + scope
          if(groupScope != null && groupScope.getValues() != null && groupScope.getValues().get(0) != null)
            scope = groupScope.getValues().get(0) + "." + scope
        }
        
        homeOrganization = new BasicAttribute("homeOrganization")
        homeOrganization.getValues().add(scope)
    ]]>
    </ad:Script>
  </resolver:AttributeDefinition> 

  <resolver:AttributeDefinition id="homeOrganizationType" xsi:type="ad:Simple" sourceAttributeID="homeOrganizationType">
    <resolver:Dependency ref="STATIC" />
    <resolver:AttributeEncoder xsi:type="enc:SAML1String" name="urn:oid:1.3.6.1.4.1.25178.1.2.10" />
    <resolver:AttributeEncoder xsi:type="enc:SAML2String" name="urn:oid:1.3.6.1.4.1.25178.1.2.10" friendlyName="homeOrganizationType" />
  </resolver:AttributeDefinition>

  <!-- Data Sources -->
  <resolver:DataConnector xsi:type="RelationalDatabase" xmlns="urn:mace:shibboleth:2.0:resolver:dc" id="VHR">
    <ContainerManagedConnection resourceName="java:comp/env/jdbc/VHR_IDP" />

    <QueryTemplate>
      <![CDATA[
        select  ms.login, ms.eptid_key, ms.cn, ms.display_name, ms.email, ms.edu_person_affiliation, 
                ms.edu_person_entitlement, ms.organizational_unit, ms.postal_address, ms.telephone_number,
                ms.shared_token, ms.edu_person_assurance, ms.given_name, ms.surname, ms.mobile_number, o.org_scope, g.group_scope
        from managed_subject as ms, organization as o, vhr_group as g 
        where ms.login='$requestContext.principalName' and ms.organization_id = o.id and ms.group_id = g.id;
      ]]>
    </QueryTemplate>

    <ResultCache elementTimeToLive="PT30M" />
  </resolver:DataConnector>

  <resolver:DataConnector xsi:type="RelationalDatabase" xmlns="urn:mace:shibboleth:2.0:resolver:dc" id="VHRORG">
    <ContainerManagedConnection resourceName="java:comp/env/jdbc/VHR_IDP" />

    <QueryTemplate>
      <![CDATA[
        select o.display_name, g.name 
        from managed_subject as ms, organization as o, vhr_group as g 
        where ms.login='$requestContext.principalName' and ms.organization_id = o.id and ms.group_id = g.id;
      ]]>
    </QueryTemplate>

    <ResultCache elementTimeToLive="PT30M" />
  </resolver:DataConnector>

  <resolver:DataConnector xsi:type="dc:StoredId" 
                          xmlns="urn:mace:shibboleth:2.0:resolver:dc"
                          id="VHRID"
                          sourceAttributeID="eptid_key"
                          generatedAttributeID="storedID"
                          salt="1234567890">
 
    <resolver:Dependency ref="VHR" />
    <!-- Error using ContainerManagedConnection is this mode so we use local connection -->
    <ApplicationManagedConnection jdbcDriver="com.mysql.jdbc.Driver"
                                   jdbcURL="jdbc:mysql://localhost:3306/virtualhome?useUnicode=yes&amp;characterEncoding=UTF-8"
                                   jdbcUserName="username"
                                   jdbcPassword="password" />
  </resolver:DataConnector>

  <resolver:DataConnector id="STATIC" xsi:type="dc:Static">
    <dc:Attribute id="homeOrganizationType">
      <dc:Value>urn:mace:terena.org:schac:homeOrganizationType:au:vho</dc:Value>
    </dc:Attribute>
    <dc:Attribute id="baseScope">
      <dc:Value>example.com</dc:Value>
    </dc:Attribute>
  </resolver:DataConnector>

  <resolver:PrincipalConnector xsi:type="pc:Transient" id="shibTransient" nameIDFormat="urn:mace:shibboleth:1.0:nameIdentifier"/>
  <resolver:PrincipalConnector xsi:type="pc:Transient" id="saml1Unspec" nameIDFormat="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"/>
  <resolver:PrincipalConnector xsi:type="pc:Transient" id="saml2Transient" nameIDFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>

</resolver:AttributeResolver>

{'fraction_non_alphanumeric': 0.14726189350231722, 'fraction_numerical': 0.025000788171127716, 'mean_word_length': 4.447363901768847, 'pattern_counts': {'":': 0, '<': 327, '<?xml version=': 2, '>': 323, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, 'pii_count': 64, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3819000', 'n_tokens_mistral': 10946, 'n_tokens_neox': 10401, 'n_words': 1162}