Skip to content

Commit 9dcfbc2

Browse files
committed
Fix OIDC claims script error handling
1 parent a97a026 commit 9dcfbc2

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

openam-oauth2/src/test/java/org/forgerock/openam/openidconnect/OidcClaimsExtensionTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2015-2016 ForgeRock AS.
15+
* Portions Copyright 2026 Wren Security
1516
*/
1617

1718
package org.forgerock.openam.openidconnect;
@@ -23,6 +24,7 @@
2324

2425
import com.iplanet.sso.SSOToken;
2526
import com.sun.identity.idm.AMIdentity;
27+
import com.sun.identity.idm.IdRepoException;
2628
import com.sun.identity.shared.debug.Debug;
2729
import java.util.ArrayList;
2830
import java.util.Collections;
@@ -192,6 +194,24 @@ public void testRequestedClaimsSelectNoScope() throws Exception {
192194
}
193195
}
194196

197+
@Test
198+
public void testIdRepoExceptionHandledGracefully() throws Exception {
199+
// Given
200+
Bindings variables = testBindings(asSet("profile"));
201+
when(identity.getAttribute("givenname")).thenThrow(new IdRepoException());
202+
when(identity.getAttribute("sn")).thenReturn(asSet("bloggs"));
203+
when(identity.getAttribute("preferredtimezone")).thenReturn(asSet("Europe/London"));
204+
when(identity.getAttribute("preferredlocale")).thenReturn(asSet("en"));
205+
when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs"));
206+
207+
// When
208+
UserInfoClaims result = scriptEvaluator.evaluateScript(script, variables);
209+
210+
// Then - given_name should be absent due to IdRepoException, other claims should be present
211+
assertThat(result.getValues()).doesNotContainKey("given_name");
212+
assertThat(result.getValues()).containsKeys("family_name", "name", "zoneinfo", "locale");
213+
}
214+
195215
private Bindings testBindings(Set<String> scopes) {
196216
return testBindings(scopes, new HashMap<String, Set<Object>>());
197217
}

openam-oauth2/src/test/resources/oidc-claims-extension.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2014-2016 ForgeRock AS.
15+
* Portions Copyright 2026 Wren Security
1516
*/
1617
import com.iplanet.sso.SSOException
1718
import com.sun.identity.idm.IdRepoException
@@ -89,16 +90,17 @@ if (logger.messageEnabled()) {
8990

9091
def computeClaim = { claim, requestedValues ->
9192
try {
92-
[ claim, claimAttributes.get(claim)(claim, identity, requestedValues) ]
93+
return [ claim, claimAttributes.get(claim)(claim, identity, requestedValues) ]
9394
} catch (IdRepoException e) {
9495
if (logger.warningEnabled()) {
95-
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve attribute=$attribute", e);
96+
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve claim=$claim", e);
9697
}
9798
} catch (SSOException e) {
9899
if (logger.warningEnabled()) {
99-
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve attribute=$attribute", e);
100+
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve claim=$claim", e);
100101
}
101102
}
103+
[ claim, null ]
102104
}
103105

104106
def computedClaims = scopes.findAll { s -> !"openid".equals(s) && scopeClaimsMap.containsKey(s) }.inject(claims) { map, s ->

openam-scripting/src/main/groovy/oidc-claims-extension.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2014-2016 ForgeRock AS.
15+
* Portions Copyright 2026 Wren Security
1516
*/
1617
import com.iplanet.sso.SSOException
1718
import com.sun.identity.idm.IdRepoException
@@ -89,16 +90,17 @@ if (logger.messageEnabled()) {
8990

9091
def computeClaim = { claim, requestedValues ->
9192
try {
92-
[ claim, claimAttributes.get(claim)(claim, identity, requestedValues) ]
93+
return [ claim, claimAttributes.get(claim)(claim, identity, requestedValues) ]
9394
} catch (IdRepoException e) {
9495
if (logger.warningEnabled()) {
95-
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve attribute=$attribute", e);
96+
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve claim=$claim", e);
9697
}
9798
} catch (SSOException e) {
9899
if (logger.warningEnabled()) {
99-
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve attribute=$attribute", e);
100+
logger.warning("OpenAMScopeValidator.getUserInfo(): Unable to retrieve claim=$claim", e);
100101
}
101102
}
103+
[ claim, null ]
102104
}
103105

104106
def computedClaims = scopes.findAll { s -> !"openid".equals(s) && scopeClaimsMap.containsKey(s) }.inject(claims) { map, s ->

0 commit comments

Comments
 (0)