Skip to content

Commit bf6ddb1

Browse files
committed
BSR
1 parent b921b79 commit bf6ddb1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

oidc/src/main/java/oidc/endpoints/IntrospectEndpoint.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030
import java.io.IOException;
3131
import java.time.Clock;
32-
import java.util.*;
32+
import java.util.Collections;
33+
import java.util.List;
34+
import java.util.Map;
35+
import java.util.Optional;
36+
import java.util.TreeMap;
3337

3438
@RestController
3539
public class IntrospectEndpoint extends SecureEndpoint {
@@ -73,7 +77,7 @@ public ResponseEntity<Map<String, Object>> introspect(HttpServletRequest request
7377
}
7478
String clientId = clientAuthentication.getClientID().getValue();
7579
OpenIDClient resourceServer = openIDClientRepository.findOptionalByClientId(clientId)
76-
.orElseThrow(() -> new UnknownClientException(clientId));
80+
.orElseThrow(() -> new UnknownClientException(clientId));
7781
MDCContext.mdcContext("action", "Introspect", "rp", resourceServer.getClientId(), "accessTokenValue", accessTokenValue);
7882

7983
if (!secretsMatch((PlainClientSecret) clientAuthentication, resourceServer)) {
@@ -109,12 +113,12 @@ public ResponseEntity<Map<String, Object>> introspect(HttpServletRequest request
109113

110114
if (isUserAccessToken) {
111115
OpenIDClient openIDClient = openIDClientRepository.findOptionalByClientId(accessToken.getClientId())
112-
.orElseThrow(() -> new UnknownClientException(accessToken.getClientId()));
116+
.orElseThrow(() -> new UnknownClientException(accessToken.getClientId()));
113117
if (!openIDClient.getClientId().equals(resourceServer.getClientId()) &&
114-
!openIDClient.getAllowedResourceServers().contains(resourceServer.getClientId())) {
118+
!openIDClient.getAllowedResourceServers().contains(resourceServer.getClientId())) {
115119
throw new UnauthorizedException(
116-
String.format("RP %s is not allowed to use the API of resource server %s. Allowed resource servers are %s",
117-
accessToken.getClientId(), resourceServer.getClientId(), openIDClient.getAllowedResourceServers()));
120+
String.format("RP %s is not allowed to use the API of resource server %s. Allowed resource servers are %s",
121+
accessToken.getClientId(), resourceServer.getClientId(), openIDClient.getAllowedResourceServers()));
118122
}
119123
User user = tokenGenerator.decryptAccessTokenWithEmbeddedUserInfo(signedJWT);
120124
result.put("updated_at", user.getUpdatedAt());
@@ -154,14 +158,15 @@ private boolean validPseudonymisation(Map<String, Object> userAttributes, OpenID
154158
String eduId = (String) userAttributes.get("eduid");
155159
Map<String, String> pseudonymiseResult = attributePseudonymisation.pseudonymise(resourceServer, openIDClient, eduId)
156160
.orElseGet(Collections::emptyMap);
157-
if (pseudonymiseResult.containsKey("eduid") &&
158-
!pseudonymiseResult.containsKey("eduperson_principal_name")) {
161+
boolean hasEdupersonPrincipalName = pseudonymiseResult.containsKey("eduperson_principal_name");
162+
if (hasEdupersonPrincipalName) {
163+
userAttributes.putAll(pseudonymiseResult);
164+
return true;
165+
} else {
159166
//The user is not linked to an IdP belonging to this RS - only replace the pseudo eduid and not other attributes
160-
userAttributes.put("eduid", pseudonymiseResult.get("eduid"));
167+
userAttributes.put("eduid", pseudonymiseResult.getOrDefault("eduid", eduId));
161168
return false;
162169
}
163-
userAttributes.putAll(pseudonymiseResult);
164-
return true;
165170
}
166171

167172
}

0 commit comments

Comments
 (0)