1212import org .springframework .web .util .UriComponentsBuilder ;
1313
1414import java .net .URI ;
15- import java .util .Collections ;
16- import java .util .HashMap ;
17- import java .util .Map ;
18- import java .util .Optional ;
15+ import java .util .*;
1916
2017@ Service
2118public class AttributePseudonymisation {
@@ -54,13 +51,23 @@ public AttributePseudonymisation(@Value("${eduid.uri}") URI eduIdUri,
5451 */
5552 public Optional <Map <String , String >> pseudonymise (OpenIDClient resourceServer , OpenIDClient openIDClient , String eduId ) {
5653 boolean resourceServerEquals = resourceServer .getClientId ().equals (openIDClient .getClientId ());
54+ String resourceServerInstitutionGuid = resourceServer .getInstitutionGuid ();
55+ String clientInstitutionGuid = openIDClient .getInstitutionGuid ();
56+ boolean institutionGuidEquals = StringUtils .hasText (resourceServerInstitutionGuid ) &&
57+ Objects .equals (resourceServerInstitutionGuid , clientInstitutionGuid );
5758
5859 LOG .debug (String .format ("Starting to pseudonymise for RS %s and openIDclient %s. " +
59- "Enabled is %s, eduId is %s, resourceServerEquals is %s" ,
60- resourceServer .getClientId (), openIDClient .getClientId (), enabled , eduId , resourceServerEquals ));
60+ "Enabled is %s, eduId is %s, resourceServerEquals is %s, institutionGuidEquals is %s" ,
61+ resourceServer .getClientId (),
62+ openIDClient .getClientId (),
63+ enabled ,
64+ eduId ,
65+ resourceServerEquals ,
66+ institutionGuidEquals
67+ ));
6168
62- if (!enabled || !StringUtils .hasText (eduId ) || resourceServerEquals ) {
63- LOG .debug ("Returning empty result for 'pseudonymise'" );
69+ if (!enabled || !StringUtils .hasText (eduId ) || resourceServerEquals || institutionGuidEquals ) {
70+ LOG .debug ("Skipping attribute manipulation and returning empty result for 'pseudonymise'" );
6471 return Optional .empty ();
6572 }
6673 Map <String , String > result = new HashMap <>();
@@ -69,7 +76,7 @@ public Optional<Map<String, String>> pseudonymise(OpenIDClient resourceServer, O
6976 String uriString = UriComponentsBuilder .fromUri (eduIdUri )
7077 .queryParam ("eduid" , eduId )
7178 .queryParam ("sp_entity_id" , resourceServer .getClientId ())
72- .queryParam ("sp_institution_guid" , resourceServer . getInstitutionGuid () )
79+ .queryParam ("sp_institution_guid" , resourceServerInstitutionGuid )
7380 .toUriString ();
7481 ResponseEntity <Map <String , String >> responseEntity =
7582 restTemplate .exchange (uriString , HttpMethod .GET , requestEntity , new ParameterizedTypeReference <>() {
0 commit comments