MarcoMala

schacPersonalUniqueCode 4 MyAcademicID

Mar 10th, 2021 (edited)
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.16 KB | None | 0 0
  1.     <AttributeDefinition xsi:type="ScriptedAttribute" id="schacPersonalUniqueCode">
  2.     <InputDataConnector ref="myLDAP" attributeNames="eduPersonAffiliation matricolaStudente schacPersonalUniqueCode"/>
  3.     <Script>
  4.            <![CDATA[
  5.             logger = Java.type("org.slf4j.LoggerFactory").getLogger("net.shibboleth.idp.attribute.resolver.schacPersonalUniqueCodeBuilder");
  6.             var isMyAcademicID = false;
  7.             var student = false;
  8.             var member = false;
  9.             var id = "https://proxy.prod.erasmus.eduteams.org/metadata/backend.xml";
  10.             // specify the child context of the root ProfileRequestContext
  11.             var subcontextClass = "net.shibboleth.idp.profile.context.RelyingPartyContext";
  12.             var subcontext;
  13.             // check if the MyAcademicID IAM Service
  14.             if (profileContext!== null) {
  15.                // check the entityID of the relying party
  16.                subcontext = profileContext.getSubcontext(subcontextClass);
  17.                if (subcontext !== null) {
  18.                   isMyAcademicID = subcontext.getRelyingPartyId().equals(id);
  19.                 }      
  20.             }
  21.             // check existance of matricolaStudente attribute and use it to enrich schacPersonalUniqueCode attribute
  22.             if (matricolaStudente != null && matricolaStudente.getValues().size() > 0) {
  23.                matricola = matricolaStudente.getValues().get(0);
  24.             } else {
  25.                matricola = null;
  26.             }
  27.             for ( i = 0; eduPersonAffiliation != null && i < eduPersonAffiliation.getValues().size(); i++ ){
  28.                  value = eduPersonAffiliation.getValues().get(i);
  29.                 if (value == 'student') student = true;
  30.                 if (value == 'member') member = true;
  31.             }
  32.             // if MyAcademicID
  33.             if (isMyAcademicID == true){
  34.                 if ( member == true && student == true ){
  35.                    logger.info('The user is able to receive ESI');
  36.                    schacPersonalUniqueCode.addValue('urn:schac:personalUniqueCode:int:esi:it:foo.bar:' + matricola);
  37.                 }
  38.             }
  39.           ]]>
  40.     </Script>
  41.     </AttributeDefinition>
Add Comment
Please, Sign In to add comment