|
29 | 29 |
|
30 | 30 | import java.io.IOException; |
31 | 31 | 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; |
33 | 37 |
|
34 | 38 | @RestController |
35 | 39 | public class IntrospectEndpoint extends SecureEndpoint { |
@@ -73,7 +77,7 @@ public ResponseEntity<Map<String, Object>> introspect(HttpServletRequest request |
73 | 77 | } |
74 | 78 | String clientId = clientAuthentication.getClientID().getValue(); |
75 | 79 | OpenIDClient resourceServer = openIDClientRepository.findOptionalByClientId(clientId) |
76 | | - .orElseThrow(() -> new UnknownClientException(clientId)); |
| 80 | + .orElseThrow(() -> new UnknownClientException(clientId)); |
77 | 81 | MDCContext.mdcContext("action", "Introspect", "rp", resourceServer.getClientId(), "accessTokenValue", accessTokenValue); |
78 | 82 |
|
79 | 83 | if (!secretsMatch((PlainClientSecret) clientAuthentication, resourceServer)) { |
@@ -109,12 +113,12 @@ public ResponseEntity<Map<String, Object>> introspect(HttpServletRequest request |
109 | 113 |
|
110 | 114 | if (isUserAccessToken) { |
111 | 115 | OpenIDClient openIDClient = openIDClientRepository.findOptionalByClientId(accessToken.getClientId()) |
112 | | - .orElseThrow(() -> new UnknownClientException(accessToken.getClientId())); |
| 116 | + .orElseThrow(() -> new UnknownClientException(accessToken.getClientId())); |
113 | 117 | if (!openIDClient.getClientId().equals(resourceServer.getClientId()) && |
114 | | - !openIDClient.getAllowedResourceServers().contains(resourceServer.getClientId())) { |
| 118 | + !openIDClient.getAllowedResourceServers().contains(resourceServer.getClientId())) { |
115 | 119 | 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())); |
118 | 122 | } |
119 | 123 | User user = tokenGenerator.decryptAccessTokenWithEmbeddedUserInfo(signedJWT); |
120 | 124 | result.put("updated_at", user.getUpdatedAt()); |
@@ -154,14 +158,15 @@ private boolean validPseudonymisation(Map<String, Object> userAttributes, OpenID |
154 | 158 | String eduId = (String) userAttributes.get("eduid"); |
155 | 159 | Map<String, String> pseudonymiseResult = attributePseudonymisation.pseudonymise(resourceServer, openIDClient, eduId) |
156 | 160 | .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 { |
159 | 166 | //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)); |
161 | 168 | return false; |
162 | 169 | } |
163 | | - userAttributes.putAll(pseudonymiseResult); |
164 | | - return true; |
165 | 170 | } |
166 | 171 |
|
167 | 172 | } |
0 commit comments