[java-idp-oidc] branch main updated: Null cleanup of test code in impl-module.
Henri Mikkonen
henri.mikkonen at iki.fi
Mon Apr 1 17:01:52 UTC 2024
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=fbfcf1c413c36816417e07678cfe6a1c83c7afc8
The following commit(s) were added to refs/heads/main by this push:
new fbfcf1c4 Null cleanup of test code in impl-module.
fbfcf1c4 is described below
commit fbfcf1c413c36816417e07678cfe6a1c83c7afc8
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Mon Apr 1 20:01:40 2024 +0300
Null cleanup of test code in impl-module.
---
.../impl/IssueRegistrationAccessTokenTest.java | 5 +-
.../AttributeInOIDCRequestedClaimsMatcherTest.java | 10 +-
.../impl/AttributeOIDCScopePolicyRuleTest.java | 1 +
...ExtractClientAuthenticationFromRequestTest.java | 54 ++++++----
.../op/authn/impl/JWTCredentialValidatorTest.java | 26 +++--
.../OIDCClientInfoCredentialValidatorTest.java | 29 ++---
.../impl/ValidateClientAuthenticationTypeTest.java | 10 +-
.../impl/OIDCAuthenticationRequestDecoderTest.java | 19 +++-
.../OIDCClientRegistrationRequestDecoderTest.java | 6 +-
.../decoding/impl/OIDCTokenRequestDecoderTest.java | 8 +-
.../impl/OIDCUserInfoRequestDecoderTest.java | 4 +-
...OIDCBackChannelLogoutPropagationActionTest.java | 5 +-
.../impl/BaseOIDCLogoutPropagationActionTest.java | 9 +-
.../impl/BaseOIDCRpInitiatedLogoutActionTest.java | 11 +-
.../impl/ExecuteBackChannelLogoutRequestTest.java | 1 +
.../impl/FormOutboundLogoutRequestMessageTest.java | 9 +-
.../impl/FormRpInitiatedLogoutResponseTest.java | 2 +-
...pInitiatedLogoutResponseMessageContextTest.java | 3 +-
.../impl/PopulateRpInitiatedLogoutContextTest.java | 15 +--
.../impl/PrepareBackChannelLogoutRequestTest.java | 1 +
.../impl/ProcessRpInitiatedLogoutRequestTest.java | 1 +
.../logout/profile/impl/RevokeTokenChainTest.java | 1 +
.../profile/impl/ValidateIdTokenHintTest.java | 7 +-
.../impl/CredentialMetadataValueResolverTest.java | 1 +
...amicFilesystemProviderMetadataResolverTest.java | 3 +
.../impl/FilesystemMetadataValueResolverTest.java | 5 +-
.../FilesystemProviderMetdataResolverTest.java | 1 +
.../OAuth2AuthorizationRequestDecoderTest.java | 33 ++++--
.../OAuth2IntrospectionRequestDecoderTest.java | 11 +-
.../impl/OAuth2RevocationRequestDecoderTest.java | 10 +-
.../impl/OAuth2RevocationErrorResponseTest.java | 8 --
.../SetEntityIdToSAMLPeerEntityContextTest.java | 22 ++--
.../oauth2/profile/impl/BuildAccessTokenTest.java | 27 ++---
.../op/oauth2/profile/impl/RevokeTokenTest.java | 99 ++++++++---------
.../SetAuthorizationCodeToResponseContextTest.java | 64 +++++++----
.../SetRequestObjectToResponseContextTest.java | 13 ++-
.../oauth2/profile/impl/ValidateAudienceTest.java | 8 +-
.../profile/impl/ValidateRedirectURITest.java | 10 +-
.../profile/impl/ValidateRequestObjectTest.java | 55 +++++-----
.../profile/impl/ValidateResponseTypeTest.java | 4 +-
.../op/oauth2/profile/impl/ValidateScopeTest.java | 45 ++++----
.../flow/AbstractIssuedJWTSecurityTest.java | 4 +-
.../op/profile/flow/AbstractOidcApiFlowTest.java | 3 +
.../oidc/op/profile/flow/AbstractOidcFlowTest.java | 11 +-
.../oidc/op/profile/flow/AuthorizeFlowTest.java | 66 ++++++++----
.../flow/ClientCredentialsTokenFlowTest.java | 27 +++--
.../oidc/op/profile/flow/EndSessionFlowTest.java | 10 +-
.../oidc/op/profile/flow/IdTokenHintJWETest.java | 2 +
.../oidc/op/profile/flow/IdTokenHintJWSTest.java | 2 +
.../op/profile/flow/IntrospectionFlowTest.java | 2 +
.../flow/IssueRegistrationAccessTokenFlowTest.java | 5 +-
.../op/profile/flow/IssuedEncryptedJWTTest.java | 1 +
.../op/profile/flow/LogoutPropagationFlowTest.java | 19 ++--
.../oidc/op/profile/flow/RegistrationFlowTest.java | 77 ++++++++------
.../flow/RegistrationManagementFlowTest.java | 8 +-
.../oidc/op/profile/flow/RequestObjectJWETest.java | 16 +--
.../oidc/op/profile/flow/RequestObjectJWSTest.java | 16 +--
.../oidc/op/profile/flow/RevocationFlowTest.java | 1 +
.../plugin/oidc/op/profile/flow/TokenFlowTest.java | 61 +++++++----
.../plugin/oidc/op/profile/flow/UserInfoTest.java | 51 +++++----
...bstractOIDCAuthenticationRequestActionTest.java | 1 +
...stractOIDCAuthenticationResponseActionTest.java | 7 +-
.../impl/AbstractOIDCTokenResponseActionTest.java | 9 +-
.../impl/AddAccessTokenHashToIDTokenTest.java | 9 +-
.../oidc/op/profile/impl/AddAcrToIDTokenTest.java | 9 +-
.../profile/impl/AddAttributesToClaimsSetTest.java | 45 ++++----
.../op/profile/impl/AddAuthTimeToIDTokenTest.java | 9 +-
.../AddAuthorizationCodeHashToIDTokenTest.java | 8 +-
.../impl/AddGrantTypeToClientMetadataTest.java | 15 +--
.../oidc/op/profile/impl/AddIDTokenShellTest.java | 17 +--
.../profile/impl/AddJwksToClientMetadataTest.java | 4 +-
.../op/profile/impl/AddNonceToIDTokenTest.java | 5 +-
.../AddRemainingClaimsToClientMetadataTest.java | 8 +-
...tSecurityConfigurationToClientMetadataTest.java | 4 +-
.../impl/AddResponseTypesToClientMetadataTest.java | 11 +-
.../profile/impl/AddScopeToClientMetadataTest.java | 7 --
...dSecurityConfigurationToClientMetadataTest.java | 5 +-
.../AddTokenDeliveryAttributesToClaimsSetTest.java | 18 ++--
.../impl/BaseOIDCClientMetadataPopulationTest.java | 22 ++--
.../profile/impl/BaseOIDCResponseActionTest.java | 25 +++--
.../profile/impl/BuildClientInformationTest.java | 22 +++-
.../impl/BuildJSONErrorResponseFromEventTest.java | 18 ++--
.../op/profile/impl/CheckRedirectUrisTest.java | 6 +-
...mOutboundAuthenticationResponseMessageTest.java | 4 +-
.../impl/FormOutboundDiscoveryResponseTest.java | 16 ++-
.../impl/FormOutboundTokenResponseMessageTest.java | 10 +-
.../impl/InitializeAuthenticationContextTest.java | 40 ++-----
...ndAuthenticationResponseMessageContextTest.java | 117 +++++++++++++++------
.../impl/InitializeRelyingPartyContextTest.java | 39 ++-----
.../profile/impl/InitializeSubjectContextTest.java | 3 +-
...nitializeUnverifiedRelyingPartyContextTest.java | 11 +-
.../impl/ManipulateClaimsForIDTokenTest.java | 24 ++++-
.../impl/ProcessRequestedAuthnContextTest.java | 3 +
...eferenceFromAuthzCodeToResponseContextTest.java | 1 +
...ContextClassReferenceToResponseContextTest.java | 20 ++--
...SetAuthenticationTimeToResponseContextTest.java | 1 +
.../SetConsentFromTokenToResponseContextTest.java | 2 +
.../impl/SetConsentToResponseContextTest.java | 19 ++--
.../impl/SetRefreshTokenToResponseContextTest.java | 109 +++++++++++++------
.../SetRequestedClaimsToResponseContextTest.java | 10 +-
...SectorIdentifierForAttributeResolutionTest.java | 36 +++----
.../impl/SetSessionIdToResponseContextTest.java | 16 +--
.../impl/SetSubjectToResponseContextTest.java | 11 +-
...ryAttributesFromTokenToResponseContextTest.java | 50 +++++----
...kenDeliveryAttributesToResponseContextTest.java | 14 +--
.../oidc/op/profile/impl/ValidateGrantTest.java | 90 ++++++++--------
.../op/profile/impl/ValidateGrantTypeTest.java | 17 +--
.../oidc/op/profile/impl/ValidatePKCETest.java | 16 ++-
...tributeResolutionSubjectLookupFunctionTest.java | 26 ++---
...tTokenRevocationLifetimeLookupStrategyTest.java | 4 +
...teredClientResponseTypesLookupFunctionTest.java | 21 +++-
.../logic/MetadataValueEqualsConditionTest.java | 1 +
.../logic/SubjectActivationConditionTest.java | 5 +-
.../profile/spring/TokenExtensionFactoryTest.java | 1 +
...adProviderResolverServiceConfigurationTest.java | 3 +-
.../impl/OIDCRPSessionCreationStrategyTest.java | 5 +
.../AbstractOIDCUserInfoResponseActionTest.java | 9 +-
.../profile/impl/AddUserInfoShellTest.java | 48 ++++-----
.../FormOutboundUserInfoResponseMessageTest.java | 30 ++++--
.../profile/impl/ParseAccessTokenTest.java | 10 +-
.../profile/impl/ValidateAccessTokenTest.java | 3 +
121 files changed, 1307 insertions(+), 860 deletions(-)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessTokenTest.java
index 1f76e913..e3d12f28 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessTokenTest.java
@@ -61,6 +61,7 @@ import net.shibboleth.shared.security.DataSealerException;
/**
* Unit tests for {@link IssueRegistrationAccessToken}.
*/
+ at SuppressWarnings("null")
public class IssueRegistrationAccessTokenTest {
private IssueRegistrationAccessToken action;
@@ -230,10 +231,11 @@ public class IssueRegistrationAccessTokenTest {
protected void validateToken(final String policyId, final String clientId) throws DataSealerException, JsonMappingException, JsonProcessingException {
final Instant start = Instant.now();
- final Object rawMessage = prc.getOutboundMessageContext().getMessage();
+ final Object rawMessage = prc.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(rawMessage);
Assert.assertTrue(rawMessage instanceof AccessTokenResponse);
final AccessTokenResponse tokenResponse = (AccessTokenResponse) rawMessage;
+ assert tokenResponse != null;
Assert.assertNotNull(tokenResponse.getTokens());
final BearerAccessToken accessToken = tokenResponse.getTokens().getBearerAccessToken();
Assert.assertNotNull(accessToken);
@@ -246,6 +248,7 @@ public class IssueRegistrationAccessTokenTest {
Assert.assertEquals(claimsSet.getClientId(), clientId);
final Map<String, MetadataPolicy> tokenPolicy = claimsSet.getMetadata();
Assert.assertNotNull(tokenPolicy);
+ assert tokenPolicy != null;
Assert.assertEquals(tokenPolicy.size(), 1);
Assert.assertTrue(tokenPolicy.containsKey("claim1"));
final MetadataPolicy claimPolicy = tokenPolicy.get("claim1");
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/matcher/impl/AttributeInOIDCRequestedClaimsMatcherTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/matcher/impl/AttributeInOIDCRequestedClaimsMatcherTest.java
index 0fe3830a..b9476883 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/matcher/impl/AttributeInOIDCRequestedClaimsMatcherTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/matcher/impl/AttributeInOIDCRequestedClaimsMatcherTest.java
@@ -48,6 +48,7 @@ import com.nimbusds.openid.connect.sdk.claims.ClaimsSetRequest;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
+ at SuppressWarnings("null")
public class AttributeInOIDCRequestedClaimsMatcherTest {
private AttributeInOIDCRequestedClaimsMatcher matcher;
@@ -125,6 +126,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
matcher.initialize();
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -135,6 +137,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
prc.setOutboundMessageContext(null);
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -142,9 +145,10 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
public void testNoOidcMsgCtx() throws Exception {
setUp(false, false);
matcher.initialize();
- prc.getOutboundMessageContext().removeSubcontext(OIDCAuthenticationResponseContext.class);
+ prc.ensureOutboundMessageContext().removeSubcontext(OIDCAuthenticationResponseContext.class);
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -154,6 +158,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
matcher.initialize();
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -164,6 +169,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
matcher.initialize();
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -188,6 +194,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
matcher.initialize();
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
@@ -198,6 +205,7 @@ public class AttributeInOIDCRequestedClaimsMatcherTest {
matcher.initialize();
final Set<IdPAttributeValue> result = matcher.getMatchingValues(attribute, filtercontext);
Assert.assertNotNull(result);
+ assert result != null;
Assert.assertEquals(result.size(), 0);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/policyrule/impl/AttributeOIDCScopePolicyRuleTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/policyrule/impl/AttributeOIDCScopePolicyRuleTest.java
index da7efaf2..dfd79b96 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/policyrule/impl/AttributeOIDCScopePolicyRuleTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/attribute/filter/policyrule/impl/AttributeOIDCScopePolicyRuleTest.java
@@ -29,6 +29,7 @@ import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.Scope;
+ at SuppressWarnings("null")
public class AttributeOIDCScopePolicyRuleTest {
private AttributeOIDCScopePolicyRule rule;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ExtractClientAuthenticationFromRequestTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ExtractClientAuthenticationFromRequestTest.java
index eeacf63d..af727e90 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ExtractClientAuthenticationFromRequestTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ExtractClientAuthenticationFromRequestTest.java
@@ -128,13 +128,17 @@ public class ExtractClientAuthenticationFromRequestTest {
ActionTestingSupport.assertProceedEvent(e);
final OAuth2ClientAuthenticationContext oauth =
- prc.getSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
Assert.assertNotNull(oauth);
- Assert.assertEquals(oauth.getClientAuthentication().getClientID(), clientId);
- Assert.assertEquals(
- oauth.getClientAuthentication().getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
- final UsernamePasswordContext up = oauth.getParent().getSubcontext(UsernamePasswordContext.class);
+ assert oauth != null;
+ final ClientAuthentication clientAuthentication = oauth.getClientAuthentication();
+ assert clientAuthentication != null;
+ Assert.assertEquals(clientAuthentication.getClientID(), clientId);
+ Assert.assertEquals(clientAuthentication.getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
+ final UsernamePasswordContext up = prc.ensureSubcontext(AuthenticationContext.class)
+ .getSubcontext(UsernamePasswordContext.class);
Assert.assertNotNull(up);
+ assert up != null;
Assert.assertEquals(up.getUsername(), clientId.getValue());
Assert.assertEquals(up.getPassword(), clientSecret.getValue());
}
@@ -146,13 +150,17 @@ public class ExtractClientAuthenticationFromRequestTest {
ActionTestingSupport.assertProceedEvent(e);
final OAuth2ClientAuthenticationContext oauth =
- prc.getSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
Assert.assertNotNull(oauth);
- Assert.assertEquals(oauth.getClientAuthentication().getClientID(), clientId);
- Assert.assertEquals(
- oauth.getClientAuthentication().getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_POST);
- final UsernamePasswordContext up = oauth.getParent().getSubcontext(UsernamePasswordContext.class);
+ assert oauth != null;
+ final ClientAuthentication clientAuthentication = oauth.getClientAuthentication();
+ assert clientAuthentication != null;
+ Assert.assertEquals(clientAuthentication.getClientID(), clientId);
+ Assert.assertEquals(clientAuthentication.getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_POST);
+ final UsernamePasswordContext up = prc.ensureSubcontext(AuthenticationContext.class)
+ .getSubcontext(UsernamePasswordContext.class);
Assert.assertNotNull(up);
+ assert up != null;
Assert.assertEquals(up.getUsername(), clientId.getValue());
Assert.assertEquals(up.getPassword(), clientSecret.getValue());
}
@@ -164,12 +172,15 @@ public class ExtractClientAuthenticationFromRequestTest {
ActionTestingSupport.assertProceedEvent(e);
final OAuth2ClientAuthenticationContext oauth =
- prc.getSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
Assert.assertNotNull(oauth);
- Assert.assertEquals(oauth.getClientAuthentication().getClientID(), clientId);
- Assert.assertEquals(
- oauth.getClientAuthentication().getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_JWT);
- final UsernamePasswordContext up = oauth.getParent().getSubcontext(UsernamePasswordContext.class);
+ assert oauth != null;
+ final ClientAuthentication clientAuthentication = oauth.getClientAuthentication();
+ assert clientAuthentication != null;
+ Assert.assertEquals(clientAuthentication.getClientID(), clientId);
+ Assert.assertEquals(clientAuthentication.getMethod(), ClientAuthenticationMethod.CLIENT_SECRET_JWT);
+ final UsernamePasswordContext up = prc.ensureSubcontext(AuthenticationContext.class)
+ .getSubcontext(UsernamePasswordContext.class);
Assert.assertNull(up);
}
@@ -180,12 +191,15 @@ public class ExtractClientAuthenticationFromRequestTest {
ActionTestingSupport.assertProceedEvent(e);
final OAuth2ClientAuthenticationContext oauth =
- prc.getSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).getSubcontext(OAuth2ClientAuthenticationContext.class);
Assert.assertNotNull(oauth);
- Assert.assertEquals(oauth.getClientAuthentication().getClientID(), clientId);
- Assert.assertEquals(
- oauth.getClientAuthentication().getMethod(), ClientAuthenticationMethod.PRIVATE_KEY_JWT);
- final UsernamePasswordContext up = oauth.getParent().getSubcontext(UsernamePasswordContext.class);
+ assert oauth != null;
+ final ClientAuthentication clientAuthentication = oauth.getClientAuthentication();
+ assert clientAuthentication != null;
+ Assert.assertEquals(clientAuthentication.getClientID(), clientId);
+ Assert.assertEquals(clientAuthentication.getMethod(), ClientAuthenticationMethod.PRIVATE_KEY_JWT);
+ final UsernamePasswordContext up = prc.ensureSubcontext(AuthenticationContext.class)
+ .getSubcontext(UsernamePasswordContext.class);
Assert.assertNull(up);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/JWTCredentialValidatorTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/JWTCredentialValidatorTest.java
index 624a5e4c..8ca18723 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/JWTCredentialValidatorTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/JWTCredentialValidatorTest.java
@@ -57,6 +57,7 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.idp.authn.AuthenticationResult;
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.impl.ValidateCredentials;
@@ -129,7 +130,7 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
constructClaimsValidator((HttpServletRequest) src.getExternalContext().getNativeRequest(), replayCache);
final DefaultOAuth2TokenConfiguration profile = new DefaultOAuth2TokenConfiguration();
profile.setClaimsValidator(claimsValidator);
- prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(profile);
+ prc.ensureSubcontext(RelyingPartyContext.class).setProfileConfig(profile);
validator = new JWTCredentialValidator();
validator.setId("test");
@@ -151,7 +152,7 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
final OIDCClientInformation clientInformation =
new OIDCClientInformation(clientId, new Date(), metadata, clientSecret);
oidcContext.setClientInformation(clientInformation);
- prc.getInboundMessageContext().addSubcontext(oidcContext);
+ prc.ensureInboundMessageContext().addSubcontext(oidcContext);
}
protected void initializeTokenRequest(final ClientAuthenticationMethod method, final SignedJWT jwt,
@@ -193,6 +194,7 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
final AudienceClaimsValidator audValidator = new AudienceClaimsValidator();
audValidator.setAudienceLookupStrategy((prc, claims) -> httpRequest.getRequestURL().toString());
final JWTIdentifierClaimsValidator jitValidator = new JWTIdentifierClaimsValidator();
+ assert replayCache != null;
jitValidator.setReplayCache(replayCache);
claimsValidation.setClaimValidators(List.of(expValidator, iatValidator, issValidator, subValidator,
audValidator, jitValidator));
@@ -275,8 +277,8 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
@Test
public void testNoClaimsValidator() throws Exception {
- ((AbstractOAuth2ClientAuthenticableProfileConfiguration) prc.getSubcontext(
- RelyingPartyContext.class).getProfileConfig()).setClaimsValidator(null);
+ ((AbstractOAuth2ClientAuthenticableProfileConfiguration) prc.ensureSubcontext(
+ RelyingPartyContext.class).ensureProfileConfig()).setClaimsValidator(null);
testFailingJwtAuth(ClientAuthenticationMethod.CLIENT_SECRET_JWT,
createSecretJWT(validClaimsSet()), false, true);
}
@@ -288,9 +290,11 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
- Assert.assertNotNull(ac.getAuthenticationResult());
- Assert.assertEquals(ac.getAuthenticationResult().getSubject().getPrincipals(UsernamePrincipal.class).iterator()
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
+ final AuthenticationResult ar = ac.getAuthenticationResult();
+ Assert.assertNotNull(ar);
+ assert ar != null;
+ Assert.assertEquals(ar.getSubject().getPrincipals(UsernamePrincipal.class).iterator()
.next().getName(), clientId.getValue());
}
@@ -301,9 +305,11 @@ public class JWTCredentialValidatorTest extends BaseAuthenticationContextTest {
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
- Assert.assertNotNull(ac.getAuthenticationResult());
- Assert.assertEquals(ac.getAuthenticationResult().getSubject().getPrincipals(UsernamePrincipal.class).iterator()
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
+ final AuthenticationResult ar = ac.getAuthenticationResult();
+ Assert.assertNotNull(ar);
+ assert ar != null;
+ Assert.assertEquals(ar.getSubject().getPrincipals(UsernamePrincipal.class).iterator()
.next().getName(), clientId.getValue());
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/OIDCClientInfoCredentialValidatorTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/OIDCClientInfoCredentialValidatorTest.java
index 09752f39..62d60f89 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/OIDCClientInfoCredentialValidatorTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/OIDCClientInfoCredentialValidatorTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
import javax.security.auth.login.LoginException;
+import net.shibboleth.idp.authn.AuthenticationResult;
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.context.AuthenticationErrorContext;
@@ -82,7 +83,7 @@ public class OIDCClientInfoCredentialValidatorTest extends BaseAuthenticationCon
final OIDCClientInformation clientInformation =
new OIDCClientInformation(clientId, new Date(), metadata, secret);
oidcContext.setClientInformation(clientInformation);
- prc.getInboundMessageContext().addSubcontext(oidcContext);
+ prc.ensureInboundMessageContext().addSubcontext(oidcContext);
}
@Test public void testMissingFlow() {
@@ -91,14 +92,14 @@ public class OIDCClientInfoCredentialValidatorTest extends BaseAuthenticationCon
}
@Test public void testMissingUser() {
- prc.getSubcontext(AuthenticationContext.class).setAttemptedFlow(authenticationFlows.get(0));
+ prc.ensureSubcontext(AuthenticationContext.class).setAttemptedFlow(authenticationFlows.get(0));
final Event event = action.execute(src);
ActionTestingSupport.assertEvent(event, AuthnEventIds.NO_CREDENTIALS);
}
@Test public void testMissingUser2() {
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
ac.setAttemptedFlow(authenticationFlows.get(0));
ac.ensureSubcontext(UsernamePasswordContext.class);
@@ -107,33 +108,35 @@ public class OIDCClientInfoCredentialValidatorTest extends BaseAuthenticationCon
}
@Test public void testBadPassword() {
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
ac.setAttemptedFlow(authenticationFlows.get(0));
ac.ensureSubcontext(UsernamePasswordContext.class).setUsername(clientId.getValue()).setPassword("foo");
final Event event = action.execute(src);
ActionTestingSupport.assertEvent(event, "InvalidPassword");
- final AuthenticationErrorContext errorCtx = ac.getSubcontext(AuthenticationErrorContext.class);
+ final AuthenticationErrorContext errorCtx = ac.ensureSubcontext(AuthenticationErrorContext.class);
Assert.assertTrue(errorCtx.getExceptions().get(0) instanceof LoginException);
Assert.assertFalse(errorCtx.isClassifiedError("UnknownUsername"));
Assert.assertTrue(errorCtx.isClassifiedError("InvalidPassword"));
}
@Test public void testAuthorized() {
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
ac.setAttemptedFlow(authenticationFlows.get(0));
ac.ensureSubcontext(UsernamePasswordContext.class).setUsername(clientId.getValue()).setPassword(clientSecret.getValue());
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(ac.getAuthenticationResult());
- Assert.assertEquals(ac.getAuthenticationResult().getSubject().getPrincipals(UsernamePrincipal.class).iterator()
+ final AuthenticationResult ar = ac.getAuthenticationResult();
+ Assert.assertNotNull(ar);
+ assert ar != null;
+ Assert.assertEquals(ar.getSubject().getPrincipals(UsernamePrincipal.class).iterator()
.next().getName(), clientId.getValue());
}
@Test public void testAuthorizedSHA2() throws NoSuchAlgorithmException {
- final AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext ac = prc.ensureSubcontext(AuthenticationContext.class);
ac.setAttemptedFlow(authenticationFlows.get(0));
ac.ensureSubcontext(UsernamePasswordContext.class).setUsername(clientId.getValue()).setPassword(clientSecret.getValue());
@@ -141,13 +144,15 @@ public class OIDCClientInfoCredentialValidatorTest extends BaseAuthenticationCon
final Secret secret = new Secret("{SHA2}" + new StringDigester("SHA-256", OutputFormat.BASE64).apply(clientSecret.getValue()));
final OIDCClientInformation clientInformation =
new OIDCClientInformation(clientId, new Date(), metadata, secret);
- prc.getInboundMessageContext().getSubcontext(OIDCMetadataContext.class).setClientInformation(clientInformation);
+ prc.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class).setClientInformation(clientInformation);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(ac.getAuthenticationResult());
- Assert.assertEquals(ac.getAuthenticationResult().getSubject().getPrincipals(UsernamePrincipal.class).iterator()
+ final AuthenticationResult ar = ac.getAuthenticationResult();
+ Assert.assertNotNull(ar);
+ assert ar != null;
+ Assert.assertEquals(ar.getSubject().getPrincipals(UsernamePrincipal.class).iterator()
.next().getName(), clientId.getValue());
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ValidateClientAuthenticationTypeTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ValidateClientAuthenticationTypeTest.java
index f1ec9d06..e2c3c91c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ValidateClientAuthenticationTypeTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/authn/impl/ValidateClientAuthenticationTypeTest.java
@@ -96,7 +96,7 @@ public class ValidateClientAuthenticationTypeTest {
final OIDCClientInformation clientInformation =
new OIDCClientInformation(clientId, new Date(), metadata, secret);
oidcContext.setClientInformation(clientInformation);
- prc.getInboundMessageContext().addSubcontext(oidcContext);
+ prc.ensureInboundMessageContext().addSubcontext(oidcContext);
}
@Test
@@ -112,7 +112,7 @@ public class ValidateClientAuthenticationTypeTest {
public void testNoneDisabled() throws Exception {
initializeRequestCtx(ClientAuthenticationMethod.NONE,
ClientAuthenticationMethod.NONE);
- prc.getSubcontext(AuthenticationContext.class).removeSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).removeSubcontext(OAuth2ClientAuthenticationContext.class);
final Event e = action.execute(rc);
ActionTestingSupport.assertEvent(e, EventIds.ACCESS_DENIED);
}
@@ -122,7 +122,7 @@ public class ValidateClientAuthenticationTypeTest {
initializeRequestCtx(ClientAuthenticationMethod.NONE,
ClientAuthenticationMethod.NONE);
enabledMethods = Collections.singleton(ClientAuthenticationMethod.NONE);
- prc.getSubcontext(AuthenticationContext.class).removeSubcontext(OAuth2ClientAuthenticationContext.class);
+ prc.ensureSubcontext(AuthenticationContext.class).removeSubcontext(OAuth2ClientAuthenticationContext.class);
final Event e = action.execute(rc);
ActionTestingSupport.assertProceedEvent(e);
}
@@ -149,8 +149,8 @@ public class ValidateClientAuthenticationTypeTest {
public void testNoMetadata() throws Exception {
initializeRequestCtx(ClientAuthenticationMethod.CLIENT_SECRET_BASIC,
ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
- prc.getInboundMessageContext().removeSubcontext(
- prc.getInboundMessageContext().getSubcontext(OIDCMetadataContext.class));
+ prc.ensureInboundMessageContext().removeSubcontext(
+ prc.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class));
enabledMethods = Collections.singleton(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
final Event e = action.execute(rc);
ActionTestingSupport.assertProceedEvent(e);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoderTest.java
index d2d0d388..179f4edc 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoderTest.java
@@ -44,7 +44,7 @@ public class OIDCAuthenticationRequestDecoderTest {
httpRequest.setMethod("GET");
decoder = new OIDCAuthenticationRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -57,7 +57,10 @@ public class OIDCAuthenticationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- Assert.assertEquals(((AuthenticationRequest) messageContext.getMessage()).getResponseType()
+ assert messageContext != null;
+ final Object message = messageContext.getMessage();
+ assert message != null;
+ Assert.assertEquals(((AuthenticationRequest) message).getResponseType()
.toString(), ResponseType.Value.CODE.toString());
}
@@ -69,8 +72,12 @@ public class OIDCAuthenticationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
+ assert messageContext != null;
final AuthenticationRequest request = (AuthenticationRequest) messageContext.getMessage();
- Assert.assertEquals(request.getResponseType().toString(), ResponseType.Value.CODE.toString());
+ assert request != null;
+ final ResponseType responseType = request.getResponseType();
+ assert responseType != null;
+ Assert.assertEquals(responseType.toString(), ResponseType.Value.CODE.toString());
Assert.assertTrue(request.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
.contains("https://resource.example.org/"));
}
@@ -83,8 +90,12 @@ public class OIDCAuthenticationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
+ assert messageContext != null;
final AuthenticationRequest request = (AuthenticationRequest) messageContext.getMessage();
- Assert.assertEquals(request.getResponseType().toString(), ResponseType.Value.CODE.toString());
+ assert request != null;
+ final ResponseType responseType = request.getResponseType();
+ assert responseType != null;
+ Assert.assertEquals(responseType.toString(), ResponseType.Value.CODE.toString());
Assert.assertTrue(request.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
.contains("mockResourceId"));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoderTest.java
index 82330400..b99beae5 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoderTest.java
@@ -47,7 +47,7 @@ public class OIDCClientRegistrationRequestDecoderTest {
httpRequest.setMethod(Method.POST.toString());
decoder = new OIDCClientRegistrationRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.setObjectMapper(new ObjectMapper());
decoder.initialize();
@@ -64,7 +64,7 @@ public class OIDCClientRegistrationRequestDecoderTest {
public void testNoObjectMapper() throws ComponentInitializationException {
decoder = new OIDCClientRegistrationRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -89,9 +89,11 @@ public class OIDCClientRegistrationRequestDecoderTest {
httpRequest.setContentType("application/json");
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
final OIDCClientRegistrationRequest message = (OIDCClientRegistrationRequest) messageContext.getMessage();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
+ assert message != null;
Assert.assertEquals(message.getClientMetadata().getName(), "My Example");
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoderTest.java
index 66e6de27..4044d245 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoderTest.java
@@ -46,7 +46,7 @@ public class OIDCTokenRequestDecoderTest {
httpRequest.setMethod(Method.POST.toString());
decoder = new OIDCTokenRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -67,7 +67,9 @@ public class OIDCTokenRequestDecoderTest {
httpRequest.addParameter("redirect_uri", "https://client.example.org/cb");
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
final TokenRequest message = (TokenRequest) messageContext.getMessage();
+ assert message != null;
Assert.assertEquals(message.getAuthorizationGrant().getType().getValue(), "authorization_code");
}
@@ -81,7 +83,9 @@ public class OIDCTokenRequestDecoderTest {
httpRequest.addParameter("resource", "https://resource.example.org");
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
final TokenRequest message = (TokenRequest) messageContext.getMessage();
+ assert message != null;
Assert.assertEquals(message.getAuthorizationGrant().getType().getValue(), "authorization_code");
Assert.assertEquals(message.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME),
List.of("https://resource.example.org"));
@@ -97,7 +101,9 @@ public class OIDCTokenRequestDecoderTest {
httpRequest.addParameter("resource", "resource.example.org");
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
final TokenRequest message = (TokenRequest) messageContext.getMessage();
+ assert message != null;
Assert.assertEquals(message.getAuthorizationGrant().getType().getValue(), "authorization_code");
Assert.assertEquals(message.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME),
List.of("resource.example.org"));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoderTest.java
index c33e6b64..8fbe902d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoderTest.java
@@ -44,7 +44,7 @@ public class OIDCUserInfoRequestDecoderTest {
httpRequest.setMethod(Method.POST.toString());
decoder = new OIDCUserInfoRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -62,7 +62,9 @@ public class OIDCUserInfoRequestDecoderTest {
httpRequest.setContentType("application/x-www-form-urlencoded");
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
final UserInfoRequest message = (UserInfoRequest) messageContext.getMessage();
+ assert message != null;
Assert.assertEquals(message.getAccessToken().getValue(), "SlAV32hkKG");
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCBackChannelLogoutPropagationActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCBackChannelLogoutPropagationActionTest.java
index f61588df..9b06cde2 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCBackChannelLogoutPropagationActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCBackChannelLogoutPropagationActionTest.java
@@ -32,18 +32,19 @@ public abstract class BaseOIDCBackChannelLogoutPropagationActionTest<T extends A
protected OIDCBackChannelLogoutPropagationContext backChannelLogoutPropagationContext;
+ @SuppressWarnings("null")
@BeforeMethod
protected void setup() throws Exception {
super.setup();
backChannelLogoutPropagationContext = new OIDCBackChannelLogoutPropagationContext();
- profileRequestContext.getOutboundMessageContext().getSubcontext(OIDCLogoutPropagationContext.class)
+ profileRequestContext.ensureOutboundMessageContext().ensureSubcontext(OIDCLogoutPropagationContext.class)
.addSubcontext(backChannelLogoutPropagationContext);
}
@Test
public void testMissingOidcBackChannelLogoutPropagationContext() {
action = constructAction();
- profileRequestContext.getOutboundMessageContext().getSubcontext(OIDCLogoutPropagationContext.class)
+ profileRequestContext.ensureOutboundMessageContext().ensureSubcontext(OIDCLogoutPropagationContext.class)
.removeSubcontext(OIDCBackChannelLogoutPropagationContext.class);
ActionTestingSupport.assertEvent(action.execute(requestContext), EventIds.INVALID_MSG_CTX);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCLogoutPropagationActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCLogoutPropagationActionTest.java
index 9c004f79..ac2ce003 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCLogoutPropagationActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCLogoutPropagationActionTest.java
@@ -49,17 +49,18 @@ public abstract class BaseOIDCLogoutPropagationActionTest<T extends AbstractOIDC
protected abstract T constructAction();
+ @SuppressWarnings("null")
@BeforeMethod
protected void setup() throws Exception {
action = constructAction();
requestContext = new RequestContextBuilder().buildRequestContext();
profileRequestContext = new WebflowRequestContextProfileRequestContextLookup().apply(requestContext);
oidcMetadataContext = new OIDCMetadataContext();
- profileRequestContext.getInboundMessageContext().addSubcontext(oidcMetadataContext);
+ profileRequestContext.ensureInboundMessageContext().addSubcontext(oidcMetadataContext);
oidcResponseContext = new OIDCAuthenticationResponseContext();
- profileRequestContext.getOutboundMessageContext().addSubcontext(oidcResponseContext);
+ profileRequestContext.ensureOutboundMessageContext().addSubcontext(oidcResponseContext);
oidcLogoutPropagationContext = new OIDCLogoutPropagationContext();
- profileRequestContext.getOutboundMessageContext().addSubcontext(oidcLogoutPropagationContext);
+ profileRequestContext.ensureOutboundMessageContext().addSubcontext(oidcLogoutPropagationContext);
logoutPropagationContext = new LogoutPropagationContext();
oidcRpSession = new OIDCRPSession.Builder()
.creationInstant(Instant.now())
@@ -78,7 +79,7 @@ public abstract class BaseOIDCLogoutPropagationActionTest<T extends AbstractOIDC
@Test
public void testMissingOidcLogoutPropagationContext() {
action = constructAction();
- profileRequestContext.getOutboundMessageContext().removeSubcontext(OIDCLogoutPropagationContext.class);
+ profileRequestContext.ensureOutboundMessageContext().removeSubcontext(OIDCLogoutPropagationContext.class);
ActionTestingSupport.assertEvent(action.execute(requestContext), EventIds.INVALID_MSG_CTX);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCRpInitiatedLogoutActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCRpInitiatedLogoutActionTest.java
index c134e1f4..ccb703de 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCRpInitiatedLogoutActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/BaseOIDCRpInitiatedLogoutActionTest.java
@@ -44,30 +44,31 @@ public abstract class BaseOIDCRpInitiatedLogoutActionTest<T extends AbstractOIDC
protected abstract T constructAction();
+ @SuppressWarnings("null")
@BeforeMethod
protected void setup() throws Exception {
action = constructAction();
requestContext = new RequestContextBuilder().buildRequestContext();
profileRequestContext = new WebflowRequestContextProfileRequestContextLookup().apply(requestContext);
oidcMetadataContext = new OIDCMetadataContext();
- profileRequestContext.getInboundMessageContext().addSubcontext(oidcMetadataContext);
+ profileRequestContext.ensureInboundMessageContext().addSubcontext(oidcMetadataContext);
rpInitiatedLogoutContext = new OIDCRpInitiatedLogoutContext();
- profileRequestContext.getOutboundMessageContext().addSubcontext(rpInitiatedLogoutContext);
+ profileRequestContext.ensureOutboundMessageContext().addSubcontext(rpInitiatedLogoutContext);
logoutRequest = new LogoutRequest(new URI("https://example.org/"));
- profileRequestContext.getInboundMessageContext().setMessage(logoutRequest);
+ profileRequestContext.ensureInboundMessageContext().setMessage(logoutRequest);
}
@Test
public void testMissingOidcMetadataContext() {
action = constructAction();
- profileRequestContext.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ profileRequestContext.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
ActionTestingSupport.assertEvent(action.execute(requestContext), EventIds.INVALID_MSG_CTX);
}
@Test
public void testMissingRpInitiatedLogoutContext() {
action = constructAction();
- profileRequestContext.getOutboundMessageContext().removeSubcontext(OIDCRpInitiatedLogoutContext.class);
+ profileRequestContext.ensureOutboundMessageContext().removeSubcontext(OIDCRpInitiatedLogoutContext.class);
ActionTestingSupport.assertEvent(action.execute(requestContext), EventIds.INVALID_MSG_CTX);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ExecuteBackChannelLogoutRequestTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ExecuteBackChannelLogoutRequestTest.java
index bfee9222..19ca0d7d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ExecuteBackChannelLogoutRequestTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ExecuteBackChannelLogoutRequestTest.java
@@ -69,6 +69,7 @@ public class ExecuteBackChannelLogoutRequestTest
}
protected ExecuteBackChannelLogoutRequest constructAction() {
final ExecuteBackChannelLogoutRequest action = new ExecuteBackChannelLogoutRequest();
+ assert mockClient != null;
action.setHttpClient(mockClient);
try {
action.initialize();
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormOutboundLogoutRequestMessageTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormOutboundLogoutRequestMessageTest.java
index bf876a5f..b3a3fd7b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormOutboundLogoutRequestMessageTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormOutboundLogoutRequestMessageTest.java
@@ -35,10 +35,10 @@ import net.shibboleth.shared.component.ComponentInitializationException;
/**
* Unit tests for {@link FormOutboundLogoutRequestMessage}.
*/
+ at SuppressWarnings("unchecked")
public class FormOutboundLogoutRequestMessageTest
extends BaseOIDCLogoutPropagationActionTest<FormOutboundLogoutRequestMessage> {
- @SuppressWarnings("unchecked")
Function<ProfileRequestContext, String> issuerLookupStrategy = Mockito.mock(Function.class);
String frontChannelUri = "https://example.org/frontchannel";
@@ -46,6 +46,7 @@ public class FormOutboundLogoutRequestMessageTest
@Override
protected FormOutboundLogoutRequestMessage constructAction() {
final FormOutboundLogoutRequestMessage action = new FormOutboundLogoutRequestMessage();
+ assert issuerLookupStrategy != null;
action.setIssuerLookupStrategy(issuerLookupStrategy);
try {
action.initialize();
@@ -72,10 +73,11 @@ public class FormOutboundLogoutRequestMessageTest
populateMetadataContext(false);
Mockito.when(issuerLookupStrategy.apply(Mockito.any())).thenReturn("mockIssuer");
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
- final Object response = profileRequestContext.getOutboundMessageContext().getMessage();
+ final Object response = profileRequestContext.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(response);
Assert.assertTrue(response instanceof FrontChannelLogoutPropagationResponse);
final FrontChannelLogoutPropagationResponse logoutResponse = (FrontChannelLogoutPropagationResponse) response;
+ assert logoutResponse != null;
Assert.assertTrue(logoutResponse.indicatesSuccess());
Assert.assertEquals(logoutResponse.toHTTPResponse().getLocation().toString(), frontChannelUri);
}
@@ -85,10 +87,11 @@ public class FormOutboundLogoutRequestMessageTest
populateMetadataContext(true);
Mockito.when(issuerLookupStrategy.apply(Mockito.any())).thenReturn("mockIssuer");
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
- final Object response = profileRequestContext.getOutboundMessageContext().getMessage();
+ final Object response = profileRequestContext.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(response);
Assert.assertTrue(response instanceof FrontChannelLogoutPropagationResponse);
final FrontChannelLogoutPropagationResponse logoutResponse = (FrontChannelLogoutPropagationResponse) response;
+ assert logoutResponse != null;
Assert.assertTrue(logoutResponse.indicatesSuccess());
final String uri = logoutResponse.toHTTPResponse().getLocation().toString();
Assert.assertTrue(uri.startsWith(frontChannelUri));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormRpInitiatedLogoutResponseTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormRpInitiatedLogoutResponseTest.java
index 0641e9b5..50929ffc 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormRpInitiatedLogoutResponseTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/FormRpInitiatedLogoutResponseTest.java
@@ -73,7 +73,7 @@ public class FormRpInitiatedLogoutResponseTest
}
protected RpInitiatedLogoutResponse parseLogoutResponse() {
- final Object responseObject = profileRequestContext.getOutboundMessageContext().getMessage();
+ final Object responseObject = profileRequestContext.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(responseObject);
Assert.assertTrue(responseObject instanceof RpInitiatedLogoutResponse);
return (RpInitiatedLogoutResponse) responseObject;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/InitializeOutboundRpInitiatedLogoutResponseMessageContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/InitializeOutboundRpInitiatedLogoutResponseMessageContextTest.java
index 8039334b..b2b6fbcc 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/InitializeOutboundRpInitiatedLogoutResponseMessageContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/InitializeOutboundRpInitiatedLogoutResponseMessageContextTest.java
@@ -39,9 +39,10 @@ public class InitializeOutboundRpInitiatedLogoutResponseMessageContextTest {
@Test
public void testSuccess() {
Assert.assertNull(profileRequestContext.getOutboundMessageContext());
+ assert profileRequestContext != null;
action.execute(profileRequestContext);
Assert.assertNotNull(profileRequestContext.getOutboundMessageContext());
- Assert.assertNotNull(profileRequestContext.getOutboundMessageContext()
+ Assert.assertNotNull(profileRequestContext.ensureOutboundMessageContext()
.getSubcontext(OIDCRpInitiatedLogoutContext.class));
}
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PopulateRpInitiatedLogoutContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PopulateRpInitiatedLogoutContextTest.java
index 947a4b0f..55548004 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PopulateRpInitiatedLogoutContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PopulateRpInitiatedLogoutContextTest.java
@@ -87,7 +87,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testNoParams() throws URISyntaxException {
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(new URI("https://example.org")));
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(new URI("https://example.org")));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertNull(rpInitiatedLogoutContext.getLogoutHint());
Assert.assertNull(rpInitiatedLogoutContext.getRequestedClientId());
@@ -99,7 +99,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithClientId() throws URISyntaxException {
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), null, null, new ClientID("mockClientId"), null, null, null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertNull(rpInitiatedLogoutContext.getLogoutHint());
@@ -113,7 +113,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithUriNoState() throws URISyntaxException {
final URI postLogoutRedirectUri = new URI("https://rp.example.org/postLogout");
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), null, null, null, postLogoutRedirectUri, null, null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertNull(rpInitiatedLogoutContext.getLogoutHint());
@@ -127,7 +127,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithUriAndState() throws URISyntaxException {
final URI postLogoutRedirectUri = new URI("https://rp.example.org/postLogout");
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), null, null, null, postLogoutRedirectUri,
new State("mockState"), null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
@@ -141,7 +141,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithLogoutHint() throws URISyntaxException {
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), null, "mockLogoutHint", null, null, null, null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertEquals(rpInitiatedLogoutContext.getLogoutHint(), "mockLogoutHint");
@@ -155,7 +155,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithNonEncryptedIdTokenHint() throws URISyntaxException {
final SignedJWT jwt = buildSignedJWT();
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), jwt, null, null, null, null, null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertNull(rpInitiatedLogoutContext.getLogoutHint());
@@ -169,7 +169,7 @@ public class PopulateRpInitiatedLogoutContextTest
@Test
public void testWithEncryptedIdTokenHint() throws URISyntaxException {
final EncryptedJWT jwt = buildEncryptedJWT();
- profileRequestContext.getInboundMessageContext().setMessage(new LogoutRequest(
+ profileRequestContext.ensureInboundMessageContext().setMessage(new LogoutRequest(
new URI("https://example.org"), jwt, null, null, null, null, null));
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
Assert.assertNull(rpInitiatedLogoutContext.getLogoutHint());
@@ -193,6 +193,7 @@ public class PopulateRpInitiatedLogoutContextTest
return jwt;
}
+ @SuppressWarnings("null")
protected EncryptedJWT buildEncryptedJWT() {
final JWEObject jweObject =
new JWEObject(new JWEHeader.Builder(JWEAlgorithm.A256KW, EncryptionMethod.A256GCM)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PrepareBackChannelLogoutRequestTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PrepareBackChannelLogoutRequestTest.java
index e2ca1568..8edd8d70 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PrepareBackChannelLogoutRequestTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/PrepareBackChannelLogoutRequestTest.java
@@ -70,6 +70,7 @@ public class PrepareBackChannelLogoutRequestTest
ActionTestingSupport.assertProceedEvent(action.execute(requestContext));
final LogoutTokenClaimsSet claimsSet = backChannelLogoutPropagationContext.getLogoutTokenClaimsSet();
Assert.assertNotNull(claimsSet);
+ assert claimsSet != null;
Assert.assertEquals(claimsSet.getAudience().size(), 1);
Assert.assertTrue(claimsSet.getAudience().contains(new Audience(oidcRpSession.getId())));
Assert.assertEquals(claimsSet.getIssuer().getValue(), "mockIssuer");
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ProcessRpInitiatedLogoutRequestTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ProcessRpInitiatedLogoutRequestTest.java
index 14e99f87..da8f5e71 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ProcessRpInitiatedLogoutRequestTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ProcessRpInitiatedLogoutRequestTest.java
@@ -48,6 +48,7 @@ import net.shibboleth.shared.resolver.ResolverException;
/**
* Unit tests for {@link ProcessRpInitiatedLogoutRequest}.
*/
+ at SuppressWarnings("null")
public class ProcessRpInitiatedLogoutRequestTest
extends BaseOIDCRpInitiatedLogoutActionTest<ProcessRpInitiatedLogoutRequest> {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/RevokeTokenChainTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/RevokeTokenChainTest.java
index 086abd70..874e0381 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/RevokeTokenChainTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/RevokeTokenChainTest.java
@@ -33,6 +33,7 @@ import net.shibboleth.shared.component.ComponentInitializationException;
/**
* Unit tests for {@link RevokeTokenChain}.
*/
+ at SuppressWarnings("null")
public class RevokeTokenChainTest extends BaseOIDCLogoutPropagationActionTest<RevokeTokenChain> {
MemoryStorageService storageService;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ValidateIdTokenHintTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ValidateIdTokenHintTest.java
index b7df5ae6..34e99698 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ValidateIdTokenHintTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/logout/profile/impl/ValidateIdTokenHintTest.java
@@ -16,8 +16,6 @@ package net.shibboleth.idp.plugin.oidc.op.logout.profile.impl;
import java.text.ParseException;
-import javax.annotation.Nonnull;
-
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -37,11 +35,12 @@ import net.shibboleth.shared.component.ComponentInitializationException;
*/
public class ValidateIdTokenHintTest extends BaseOIDCRpInitiatedLogoutActionTest<ValidateIdTokenHint> {
- @Nonnull ClaimsValidator validator = Mockito.mock(ClaimsValidator.class);
+ ClaimsValidator validator = Mockito.mock(ClaimsValidator.class);
@Override
protected ValidateIdTokenHint constructAction() {
final ValidateIdTokenHint action = new ValidateIdTokenHint();
+ assert validator != null;
action.setClaimsValidator(validator);
try {
action.initialize();
@@ -68,6 +67,7 @@ public class ValidateIdTokenHintTest extends BaseOIDCRpInitiatedLogoutActionTest
ActionTestingSupport.assertEvent(action.execute(requestContext), OidcEventIds.INVALID_ID_TOKEN_HINT);
}
+ @SuppressWarnings("null")
@Test
public void notValidatedIdTokenHint() throws JWTValidationException, ParseException {
Mockito.doThrow(JWTValidationException.class).when(validator).validate(Mockito.any(), Mockito.any());
@@ -77,6 +77,7 @@ public class ValidateIdTokenHintTest extends BaseOIDCRpInitiatedLogoutActionTest
ActionTestingSupport.assertEvent(action.execute(requestContext), OidcEventIds.INVALID_ID_TOKEN_HINT);
}
+ @SuppressWarnings("null")
@Test
public void validatedIdTokenHint() throws JWTValidationException, ParseException {
Mockito.doNothing().when(validator).validate(Mockito.any(), Mockito.any());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
index 850f56c7..eea11b82 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
@@ -77,6 +77,7 @@ public class CredentialMetadataValueResolverTest {
Assert.assertNotNull(result);
System.out.println(result);
Assert.assertTrue(result instanceof List);
+ assert result != null;
@SuppressWarnings({ "rawtypes", "unchecked" })
final Map<String, Object> json = (Map<String, Object>)((List) result).get(0);
Assert.assertEquals(json.keySet().size(), 6);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/DynamicFilesystemProviderMetadataResolverTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/DynamicFilesystemProviderMetadataResolverTest.java
index c54b66f6..32645ced 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/DynamicFilesystemProviderMetadataResolverTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/DynamicFilesystemProviderMetadataResolverTest.java
@@ -38,6 +38,7 @@ public class DynamicFilesystemProviderMetadataResolverTest extends FilesystemPro
@BeforeMethod
public void initTests() throws Exception {
super.initTests();
+ assert file != null;
resolver = new DynamicFilesystemProviderMetadataResolver(file);
((DynamicFilesystemProviderMetadataResolver)resolver).setId("mockId");
((DynamicFilesystemProviderMetadataResolver)resolver).initialize();
@@ -56,9 +57,11 @@ public class DynamicFilesystemProviderMetadataResolverTest extends FilesystemPro
public void testDynamic() throws Exception {
OIDCProviderMetadata metadata = resolver.resolveSingle(new ProfileRequestContext());
Assert.assertNotNull(metadata);
+ assert metadata != null;
Assert.assertEquals(metadata.getIssuer().getValue(), "http://idp.example.org");
((DynamicFilesystemProviderMetadataResolver)resolver).refresh();
metadata = resolver.resolveSingle(new ProfileRequestContext());
+ assert metadata != null;
Assert.assertNotNull(metadata.getCustomParameter(name));
Assert.assertEquals(metadata.getCustomParameter(name), value);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemMetadataValueResolverTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemMetadataValueResolverTest.java
index dd7bf9b9..8fb3e70d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemMetadataValueResolverTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemMetadataValueResolverTest.java
@@ -14,6 +14,8 @@
package net.shibboleth.idp.plugin.oidc.op.metadata.impl;
+import javax.annotation.Nonnull;
+
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.testng.Assert;
@@ -26,7 +28,7 @@ import net.minidev.json.JSONObject;
*/
public class FilesystemMetadataValueResolverTest {
- public FilesystemMetadataValueResolver initTests(final String filename) throws Exception {
+ public FilesystemMetadataValueResolver initTests(@Nonnull final String filename) throws Exception {
final Resource file = new ClassPathResource(filename);
final FilesystemMetadataValueResolver resolver = new FilesystemMetadataValueResolver(file);
resolver.setId("mockId");
@@ -52,6 +54,7 @@ public class FilesystemMetadataValueResolverTest {
Assert.assertNotNull(value);
Assert.assertTrue(value instanceof JSONObject);
final JSONObject jsonValue = (JSONObject) value;
+ assert jsonValue != null;
Assert.assertEquals(jsonValue.size(), 1);
Assert.assertEquals(jsonValue.get("mockKey"), "mockValue");
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemProviderMetdataResolverTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemProviderMetdataResolverTest.java
index 206f5e32..856a006e 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemProviderMetdataResolverTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/FilesystemProviderMetdataResolverTest.java
@@ -56,6 +56,7 @@ public class FilesystemProviderMetdataResolverTest {
final String issuer = "http://idp.example.org";
final OIDCProviderMetadata metadata = resolver.resolveSingle(initMockWithRpId(issuer));
Assert.assertNotNull(metadata);
+ assert metadata != null;
Assert.assertEquals(metadata.getIssuer().getValue(), issuer);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoderTest.java
index 58ffbe5e..887f9b2c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoderTest.java
@@ -44,7 +44,7 @@ public class OAuth2AuthorizationRequestDecoderTest {
httpRequest.setMethod("GET");
decoder = new OAuth2AuthorizationRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -57,8 +57,13 @@ public class OAuth2AuthorizationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- Assert.assertEquals(((AuthorizationRequest) messageContext.getMessage()).getResponseType()
- .toString(), ResponseType.Value.CODE.toString());
+ assert messageContext != null;
+ if (messageContext.getMessage() instanceof AuthorizationRequest authzRequest) {
+ Assert.assertEquals(authzRequest.getResponseType()
+ .toString(), ResponseType.Value.CODE.toString());
+ } else {
+ Assert.fail();
+ }
}
@Test
@@ -69,10 +74,14 @@ public class OAuth2AuthorizationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- final AuthorizationRequest request = (AuthorizationRequest) messageContext.getMessage();
- Assert.assertEquals(request.getResponseType().toString(), ResponseType.Value.CODE.toString());
- Assert.assertTrue(request.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
+ assert messageContext != null;
+ if (messageContext.getMessage() instanceof AuthorizationRequest authzRequest) {
+ Assert.assertEquals(authzRequest.getResponseType().toString(), ResponseType.Value.CODE.toString());
+ Assert.assertTrue(authzRequest.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
.contains("https://resource.example.org/"));
+ } else {
+ Assert.fail();
+ }
}
@Test
@@ -83,10 +92,14 @@ public class OAuth2AuthorizationRequestDecoderTest {
final MessageContext messageContext = decoder.getMessageContext();
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- final AuthorizationRequest request = (AuthorizationRequest) messageContext.getMessage();
- Assert.assertEquals(request.getResponseType().toString(), ResponseType.Value.CODE.toString());
- Assert.assertTrue(request.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
- .contains("mockResourceId"));
+ assert messageContext != null;
+ if (messageContext.getMessage() instanceof AuthorizationRequest authzRequest) {
+ Assert.assertEquals(authzRequest.getResponseType().toString(), ResponseType.Value.CODE.toString());
+ Assert.assertTrue(authzRequest.getCustomParameter(DefaultRequestAudienceLookupFunction.CUSTOM_RESOURCE_PARAM_NAME)
+ .contains("mockResourceId"));
+ } else {
+ Assert.fail();
+ }
}
@Test(expectedExceptions = MessageDecodingException.class)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoderTest.java
index 4597446d..3214a0a0 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoderTest.java
@@ -43,7 +43,7 @@ public class OAuth2IntrospectionRequestDecoderTest {
httpRequest.addParameter("token", "45ghiukldjahdnhzdauz");
decoder = new OAuth2IntrospectionRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -52,11 +52,14 @@ public class OAuth2IntrospectionRequestDecoderTest {
public void testRequestDecoding() throws MessageDecodingException {
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- Assert.assertEquals(((TokenIntrospectionRequest) messageContext.getMessage()).getToken().toString(),
- "45ghiukldjahdnhzdauz");
-
+ if (messageContext.getMessage() instanceof TokenIntrospectionRequest request) {
+ Assert.assertEquals(request.getToken().toString(), "45ghiukldjahdnhzdauz");
+ } else {
+ Assert.fail();
+ }
}
@Test(expectedExceptions = MessageDecodingException.class)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoderTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoderTest.java
index 02cfb0e1..1c85f17a 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoderTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoderTest.java
@@ -45,7 +45,7 @@ public class OAuth2RevocationRequestDecoderTest {
httpRequest.addParameter("client_id", "123456");
decoder = new OAuth2RevocationRequestDecoder();
decoder.setHttpServletRequestSupplier(new NonnullSupplier<> () {
- public HttpServletRequest get() { return httpRequest;}
+ public HttpServletRequest get() { assert httpRequest != null; return httpRequest;}
});
decoder.initialize();
}
@@ -54,10 +54,14 @@ public class OAuth2RevocationRequestDecoderTest {
public void testRequestDecoding() throws MessageDecodingException {
decoder.decode();
final MessageContext messageContext = decoder.getMessageContext();
+ assert messageContext != null;
// We are not testing nimbus itself here, i.e. we are happy to decode
// one parameter successfully
- Assert.assertEquals(((TokenRevocationRequest) messageContext.getMessage()).getClientID().toString(), "123456");
-
+ if (messageContext.getMessage() instanceof TokenRevocationRequest request) {
+ Assert.assertEquals(request.getClientID().toString(), "123456");
+ } else {
+ Assert.fail();
+ }
}
@Test(expectedExceptions = MessageDecodingException.class)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/OAuth2RevocationErrorResponseTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/OAuth2RevocationErrorResponseTest.java
index ab87bc38..9a018060 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/OAuth2RevocationErrorResponseTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/OAuth2RevocationErrorResponseTest.java
@@ -19,8 +19,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ErrorObject;
-import net.shibboleth.shared.logic.ConstraintViolationException;
-
/**
* Tests for {@link OAuth2RevocationErrorResponse}.
*/
@@ -40,10 +38,4 @@ public class OAuth2RevocationErrorResponseTest {
Assert.assertEquals(400, resp.toHTTPResponse().getStatusCode());
Assert.assertFalse(resp.indicatesSuccess());
}
-
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNull() {
- resp = new OAuth2RevocationErrorResponse(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/SetEntityIdToSAMLPeerEntityContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/SetEntityIdToSAMLPeerEntityContextTest.java
index 586fe3d3..8ada1ce9 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/SetEntityIdToSAMLPeerEntityContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/messaging/impl/SetEntityIdToSAMLPeerEntityContextTest.java
@@ -28,11 +28,11 @@ import com.nimbusds.oauth2.sdk.id.ClientID;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.component.UnmodifiableComponentException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
/**
* Unit tests for {@link SetEntityIdToSAMLPeerEntityContext}.
*/
+ at SuppressWarnings("null")
public class SetEntityIdToSAMLPeerEntityContextTest {
private SetEntityIdToSAMLPeerEntityContext handler;
@@ -48,6 +48,7 @@ public class SetEntityIdToSAMLPeerEntityContextTest {
public void initialize(final SAMLPeerEntityContext entityContext,
final Function<MessageContext, ClientID> clientIdLookupStrategy) throws ComponentInitializationException {
+ assert clientIdLookupStrategy != null;
handler.setClientIDLookupStrategy(clientIdLookupStrategy);
handler.initialize();
messageCtx = new MessageContext();
@@ -56,27 +57,18 @@ public class SetEntityIdToSAMLPeerEntityContextTest {
}
}
- @Test(expectedExceptions = { ConstraintViolationException.class })
- public void setClientIDLookupStrategy_shouldThrowIfGivenNull() {
- handler.setClientIDLookupStrategy(null);
- }
-
+ @SuppressWarnings("unchecked")
@Test(expectedExceptions = { UnmodifiableComponentException.class })
public void setClientIDLookupStrategy_shouldThrowIfCalledAfterInitialization()
throws ComponentInitializationException {
handler.initialize();
- handler.setClientIDLookupStrategy(null);
+ handler.setClientIDLookupStrategy(Mockito.mock(Function.class));
}
- @Test(expectedExceptions = { ConstraintViolationException.class })
- public void setEntityContextClass_shouldThrowIfGivenNull() {
- handler.setEntityContextClass(null);
- }
-
@Test(expectedExceptions = { UnmodifiableComponentException.class })
public void setEntityContextClass_shouldThrowIfCalledAfterInitialization() throws ComponentInitializationException {
handler.initialize();
- handler.setEntityContextClass(null);
+ handler.setEntityContextClass(SAMLPeerEntityContext.class);
}
@Test(expectedExceptions=MessageHandlerException.class)
@@ -91,7 +83,7 @@ public class SetEntityIdToSAMLPeerEntityContextTest {
MessageHandlerException {
initialize(new SAMLPeerEntityContext(), mockClientIdLookupStrategy(null));
handler.invoke(messageCtx);
- final SAMLPeerEntityContext entityCtx = messageCtx.getSubcontext(SAMLPeerEntityContext.class);
+ final SAMLPeerEntityContext entityCtx = messageCtx.ensureSubcontext(SAMLPeerEntityContext.class);
Assert.assertNull(entityCtx.getEntityId());
}
@@ -100,7 +92,7 @@ public class SetEntityIdToSAMLPeerEntityContextTest {
MessageHandlerException {
initialize(new SAMLPeerEntityContext(), mockClientIdLookupStrategy(clientId));
handler.invoke(messageCtx);
- final SAMLPeerEntityContext entityCtx = messageCtx.getSubcontext(SAMLPeerEntityContext.class);
+ final SAMLPeerEntityContext entityCtx = messageCtx.ensureSubcontext(SAMLPeerEntityContext.class);
Assert.assertEquals(entityCtx.getEntityId(), clientId);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/BuildAccessTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/BuildAccessTokenTest.java
index bd6f5545..fc4219f8 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/BuildAccessTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/BuildAccessTokenTest.java
@@ -26,6 +26,7 @@ import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.FunctionSupport;
import net.shibboleth.shared.security.DataSealerException;
@@ -35,7 +36,6 @@ import java.text.ParseException;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
@@ -57,6 +57,7 @@ import com.nimbusds.oauth2.sdk.id.ClientID;
// Checkstyle: ThrowsCount OFF
/** {@link BuildAccessToken} unit test. */
+ at SuppressWarnings("null")
public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
/** Action to test. */
@@ -110,8 +111,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), null);
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), null);
}
/**
@@ -132,8 +133,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), null, "mockSid");
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), null, "mockSid");
}
/**
@@ -153,8 +154,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), Map.of("custom_claim", "custom_value"));
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), Map.of("custom_claim", "custom_value"));
}
/**
@@ -174,8 +175,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), null);
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), null);
}
/**
@@ -196,8 +197,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), null, "mockSid");
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), null, "mockSid");
}
/**
@@ -217,8 +218,8 @@ public class BuildAccessTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- verifyClaims(respCtx.getSubcontext(AccessTokenContext.class), new Scope(),
- Collections.singletonList("https://rp.example.org"), Map.of("custom_claim", "custom_value"));
+ verifyClaims(respCtx.ensureSubcontext(AccessTokenContext.class), new Scope(),
+ CollectionSupport.singletonList("https://rp.example.org"), Map.of("custom_claim", "custom_value"));
}
/**
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/RevokeTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/RevokeTokenTest.java
index eee248f7..bbfa71b0 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/RevokeTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/RevokeTokenTest.java
@@ -65,6 +65,7 @@ public class RevokeTokenTest extends BaseTokenClaimsSetTest {
setUp(method, rootTokenId, exp);
}
+ @SuppressWarnings("null")
protected void setUp(final OAuth2TokenRevocationMethod method, final String rootTokenId, final Instant exp)
throws Exception {
@@ -108,7 +109,7 @@ public class RevokeTokenTest extends BaseTokenClaimsSetTest {
src = new RequestContextBuilder().buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
- tokenCtx = prc.getOutboundMessageContext().ensureSubcontext(OAuth2TokenMgmtResponseContext.class);
+ tokenCtx = prc.ensureOutboundMessageContext().ensureSubcontext(OAuth2TokenMgmtResponseContext.class);
}
@AfterMethod
@@ -127,59 +128,59 @@ public class RevokeTokenTest extends BaseTokenClaimsSetTest {
@Test
public void testChain_RevokeAccessToken() throws Exception {
setUp(OAuth2TokenRevocationMethod.CHAIN, null);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
+ final String id = atClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
tokenCtx.setTokenClaimsSet(atClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
}
@Test
public void testChain_RevokeRefreshToken() throws Exception {
setUp(OAuth2TokenRevocationMethod.CHAIN, null);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
+ final String id = rfClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
tokenCtx.setTokenClaimsSet(rfClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
}
@Test
public void testChain_RevokeAccessTokenViaRootToken() throws Exception {
final String rootTokenIdentifier = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
setUp(OAuth2TokenRevocationMethod.CHAIN, rootTokenIdentifier);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
+ final String id = atClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
tokenCtx.setTokenClaimsSet(atClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
}
@Test
public void testChain_RevokeRefreshTokenViaRootToken() throws Exception {
final String rootTokenIdentifier = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
setUp(OAuth2TokenRevocationMethod.CHAIN, rootTokenIdentifier);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
+ final String id = rfClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
tokenCtx.setTokenClaimsSet(rfClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
}
@Test
@@ -205,42 +206,42 @@ public class RevokeTokenTest extends BaseTokenClaimsSetTest {
@Test
public void testSingleToken_RevokeAccessToken() throws Exception {
setUp(OAuth2TokenRevocationMethod.TOKEN, null);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
+ final String id = atClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
tokenCtx.setTokenClaimsSet(atClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
}
@Test
public void testSingleToken_RevokeRefreshToken() throws Exception {
setUp(OAuth2TokenRevocationMethod.TOKEN, null);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
+ final String id = rfClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
tokenCtx.setTokenClaimsSet(rfClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
}
@Test
public void testSingleToken_RevokeAccessTokenViaRootToken() throws Exception {
final String rootTokenIdentifier = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
setUp(OAuth2TokenRevocationMethod.TOKEN, rootTokenIdentifier);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
+ final String id = atClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
tokenCtx.setTokenClaimsSet(atClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- atClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, atClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
}
@@ -248,15 +249,15 @@ public class RevokeTokenTest extends BaseTokenClaimsSetTest {
public void testSingleToken_RevokeRefreshTokenViaRootToken() throws Exception {
final String rootTokenIdentifier = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
setUp(OAuth2TokenRevocationMethod.TOKEN, rootTokenIdentifier);
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
+ final String id = rfClaimsSet.getID();
+ assert id != null;
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
tokenCtx.setTokenClaimsSet(rfClaimsSet.getClaimsSet());
ActionTestingSupport.assertProceedEvent(action.execute(src));
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaimsSet.getID()));
- Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rfClaimsSet.getID()));
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, id));
+ Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, id));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootTokenIdentifier));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetAuthorizationCodeToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetAuthorizationCodeToResponseContextTest.java
index 8519df68..4d6cd965 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetAuthorizationCodeToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetAuthorizationCodeToResponseContextTest.java
@@ -23,6 +23,7 @@ import net.shibboleth.idp.profile.IdPEventIds;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.security.DataSealer;
import net.shibboleth.shared.security.DataSealerException;
import java.net.URI;
@@ -34,13 +35,20 @@ import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.webflow.execution.Event;
import org.testng.Assert;
import org.testng.annotations.Test;
+
+import com.nimbusds.jwt.JWTClaimsSet;
+import com.nimbusds.oauth2.sdk.AuthorizationCode;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.AuthenticationRequest;
+import com.nimbusds.openid.connect.sdk.claims.ClaimsSet;
// Checkstyle: ThrowsCount OFF
@@ -62,7 +70,9 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
respCtx.setAcr("0");
respCtx.setRedirectURI(new URI("http://example.com"));
action = new SetAuthorizationCodeToResponseContext();
- action.setDataSealer(getDataSealer());
+ final DataSealer dataSealer = getDataSealer();
+ assert dataSealer != null;
+ action.setDataSealer(dataSealer);
if (manipulationStrategy != null) {
action.setTokenClaimsSetManipulationStrategyLookupStrategy(manipulationStrategy);
}
@@ -87,8 +97,7 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
Assert.assertNull(ac.getSessionIdentifier());
}
@@ -110,8 +119,7 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
Assert.assertEquals(ac.getSessionIdentifier(), "mockSid");
}
@@ -123,11 +131,12 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
- Assert.assertNotNull(ac.getClaimsSet().getClaim("custom_claim"));
- Assert.assertEquals(ac.getClaimsSet().getStringClaim("custom_claim"), "custom_value");
+ final JWTClaimsSet claimsSet = ac.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNotNull(claimsSet.getClaim("custom_claim"));
+ Assert.assertEquals(claimsSet.getStringClaim("custom_claim"), "custom_value");
}
/**
@@ -149,8 +158,7 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
Assert.assertEquals(ac.getConsentedClaims(), consCtx.getConsentedAttributes());
}
@@ -177,12 +185,17 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
- Assert.assertNotNull(ac.getDeliveryClaims().getClaim("1"));
- Assert.assertNotNull(ac.getIDTokenDeliveryClaims().getClaim("2"));
- Assert.assertNotNull(ac.getUserinfoDeliveryClaims().getClaim("3"));
+ final ClaimsSet deliveryClaims = ac.getDeliveryClaims();
+ assert deliveryClaims != null;
+ Assert.assertNotNull(deliveryClaims.getClaim("1"));
+ final ClaimsSet idTokenDeliveryClaims = ac.getIDTokenDeliveryClaims();
+ assert idTokenDeliveryClaims != null;
+ Assert.assertNotNull(idTokenDeliveryClaims.getClaim("2"));
+ final ClaimsSet userInfoDeliveryClaims = ac.getUserinfoDeliveryClaims();
+ assert userInfoDeliveryClaims != null;
+ Assert.assertNotNull(userInfoDeliveryClaims.getClaim("3"));
}
/**
@@ -205,8 +218,7 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
Assert.assertEquals(ac.getCodeChallenge(), "S256123456");
}
@@ -231,12 +243,23 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getAuthorizationCode());
- final AuthorizeCodeClaimsSet ac =
- AuthorizeCodeClaimsSet.parse(respCtx.getAuthorizationCode().getValue(), getDataSealer());
+ final AuthorizeCodeClaimsSet ac = parseAuthorizeCodeClaimsSet(respCtx.getAuthorizationCode());
Assert.assertNotNull(ac);
Assert.assertEquals(ac.getCodeChallenge(), "plain123456");
}
+ @Nonnull private AuthorizeCodeClaimsSet parseAuthorizeCodeClaimsSet(@Nullable final AuthorizationCode code)
+ throws ParseException, DataSealerException, NoSuchAlgorithmException, ComponentInitializationException {
+ final DataSealer dataSealer = getDataSealer();
+ assert dataSealer != null;
+ assert code != null;
+ final String value = code.getValue();
+ assert value != null;
+ final AuthorizeCodeClaimsSet result = AuthorizeCodeClaimsSet.parse(value, dataSealer);
+ assert result != null;
+ return result;
+ }
+
/**
* fails as there is no rp ctx.
*
@@ -281,6 +304,7 @@ public class SetAuthorizationCodeToResponseContextTest extends BaseOIDCResponseA
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
init();
final RelyingPartyContext rpCtx = profileRequestCtx.getSubcontext(RelyingPartyContext.class);
+ assert rpCtx != null;
rpCtx.setProfileConfig(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_PROFILE_CONFIG);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetRequestObjectToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetRequestObjectToResponseContextTest.java
index 6a60ca27..89c52b58 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetRequestObjectToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/SetRequestObjectToResponseContextTest.java
@@ -39,6 +39,7 @@ import com.nimbusds.jwt.PlainJWT;
import com.nimbusds.jwt.SignedJWT;
import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.openid.connect.sdk.AuthenticationRequest;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
/** {@link SetRequestObjectToResponseContext} unit test. */
public class SetRequestObjectToResponseContextTest extends BaseOIDCResponseActionTest {
@@ -58,6 +59,7 @@ public class SetRequestObjectToResponseContextTest extends BaseOIDCResponseActio
final HttpClientBuilder builder = new HttpClientBuilder();
builder.setTLSSocketFactory(HttpClientSupport.buildNoTrustTLSSocketFactory());
action.setHttpClient(builder.buildClient());
+ assert enforceRequestObjects != null;
action.setRequestObjectEnforcedPredicate(enforceRequestObjects);
action.initialize();
}
@@ -105,8 +107,10 @@ public class SetRequestObjectToResponseContextTest extends BaseOIDCResponseActio
*/
@Test
public void testInvalidRequestURI() throws ParseException, URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata().setRequestObjectURIs(
- Set.of(new URI("https://localhost/foobar")));
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setRequestObjectURIs(Set.of(new URI("https://localhost/foobar")));
setAuthenticationRequest(
AuthenticationRequest.parse("client_id=mockClientId&request_uri=http://localhost/foo"));
@@ -126,7 +130,10 @@ public class SetRequestObjectToResponseContextTest extends BaseOIDCResponseActio
final String uri = RepositorySupport.buildHTTPSResourceURL("java-idp-oidc",
"idp-oidc-extension-impl/src/test/resources/net/shibboleth/idp/oidc/profile/impl/oidc-authreq.json");
- metadataCtx.getClientInformation().getOIDCMetadata().setRequestObjectURIs(Set.of(new URI(uri)));
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setRequestObjectURIs(Set.of(new URI(uri)));
setAuthenticationRequest(
AuthenticationRequest.parse("client_id=" + clientId +
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateAudienceTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateAudienceTest.java
index d09dc44a..9b5f3a3d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateAudienceTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateAudienceTest.java
@@ -59,7 +59,7 @@ public class ValidateAudienceTest extends BaseOIDCResponseActionTest {
action = new ValidateAudience();
action.initialize();
final OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
metaData = new OIDCClientMetadata();
metaData.setCustomField("audience", List.of("https://sp.example.org", "https://sp2.example.org"));
final OIDCClientInformation information =
@@ -148,7 +148,8 @@ public class ValidateAudienceTest extends BaseOIDCResponseActionTest {
* @throws ComponentInitializationException
* @throws URISyntaxException
*/
- @Test
+ @SuppressWarnings("null")
+ at Test
public void testTokenFailNonePrevGranted() throws ComponentInitializationException, URISyntaxException {
final TokenRequest req = new TokenRequest(new URI("http://localhost"),
@@ -185,7 +186,8 @@ public class ValidateAudienceTest extends BaseOIDCResponseActionTest {
* @throws ComponentInitializationException
* @throws URISyntaxException
*/
- @Test
+ @SuppressWarnings("null")
+ at Test
public void testTokenFailPrevGranted() throws ComponentInitializationException, URISyntaxException {
final TokenRequest req = new TokenRequest(new URI("http://localhost"),
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRedirectURITest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRedirectURITest.java
index 4d5c7fb4..ee79116d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRedirectURITest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRedirectURITest.java
@@ -80,7 +80,7 @@ public class ValidateRedirectURITest extends BaseOIDCResponseActionTest {
@Test
public void testNoCtxNoPolicy() throws ComponentInitializationException, URISyntaxException {
init();
- profileRequestCtx.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REDIRECT_URI);
}
@@ -95,7 +95,7 @@ public class ValidateRedirectURITest extends BaseOIDCResponseActionTest {
public void testNoMatchViaMetadata() throws ComponentInitializationException, URISyntaxException {
init();
OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
OIDCClientMetadata metaData = new OIDCClientMetadata();
metaData.setRedirectionURI(new URI("https://notmatching.org"));
OIDCClientInformation information =
@@ -116,7 +116,7 @@ public class ValidateRedirectURITest extends BaseOIDCResponseActionTest {
public void testMatch() throws ComponentInitializationException, URISyntaxException {
init();
OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
OIDCClientMetadata metaData = new OIDCClientMetadata();
metaData.setRedirectionURI(new URI("https://client.example.org/cb"));
OIDCClientInformation information =
@@ -131,7 +131,7 @@ public class ValidateRedirectURITest extends BaseOIDCResponseActionTest {
public void testNoMatchViaPolicy() throws ComponentInitializationException, URISyntaxException {
init(true, new URI(requestUri), null, null, Map.of("redirect_uri", new UnregisteredClientPolicy(
new MetadataPolicy.Builder().withOneOfValues(List.of("https://notmatching.org")).build())));
- profileRequestCtx.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REDIRECT_URI);
Assert.assertNull(respCtx.getRedirectURI());
@@ -141,7 +141,7 @@ public class ValidateRedirectURITest extends BaseOIDCResponseActionTest {
public void testMatchViaPolicy() throws ComponentInitializationException, URISyntaxException {
init(true, new URI(requestUri), null, null, Map.of("redirect_uri", new UnregisteredClientPolicy(
new MetadataPolicy.Builder().withRegexp("^https:\\/\\/(?:([^.]+).)?example.org\\/(.*)").build())));
- profileRequestCtx.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRedirectURI());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObjectTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObjectTest.java
index a71a950c..f7b80f58 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObjectTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObjectTest.java
@@ -82,13 +82,14 @@ public class ValidateRequestObjectTest {
private String issuer;
+ @SuppressWarnings("null")
@BeforeMethod
public void setup() throws ComponentInitializationException, NoSuchAlgorithmException {
requestCtx = new RequestContextBuilder().buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- oidcCtx = prc.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ oidcCtx = prc.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
oidcRespCtx = new OIDCAuthenticationResponseContext();
- prc.getOutboundMessageContext().addSubcontext(oidcRespCtx);
+ prc.ensureOutboundMessageContext().addSubcontext(oidcRespCtx);
issuer = "https://op.example.org/";
OIDCClientMetadata metaData = new OIDCClientMetadata();
OIDCClientInformation information = new OIDCClientInformation(new ClientID("test"), null, metaData,
@@ -159,7 +160,7 @@ public class ValidateRequestObjectTest {
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
}
@@ -174,7 +175,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro))
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -186,12 +187,15 @@ public class ValidateRequestObjectTest {
@Test
public void testRequestObjectAlgMismatch()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
- oidcCtx.getClientInformation().getOIDCMetadata().setRequestObjectJWSAlg(JWSAlgorithm.RS256);
+ assert oidcCtx != null;
+ final OIDCClientInformation clientInformation = oidcCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setRequestObjectJWSAlg(JWSAlgorithm.RS256);
JWTClaimsSet ro = new JWTClaimsSet.Builder().subject("alice").build();
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro))
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -203,12 +207,15 @@ public class ValidateRequestObjectTest {
@Test
public void testRequestObjectAlgMatch()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
- oidcCtx.getClientInformation().getOIDCMetadata().setRequestObjectJWSAlg(new JWSAlgorithm("none"));
+ assert oidcCtx != null;
+ final OIDCClientInformation clientInformation = oidcCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setRequestObjectJWSAlg(new JWSAlgorithm("none"));
JWTClaimsSet ro = new JWTClaimsSet.Builder().subject("alice").build();
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro))
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -224,7 +231,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro))
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -240,7 +247,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro))
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -260,7 +267,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req = new AuthenticationRequest.Builder(rt, new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro)).nonce(new Nonce())
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -280,7 +287,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req = new AuthenticationRequest.Builder(rt, new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro)).nonce(new Nonce())
.state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -301,7 +308,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -321,7 +328,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -343,7 +350,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -365,7 +372,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -385,7 +392,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -405,7 +412,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -423,7 +430,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -442,7 +449,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -460,7 +467,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -479,7 +486,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(signed).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -494,7 +501,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro)).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
@@ -509,7 +516,7 @@ public class ValidateRequestObjectTest {
AuthenticationRequest req =
new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"), new ClientID("000123"),
URI.create("https://example.com/callback")).requestObject(new PlainJWT(ro)).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
oidcRespCtx.setRequestObject(req.getRequestObject());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_REQUEST_OBJECT);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateResponseTypeTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateResponseTypeTest.java
index b8ea993f..dcbd9113 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateResponseTypeTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateResponseTypeTest.java
@@ -50,7 +50,7 @@ public class ValidateResponseTypeTest extends BaseOIDCResponseActionTest {
action = new ValidateResponseType();
action.initialize();
final OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
metaData = new OIDCClientMetadata();
metaData.setResponseTypes(responseTypes);
metaData.setRedirectionURI(new URI("https://notmatching.org"));
@@ -95,7 +95,7 @@ public class ValidateResponseTypeTest extends BaseOIDCResponseActionTest {
} catch (ComponentInitializationException e) {
Assert.fail("Initializiation failed", e);
}
- profileRequestCtx.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
}
@Test
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateScopeTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateScopeTest.java
index 5a098a6c..e8596bd5 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateScopeTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateScopeTest.java
@@ -48,6 +48,7 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
/** {@link ValidateScope} unit test. */
+ at SuppressWarnings("null")
public class ValidateScopeTest extends BaseOIDCResponseActionTest {
/** Action to test. */
@@ -65,7 +66,7 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
action = new ValidateScope();
action.initialize();
final OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
metaData = new OIDCClientMetadata();
final Scope scope = new Scope();
for (final Scope.Value value : values) {
@@ -99,10 +100,12 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
// input is openid, profile, offline_access and email. profile and offline_access should be filtered out
// (offline because the request is implicit).
Assert.assertNotNull(respCtx.getScope());
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.OPENID));
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.EMAIL));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.OFFLINE_ACCESS));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.PROFILE));
+ final Scope scope = respCtx.getScope();
+ assert scope != null;
+ Assert.assertTrue(scope.contains(OIDCScopeValue.OPENID));
+ Assert.assertTrue(scope.contains(OIDCScopeValue.EMAIL));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.OFFLINE_ACCESS));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.PROFILE));
}
/**
@@ -143,10 +146,12 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
// input is openid, profile, offline_access and email. profile should be filtered out.
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.OPENID));
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.EMAIL));
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.OFFLINE_ACCESS));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.PROFILE));
+ final Scope scope = respCtx.getScope();
+ assert scope != null;
+ Assert.assertTrue(scope.contains(OIDCScopeValue.OPENID));
+ Assert.assertTrue(scope.contains(OIDCScopeValue.EMAIL));
+ Assert.assertTrue(scope.contains(OIDCScopeValue.OFFLINE_ACCESS));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.PROFILE));
final OIDCAuthenticationResponseTokenClaimsContext tokenClaimsCtx =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
@@ -161,7 +166,7 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
* @throws ComponentInitializationException
* @throws URISyntaxException
*/
- @Test
+ at Test
public void testTokenNoGrantedScopes() throws ComponentInitializationException, URISyntaxException {
action = new ValidateScope();
@@ -235,10 +240,12 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
// input is openid, profile, offline_access and email. profile should be filtered out.
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.OPENID));
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.EMAIL));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.OFFLINE_ACCESS));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.PROFILE));
+ final Scope scope = respCtx.getScope();
+ assert scope != null;
+ Assert.assertTrue(scope.contains(OIDCScopeValue.OPENID));
+ Assert.assertTrue(scope.contains(OIDCScopeValue.EMAIL));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.OFFLINE_ACCESS));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.PROFILE));
final OIDCAuthenticationResponseTokenClaimsContext tokenClaimsCtx =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
@@ -309,10 +316,12 @@ public class ValidateScopeTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
// input is openid, profile, offline_access and email. profile should be filtered out.
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.OPENID));
- Assert.assertTrue(respCtx.getScope().contains(OIDCScopeValue.EMAIL));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.OFFLINE_ACCESS));
- Assert.assertFalse(respCtx.getScope().contains(OIDCScopeValue.PROFILE));
+ final Scope scope = respCtx.getScope();
+ assert scope != null;
+ Assert.assertTrue(scope.contains(OIDCScopeValue.OPENID));
+ Assert.assertTrue(scope.contains(OIDCScopeValue.EMAIL));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.OFFLINE_ACCESS));
+ Assert.assertFalse(scope.contains(OIDCScopeValue.PROFILE));
final OIDCAuthenticationResponseTokenClaimsContext tokenClaimsCtx =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractIssuedJWTSecurityTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractIssuedJWTSecurityTest.java
index cba65a84..04f54336 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractIssuedJWTSecurityTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractIssuedJWTSecurityTest.java
@@ -210,6 +210,7 @@ public abstract class AbstractIssuedJWTSecurityTest extends AbstractOidcFlowTest
Assert.assertEquals(encryptedJwt.getPayload().toJSONObject().get("sub"), "mockSubject");
}
+ @SuppressWarnings("null")
protected static EncryptedJWT assertAndDecryptJwt(final JWT jwt, final JWEAlgorithm algorithm,
final EncryptionMethod method, final String clientSecret, final PrivateKey privateKey) {
@@ -312,6 +313,7 @@ public abstract class AbstractIssuedJWTSecurityTest extends AbstractOidcFlowTest
return obtainUserInfoResponse(clientId, null, null, jwsAlgorithm, null, null);
}
+ @SuppressWarnings("null")
public UserInfoSuccessResponse obtainUserInfoResponse(final String clientId, final String clientSecret,
final PublicKey publicKey, final JWSAlgorithm jwsAlgorithm, final JWEAlgorithm jweAlgorithm,
final EncryptionMethod encryptionMethod) {
@@ -591,7 +593,7 @@ public abstract class AbstractIssuedJWTSecurityTest extends AbstractOidcFlowTest
if ("RenderResult".equals(result.getOutcome().getId())) {
final ProfileRequestContext prc =
(ProfileRequestContext)request.getAttribute(ProfileRequestContext.BINDING_KEY);
- return prc.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class)
+ return prc.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class)
.getProcessedToken();
}
return null;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcApiFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcApiFlowTest.java
index c0336e11..4e1623e7 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcApiFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcApiFlowTest.java
@@ -68,6 +68,7 @@ public class AbstractOidcApiFlowTest extends AbstractOidcFlowTest {
return buildRefreshToken(clientId, subject, scope, userInfoDeliverySet, id, rootId, Instant.now(), null);
}
+ @SuppressWarnings("null")
protected RefreshToken buildRefreshToken(final String clientId, final String subject, final Scope scope,
final ClaimsSet userInfoDeliverySet, final String id, final String rootId, final Instant authTime,
final Instant chainExp)
@@ -115,6 +116,7 @@ public class AbstractOidcApiFlowTest extends AbstractOidcFlowTest {
return jwt.serialize();
}
+ @SuppressWarnings("null")
protected BearerAccessToken buildLegacyToken(final String clientId, final String subject, final Scope scope,
final ClaimsSet userInfoDeliverySet, final String... consentedClaims)
throws URISyntaxException, NoSuchAlgorithmException, DataSealerException, ComponentInitializationException {
@@ -124,6 +126,7 @@ public class AbstractOidcApiFlowTest extends AbstractOidcFlowTest {
Instant.now().plusSeconds(30)));
}
+ @SuppressWarnings("null")
protected BearerAccessToken buildJWTToken(final String clientId, final String subject, final Scope scope,
final Collection<String> audience, final PrivateKey key, final String alg) throws JOSEException {
final AccessTokenClaimsSet claims = new AccessTokenClaimsSet.Builder()
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcFlowTest.java
index 8f4d20e2..65d8faa9 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AbstractOidcFlowTest.java
@@ -34,6 +34,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
+
import org.apache.commons.codec.binary.Base64;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.storage.StorageService;
@@ -101,6 +103,7 @@ import net.shibboleth.shared.servlet.impl.HttpServletRequestResponseContext;
* Abstract unit test for the OIDC flows.
*/
@ContextConfiguration(locations = { "classpath*:/META-INF/net.shibboleth.idp/postconfig.xml",})
+ at SuppressWarnings("null")
public abstract class AbstractOidcFlowTest extends AbstractFlowTest {
public static final String END_STATE_ID = "CommitResponse";
@@ -180,7 +183,8 @@ public abstract class AbstractOidcFlowTest extends AbstractFlowTest {
return keyGen.genKeyPair();
}
- protected DataSealer getDataSealer() {
+ @Nonnull protected DataSealer getDataSealer() {
+ assert dataSealer != null;
return dataSealer;
}
@@ -188,8 +192,9 @@ public abstract class AbstractOidcFlowTest extends AbstractFlowTest {
assertFlowExecutionOutcome(result.getOutcome(), END_STATE_ID);
final ProfileRequestContext prc = retrieveProfileRequestContext(result);
Assert.assertNotNull(prc);
- Assert.assertNotNull(prc.getOutboundMessageContext());
- final Object responseMessage = prc.getOutboundMessageContext().getMessage();
+ assert prc != null;
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
+ final Object responseMessage = prc.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(responseMessage);
Assert.assertTrue(responseMessage instanceof Response);
return (Response) responseMessage;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
index 26099709..63d618f6 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
@@ -54,6 +54,7 @@ import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.AuthenticationErrorResponse;
import com.nimbusds.openid.connect.sdk.AuthenticationResponse;
import com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse;
+import com.nimbusds.openid.connect.sdk.OIDCClaimsRequest;
import com.nimbusds.openid.connect.sdk.claims.ClaimRequirement;
import com.nimbusds.openid.connect.sdk.claims.ClaimsSetRequest;
import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
@@ -68,6 +69,7 @@ import net.shibboleth.shared.security.DataSealerException;
/**
* Tests for the authorize-flow.
*/
+ at SuppressWarnings("null")
public class AuthorizeFlowTest extends AbstractOidcFlowTest {
public static final String FLOW_ID = "oidc/authorize";
@@ -560,7 +562,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(successResponse.getAccessToken().getValue(), getDataSealer());
Assert.assertEquals(token.getAudience(), Collections.singletonList(issuer));
- Assert.assertNull(token.getClaimsSet().getStringClaim("eduPersonScopedAffiliation"));
+ final JWTClaimsSet claimsSet = token.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNull(claimsSet.getStringClaim("eduPersonScopedAffiliation"));
Assert.assertNull(successResponse.getIssuer());
}
@@ -607,7 +611,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(successResponse.getAccessToken().getValue(), getDataSealer());
Assert.assertEquals(token.getAudience(), Collections.singletonList(issuer));
- Assert.assertNull(token.getClaimsSet().getStringClaim("eduPersonScopedAffiliation"));
+ final JWTClaimsSet claimsSet = token.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNull(claimsSet.getStringClaim("eduPersonScopedAffiliation"));
Assert.assertNotNull(successResponse.getIssuer());
Assert.assertEquals(successResponse.getIssuer().getValue(), issuer);
}
@@ -911,7 +917,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(successResponse.getAccessToken().getValue(), getDataSealer());
Assert.assertEquals(token.getAudience(), Collections.singletonList(issuer));
- Assert.assertNull(token.getClaimsSet().getStringClaim("eduPersonScopedAffiliation"));
+ final JWTClaimsSet claimsSet = token.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNull(claimsSet.getStringClaim("eduPersonScopedAffiliation"));
Assert.assertNull(successResponse.getIssuer());
}
@@ -1056,7 +1064,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(successResponse.getAccessToken().getValue(), getDataSealer());
Assert.assertEquals(token.getAudience(), Collections.singletonList(issuer));
- Assert.assertNull(token.getClaimsSet().getStringClaim("eduPersonScopedAffiliation"));
+ final JWTClaimsSet claimsSet = token.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNull(claimsSet.getStringClaim("eduPersonScopedAffiliation"));
}
@Test
@@ -1146,8 +1156,10 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(successResponse.getAccessToken().getValue(), getDataSealer());
Assert.assertEquals(token.getAudience(), Collections.singletonList(issuer));
- Assert.assertNull(token.getClaimsSet().getStringClaim("eduPersonScopedAffiliation"));
- final String customClaim = token.getClaimsSet().getStringClaim("custom_access_token_claim");
+ final JWTClaimsSet claimsSet = token.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNull(claimsSet.getStringClaim("eduPersonScopedAffiliation"));
+ final String customClaim = claimsSet.getStringClaim("custom_access_token_claim");
Assert.assertNotNull(customClaim);
Assert.assertEquals(customClaim, "value2");
}
@@ -1427,10 +1439,12 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AuthorizeCodeClaimsSet code =
AuthorizeCodeClaimsSet.parse(successResponse.getAuthorizationCode().getValue(), getDataSealer());
Assert.assertNotNull(code.getClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getIDTokenClaimsRequest());
- Assert.assertNull(code.getClaimsRequest().getUserInfoClaimsRequest());
- Assert.assertTrue(code.getClaimsRequest().getIDTokenClaimsRequest().getClaimNames(false).contains("email"));
- final ClaimsSetRequest.Entry email = code.getClaimsRequest().getIDTokenClaimsRequest().get("email", null);
+ final OIDCClaimsRequest claimsRequest = code.getClaimsRequest();
+ assert claimsRequest != null;
+ Assert.assertNotNull(claimsRequest.getIDTokenClaimsRequest());
+ Assert.assertNull(claimsRequest.getUserInfoClaimsRequest());
+ Assert.assertTrue(claimsRequest.getIDTokenClaimsRequest().getClaimNames(false).contains("email"));
+ final ClaimsSetRequest.Entry email = claimsRequest.getIDTokenClaimsRequest().get("email", null);
Assert.assertEquals(email.getClaimName(), "email");
Assert.assertEquals(email.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
}
@@ -1460,10 +1474,12 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AuthorizeCodeClaimsSet code =
AuthorizeCodeClaimsSet.parse(successResponse.getAuthorizationCode().getValue(), getDataSealer());
Assert.assertNotNull(code.getClaimsRequest());
- Assert.assertNull(code.getClaimsRequest().getIDTokenClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getUserInfoClaimsRequest());
- Assert.assertTrue(code.getClaimsRequest().getUserInfoClaimsRequest().getClaimNames(false).contains("email"));
- final ClaimsSetRequest.Entry email = code.getClaimsRequest().getUserInfoClaimsRequest().get("email", null);
+ final OIDCClaimsRequest claimsRequest = code.getClaimsRequest();
+ assert claimsRequest != null;
+ Assert.assertNull(claimsRequest.getIDTokenClaimsRequest());
+ Assert.assertNotNull(claimsRequest.getUserInfoClaimsRequest());
+ Assert.assertTrue(claimsRequest.getUserInfoClaimsRequest().getClaimNames(false).contains("email"));
+ final ClaimsSetRequest.Entry email = claimsRequest.getUserInfoClaimsRequest().get("email", null);
Assert.assertEquals(email.getClaimName(), "email");
Assert.assertEquals(email.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
}
@@ -1492,7 +1508,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AuthorizeCodeClaimsSet code =
AuthorizeCodeClaimsSet.parse(successResponse.getAuthorizationCode().getValue(), getDataSealer());
- final Object customClaim = code.getClaimsSet().getClaim("custom_code_claim");
+ final JWTClaimsSet claimsSet = code.getClaimsSet();
+ assert claimsSet != null;
+ final Object customClaim = claimsSet.getClaim("custom_code_claim");
Assert.assertNotNull(customClaim);
Assert.assertEquals(customClaim, "value1");
}
@@ -1845,17 +1863,19 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final AuthorizeCodeClaimsSet code =
AuthorizeCodeClaimsSet.parse(successResponse.getAuthorizationCode().getValue(), getDataSealer());
Assert.assertNotNull(code.getClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getIDTokenClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getUserInfoClaimsRequest());
- Assert.assertTrue(code.getClaimsRequest().getUserInfoClaimsRequest().getClaimNames(false)
+ final OIDCClaimsRequest claimsRequest = code.getClaimsRequest();
+ assert claimsRequest != null;
+ Assert.assertNotNull(claimsRequest.getIDTokenClaimsRequest());
+ Assert.assertNotNull(claimsRequest.getUserInfoClaimsRequest());
+ Assert.assertTrue(claimsRequest.getUserInfoClaimsRequest().getClaimNames(false)
.contains("family_name"));
- Assert.assertTrue(code.getClaimsRequest().getIDTokenClaimsRequest().getClaimNames(false)
+ Assert.assertTrue(claimsRequest.getIDTokenClaimsRequest().getClaimNames(false)
.contains("given_name"));
- final ClaimsSetRequest.Entry familyName = code.getClaimsRequest().getUserInfoClaimsRequest().get("family_name",
+ final ClaimsSetRequest.Entry familyName = claimsRequest.getUserInfoClaimsRequest().get("family_name",
null);
Assert.assertEquals(familyName.getClaimName(), "family_name");
Assert.assertEquals(familyName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
- final ClaimsSetRequest.Entry givenName = code.getClaimsRequest().getIDTokenClaimsRequest().get("given_name",
+ final ClaimsSetRequest.Entry givenName = claimsRequest.getIDTokenClaimsRequest().get("given_name",
null);
Assert.assertEquals(givenName.getClaimName(), "given_name");
Assert.assertEquals(givenName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
@@ -1978,7 +1998,9 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
final List<Pair<String, String>> pairs) {
final StringBuffer query = new StringBuffer();
for (final Pair<String, String> pair : pairs) {
- request.addParameter(pair.getFirst(), pair.getSecond());
+ final String first = pair.getFirst();
+ assert first != null;
+ request.addParameter(first, pair.getSecond());
try {
query.append(pair.getFirst() + "=" + URLEncoder.encode(pair.getSecond(), "UTF-8") + "&");
} catch (UnsupportedEncodingException e) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/ClientCredentialsTokenFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/ClientCredentialsTokenFlowTest.java
index 44f3ef18..af74f631 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/ClientCredentialsTokenFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/ClientCredentialsTokenFlowTest.java
@@ -57,6 +57,7 @@ import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod;
import com.nimbusds.oauth2.sdk.auth.ClientSecretJWT;
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication;
+import com.nimbusds.oauth2.sdk.id.ClientID;
import com.nimbusds.oauth2.sdk.token.AccessToken;
import net.shibboleth.idp.plugin.oidc.op.token.support.AccessTokenClaimsSet;
@@ -69,6 +70,7 @@ import net.shibboleth.shared.security.DataSealerException;
/**
* Unit tests for the token flow when using the client_credentials grant type.
*/
+ at SuppressWarnings("null")
public class ClientCredentialsTokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
public static final String FLOW_ID = "oidc/token";
@@ -334,17 +336,6 @@ public class ClientCredentialsTokenFlowTest extends AbstractOidcClientAuthentica
Collections.singletonList(resourceSaml), "customEmailName", "eduPersonScopedAffiliation");
}
-
- private AccessTokenClaimsSet unwrapAccessToken(final AccessTokenResponse tokenResponse) {
- final AccessToken accessToken = tokenResponse.getTokens().getAccessToken();
- Assert.assertNotNull(accessToken);
- try {
- return AccessTokenClaimsSet.parse(accessToken.getValue(), getDataSealer());
- } catch (final java.text.ParseException | DataSealerException e) {
- return null;
- }
- }
-
protected FlowExecutionResult launchWithJwtAuthentication(final JWTAuthentication authnMethod,
final JWSAlgorithm algorithm) throws Exception {
final String clientId = authnMethod.getClientID().getValue();
@@ -409,7 +400,7 @@ public class ClientCredentialsTokenFlowTest extends AbstractOidcClientAuthentica
* @throws ParseException
* @throws JOSEException
*/
- private void verifyClaims(@Nullable final String type, @Nonnull final AccessToken token, @Nonnull final String cid,
+ private void verifyClaims(@Nullable final String type, @Nonnull final AccessToken token, @Nonnull final String cid,
@Nonnull final Scope s, @Nonnull @NonnullElements final Collection<String> audiences,
@Nullable final String...customClaims)
throws ParseException, DataSealerException, JOSEException {
@@ -419,8 +410,12 @@ public class ClientCredentialsTokenFlowTest extends AbstractOidcClientAuthentica
assertNotNull(at);
assertEquals(at.getACR(), null);
assertEquals(at.getAudience(), audiences);
- assertTrue(at.getAuthenticationTime().isBefore(Instant.now()));
- assertEquals(at.getClientID().getValue(), cid);
+ final Instant authenticationTime = at.getAuthenticationTime();
+ assert authenticationTime != null;
+ assertTrue(authenticationTime.isBefore(Instant.now()));
+ final ClientID clientId = at.getClientID();
+ assert clientId != null;
+ assertEquals(clientId.getValue(), cid);
assertEquals(at.getExp(), at.getIssuedAt().plusSeconds(600));
assertEquals(at.getIssuer(), "https://op.example.org");
assertTrue(at.getIssuedAt().isBefore(Instant.now()));
@@ -429,7 +424,9 @@ public class ClientCredentialsTokenFlowTest extends AbstractOidcClientAuthentica
if (customClaims != null) {
for (final String c : customClaims) {
// These should be absent in opaque tokens.
- assertNull(at.getClaimsSet().getClaim(c));
+ final JWTClaimsSet claimsSet = at.getClaimsSet();
+ assert claimsSet != null;
+ assertNull(claimsSet.getClaim(c));
}
}
return;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/EndSessionFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/EndSessionFlowTest.java
index 769aa376..54ec8951 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/EndSessionFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/EndSessionFlowTest.java
@@ -367,6 +367,7 @@ public class EndSessionFlowTest extends AbstractOidcFlowTest {
};
}
+ @SuppressWarnings("null")
protected IdPSession buildIdPSessionWithDefaultSP() {
return buildIdPSession(sessionManager, new OIDCRPSession.Builder()
.serviceId(clientId)
@@ -384,6 +385,7 @@ public class EndSessionFlowTest extends AbstractOidcFlowTest {
try {
final IdPSession idpSession = sessionManager.createSession("mockSessionPrincipal");
for (final SPSession session : sessions) {
+ assert session != null;
idpSession.addSPSession(session);
}
return idpSession;
@@ -401,7 +403,9 @@ public class EndSessionFlowTest extends AbstractOidcFlowTest {
final List<Pair<String, String>> pairs) {
final StringBuffer query = new StringBuffer();
for (final Pair<String, String> pair : pairs) {
- request.addParameter(pair.getFirst(), pair.getSecond());
+ final String first = pair.getFirst();
+ assert first != null;
+ request.addParameter(first, pair.getSecond());
try {
query.append(pair.getFirst() + "=" + URLEncoder.encode(pair.getSecond(), "UTF-8") + "&");
} catch (UnsupportedEncodingException e) {
@@ -422,8 +426,10 @@ public class EndSessionFlowTest extends AbstractOidcFlowTest {
protected static boolean isSessionValid(final StorageBackedSessionManager sessionManager,
final IdPSession session) {
+ final String id = session.getId();
+ assert id != null;
try {
- return sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId()))) != null;
+ return sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(id))) != null;
} catch (ResolverException e) {
Assert.fail();
return false;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWETest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWETest.java
index b19b93db..0a113850 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWETest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWETest.java
@@ -219,6 +219,7 @@ public class IdTokenHintJWETest extends IssuedEncryptedJWTTest {
}
}
+ @SuppressWarnings("null")
protected void assertErrorIdTokenHintResponse(final String idTokenHint,
final JWSAlgorithm idTokenHintSigAlg, final JWEAlgorithm idTokenHintEncAlg,
final EncryptionMethod idTokenHintEncMethod, final String clientSecret, final PublicKey publicKey) {
@@ -260,6 +261,7 @@ public class IdTokenHintJWETest extends IssuedEncryptedJWTTest {
}
}
+ @SuppressWarnings("null")
protected void assertSuccessIdTokenHintResponse(final String idTokenHint,
final JWSAlgorithm idTokenHintSigAlg, final JWEAlgorithm idTokenHintEncAlg,
final EncryptionMethod idTokenHintEncMethod, final String clientSecret, final PublicKey publicKey) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWSTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWSTest.java
index d5b61698..77971b60 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWSTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IdTokenHintJWSTest.java
@@ -93,6 +93,7 @@ public class IdTokenHintJWSTest extends IssuedSignedJWTTest {
assertErrorIdTokenHintResponse(jwt.serialize(), jwsAlgorithm, clientSecret, publicKey);
}
+ @SuppressWarnings("null")
protected void assertErrorIdTokenHintResponse(final String IdTokenHint,
final JWSAlgorithm IdTokenHintSigAlg, final String clientSecret, final PublicKey publicKey) {
request.setMethod("GET");
@@ -125,6 +126,7 @@ public class IdTokenHintJWSTest extends IssuedSignedJWTTest {
}
}
+ @SuppressWarnings("null")
protected void assertSuccessIdTokenHintResponse(final String IdTokenHint,
final JWSAlgorithm IdTokenHintSigAlg, final String clientSecret, final PublicKey publicKey) {
request.setMethod("GET");
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IntrospectionFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IntrospectionFlowTest.java
index 9ff6545e..2f1c7ebb 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IntrospectionFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IntrospectionFlowTest.java
@@ -430,6 +430,7 @@ public class IntrospectionFlowTest extends AbstractOidcClientAuthenticationFlowT
List.of(new Audience("https://sp.example.org"), new Audience(clientId)));
}
+ @SuppressWarnings("null")
@Test
public void testFailureJWTExpired() throws JOSEException, IOException {
storeMetadata(storageService, clientId, clientSecret, scope);
@@ -456,6 +457,7 @@ public class IntrospectionFlowTest extends AbstractOidcClientAuthenticationFlowT
Assert.assertFalse(resp.isActive());
}
+ @SuppressWarnings("null")
@Test
public void testFailureJWTNotYetValid() throws JOSEException, IOException {
storeMetadata(storageService, clientId, clientSecret, scope);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssueRegistrationAccessTokenFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssueRegistrationAccessTokenFlowTest.java
index 5766cfa0..3e009673 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssueRegistrationAccessTokenFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssueRegistrationAccessTokenFlowTest.java
@@ -237,7 +237,9 @@ public class IssueRegistrationAccessTokenFlowTest extends AbstractOidcFlowTest {
Assert.assertNotNull(accessToken);
final DataSealer dataSealer = BaseOIDCResponseActionTest.initializeDataSealer();
- final String decryptedToken = dataSealer.unwrap(accessToken.getValue());
+ final String value = accessToken.getValue();
+ assert value != null;
+ final String decryptedToken = dataSealer.unwrap(value);
final RegistrationClaimsSet claimsSet = new ObjectMapper().readValue(decryptedToken,
RegistrationClaimsSet.class);
Assert.assertEquals(claimsSet.getKeyType(), "rt");
@@ -248,6 +250,7 @@ public class IssueRegistrationAccessTokenFlowTest extends AbstractOidcFlowTest {
if (policy != null) {
final Map<String, MetadataPolicy> tokenPolicy = claimsSet.getMetadata();
Assert.assertNotNull(tokenPolicy);
+ assert tokenPolicy != null;
Assert.assertEquals(tokenPolicy.size(), policy.size());
for (final String claim : tokenPolicy.keySet()) {
Assert.assertEquals(tokenPolicy.get(claim).toString(), policy.get(claim).toString());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssuedEncryptedJWTTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssuedEncryptedJWTTest.java
index a436b793..197f8766 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssuedEncryptedJWTTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/IssuedEncryptedJWTTest.java
@@ -31,6 +31,7 @@ import com.nimbusds.openid.connect.sdk.UserInfoSuccessResponse;
* Tests for verifying that the JWT encryption issued by OP matches the expected configuration. OP may issue JWTs
* from authorize, token and userinfo endpoints, depending on the RP or resource metadata.
*/
+ at SuppressWarnings("deprecation")
public class IssuedEncryptedJWTTest extends AbstractIssuedJWTSecurityTest {
/** Enabled JWS algorithms to be iterated over in the tests. */
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/LogoutPropagationFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/LogoutPropagationFlowTest.java
index 8f10d4f2..088b02b1 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/LogoutPropagationFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/LogoutPropagationFlowTest.java
@@ -174,11 +174,11 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
Assert.assertEquals(result.getOutcome().getId(), "RenderResult");
final ProfileRequestContext prc = retrievePrcViaRequest();
final OIDCBackChannelLogoutPropagationContext backChannelCtx =
- prc.getOutboundMessageContext().getSubcontext(OIDCLogoutPropagationContext.class)
- .getSubcontext(OIDCBackChannelLogoutPropagationContext.class);
+ prc.ensureOutboundMessageContext().ensureSubcontext(OIDCLogoutPropagationContext.class)
+ .ensureSubcontext(OIDCBackChannelLogoutPropagationContext.class);
Assert.assertNotNull(backChannelCtx.getLogoutTokenClaimsSet());
final JWT logoutToken =
- prc.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class)
+ prc.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class)
.getProcessedToken();
Assert.assertNotNull(logoutToken);
Assert.assertTrue(logoutToken instanceof SignedJWT);
@@ -204,8 +204,7 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
protected void assertPropagationResult(final LogoutPropagationContext.Result expected) {
final ProfileRequestContext prc = retrievePrcViaRequest();
- final LogoutPropagationContext propCtx = prc.getSubcontext(LogoutPropagationContext.class);
- Assert.assertNotNull(propCtx);
+ final LogoutPropagationContext propCtx = prc.ensureSubcontext(LogoutPropagationContext.class);
Assert.assertEquals(propCtx.getResult(), expected);
}
@@ -213,6 +212,7 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
return buildIdPSessionWithDefaultSP(sessionManager, clientId, issuer, sessionId, subject);
}
+ @SuppressWarnings("null")
protected static IdPSession buildIdPSessionWithDefaultSP(final StorageBackedSessionManager sessionManager,
final String clientId, final String issuer, final String sessionId, final String subject) {
return buildIdPSession(sessionManager, new OIDCRPSession.Builder()
@@ -232,6 +232,7 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
try {
final IdPSession idpSession = sessionManager.createSession("mockSessionPrincipal");
for (final SPSession session : sessions) {
+ assert session != null;
idpSession.addSPSession(session);
}
return idpSession;
@@ -249,7 +250,9 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
final List<Pair<String, String>> pairs) {
final StringBuffer query = new StringBuffer();
for (final Pair<String, String> pair : pairs) {
- request.addParameter(pair.getFirst(), pair.getSecond());
+ final String first = pair.getFirst();
+ assert first != null;
+ request.addParameter(first, pair.getSecond());
try {
query.append(pair.getFirst() + "=" + URLEncoder.encode(pair.getSecond(), "UTF-8") + "&");
} catch (UnsupportedEncodingException e) {
@@ -270,8 +273,10 @@ public class LogoutPropagationFlowTest extends AbstractOidcFlowTest {
protected static boolean isSessionValid(final StorageBackedSessionManager sessionManager,
final IdPSession session) {
+ final String id = session.getId();
+ assert id != null;
try {
- return sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId()))) != null;
+ return sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(id))) != null;
} catch (ResolverException e) {
Assert.fail();
return false;
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationFlowTest.java
index 27f71b34..27243f7c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationFlowTest.java
@@ -20,6 +20,9 @@ import java.net.URISyntaxException;
import java.time.Instant;
import java.util.Set;
+import javax.annotation.Nonnull;
+
+import org.opensaml.storage.StorageRecord;
import org.opensaml.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -106,8 +109,13 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
parseSuccessResponse(result, OIDCClientInformationResponse.class);
final OIDCClientInformation clientInfo = parsedResponse.getOIDCClientInformation();
final OIDCClientMetadata metadata = clientInfo.getOIDCMetadata();
- final String record = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
- clientInfo.getID().toString()).getValue();
+ final String clientId = clientInfo.getID().getValue();
+ assert clientId != null;
+ assert storageService != null;
+ final StorageRecord<String> storageRecord = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
+ clientId);
+ assert storageRecord != null;
+ final String record = storageRecord.getValue();
Assert.assertNotNull(record);
final JSONParser parser = new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE);
final OIDCClientInformation storedInfo = OIDCClientInformation.parse((JSONObject) parser.parse(record));
@@ -141,8 +149,13 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
parseSuccessResponse(result, OIDCClientInformationResponse.class);
final OIDCClientInformation clientInfo = parsedResponse.getOIDCClientInformation();
final OIDCClientMetadata metadata = clientInfo.getOIDCMetadata();
- final String record = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
- clientInfo.getID().toString()).getValue();
+ final String clientId = clientInfo.getID().getValue();
+ assert clientId != null;
+ assert storageService != null;
+ final StorageRecord<String> storageRecord = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
+ clientId);
+ assert storageRecord != null;
+ final String record = storageRecord.getValue();
Assert.assertNotNull(record);
final JSONParser parser = new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE);
final OIDCClientInformation storedInfo = OIDCClientInformation.parse((JSONObject) parser.parse(record));
@@ -162,8 +175,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
@Test
public void testAccessToken_nonCompliantWithProfilePolicy1() throws Exception {
setJsonRequest("POST", "{ \"redirect_uris\":[\"" + redirectUri + "\"] }");
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://invalid.domain.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://invalid.domain.org/cb\"]"));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, RegistrationError.INVALID_CLIENT_METADATA.getCode());
}
@@ -171,8 +183,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
@Test
public void testAccessToken_nonCompliantWithProfilePolicy2() throws Exception {
setJsonRequest("POST", "{ \"redirect_uris\":[\"" + redirectUri + "\"], \"id_token_signed_response_alg\":\"HS256\" }");
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, RegistrationError.INVALID_CLIENT_METADATA.getCode());
}
@@ -180,8 +191,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
@Test
public void testAccessToken_success() throws Exception {
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
assertSuccessfulResponse(flowExecutor.launchExecution(FLOW_ID, null, externalContext), null);
}
@@ -190,8 +200,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
clientId = "https://example.org";
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(true, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(true, "[\"https://example.org/cb\"]"));
assertSuccessfulResponse(flowExecutor.launchExecution(FLOW_ID, null, externalContext), clientId);
}
@@ -200,8 +209,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
clientId = "https://example.org";
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
assertSuccessfulResponse(flowExecutor.launchExecution(FLOW_ID, null, externalContext), null);
// Repeat should work.
@@ -209,8 +217,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
initializeThreadLocals();
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(true, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(true, "[\"https://example.org/cb\"]"));
assertSuccessfulResponse(flowExecutor.launchExecution(FLOW_ID, null, externalContext), null);
}
@@ -219,8 +226,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
clientId = "https://example.org";
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
assertSuccessfulResponse(flowExecutor.launchExecution(FLOW_ID, null, externalContext), null);
// Repeat should not work.
@@ -228,8 +234,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
initializeThreadLocals();
setJsonRequest("POST", buildRequestMessage(redirectUri));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, OAuth2Error.SERVER_ERROR_CODE);
}
@@ -237,8 +242,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
@Test
public void testAccessToken_successCustomClaimIgnored() throws Exception {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"customClaim\":\"customValue\""));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]")
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]"));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertSuccessfulResponse(result, null);
final OIDCClientInformationResponse parsedResponse =
@@ -249,8 +253,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
@Test
public void testAccessToken_successCustomClaimInPolicyAdded() throws Exception {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"customClaim\":\"customValue\""));
- request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]", new String[] {"customClaim"})
- .toAuthorizationHeader());
+ request.addHeader("Authorization", buildRegistrationAccessToken(false, "[\"https://example.org/cb\"]", new String[] {"customClaim"}));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertSuccessfulResponse(result, null);
final OIDCClientInformationResponse parsedResponse =
@@ -263,7 +266,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
setJsonRequest("POST", "{ \"test\":false }");
rpId = "mockDynRegClientNoProfilePolicy";
request.addHeader("Authorization", buildRegistrationAccessToken(false, (String) null,
- (String[]) null).toAuthorizationHeader());
+ (String[]) null));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, "invalid_client_metadata");
}
@@ -274,7 +277,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"grant_types\":[\"authorization_code\"]"));
rpId = "mockDynRegClientAnotherProfilePolicy";
request.addHeader("Authorization", buildRegistrationAccessToken(false, (String) null,
- (String[]) null).toAuthorizationHeader());
+ (String[]) null));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, "invalid_client_metadata");
}
@@ -284,7 +287,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"grant_types\":[\"implicit\"]"));
rpId = "mockDynRegClientAnotherProfilePolicy";
request.addHeader("Authorization", buildRegistrationAccessToken(false, (String) null,
- (String[]) null).toAuthorizationHeader());
+ (String[]) null));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertSuccessfulResponse(result, null);
final OIDCClientInformationResponse parsedResponse =
@@ -297,7 +300,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"grant_types\":[\"authorization_code\"]"));
rpId = "alwaysFailingMetadataPolicy";
request.addHeader("Authorization", buildRegistrationAccessToken(false, (String) null,
- (String[]) null).toAuthorizationHeader());
+ (String[]) null));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, "invalid_client_metadata");
}
@@ -307,7 +310,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
setJsonRequest("POST", buildRequestMessage(redirectUri, "\"grant_types\":[\"authorization_code\"]"));
rpId = "invalidBeanMetadataPolicy";
request.addHeader("Authorization", buildRegistrationAccessToken(false, (String) null,
- (String[]) null).toAuthorizationHeader());
+ (String[]) null));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, "invalid_client_metadata");
}
@@ -323,8 +326,13 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
} else {
Assert.assertNotEquals(clientId, clientInfo.getID().getValue());
}
- final String record = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
- clientInfo.getID().toString()).getValue();
+ final String clientIdValue = clientInfo.getID().getValue();
+ assert clientIdValue != null;
+ assert storageService != null;
+ final StorageRecord<String> storageRecord = storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME,
+ clientIdValue);
+ assert storageRecord != null;
+ final String record = storageRecord.getValue();
Assert.assertNotNull(record);
final JSONParser parser = new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE);
final OIDCClientInformation storedInfo = OIDCClientInformation.parse((JSONObject) parser.parse(record));
@@ -344,7 +352,7 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
Assert.assertNull(clientInfo.getSecret().getExpirationDate());
}
- protected BearerAccessToken buildRegistrationAccessToken(final boolean replacement, final String redirectUriSubset,
+ @Nonnull protected String buildRegistrationAccessToken(final boolean replacement, final String redirectUriSubset,
final String... additionalPolicyClaims) throws Exception {
final StringBuilder metadata = new StringBuilder();
if (additionalPolicyClaims != null) {
@@ -373,8 +381,11 @@ public class RegistrationFlowTest extends AbstractOidcFlowTest {
"\"replacement\":" + Boolean.toString(replacement) + "," +
"\"metadata\":" + (metadata.length() == 0 ? "null" : "{" + metadata.toString()) + "}" +
"}";
- return new BearerAccessToken(getDataSealer().wrap(json,
+ final BearerAccessToken token = new BearerAccessToken(getDataSealer().wrap(json,
Instant.now().plusSeconds(30)));
+ final String result = token.toAuthorizationHeader();
+ assert result != null;
+ return result;
}
protected String buildRequestMessage(final String redirectUri) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationManagementFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationManagementFlowTest.java
index f6490a97..2855542b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationManagementFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RegistrationManagementFlowTest.java
@@ -41,6 +41,7 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import jakarta.servlet.http.HttpServletResponse;
import net.minidev.json.JSONObject;
import net.shibboleth.oidc.metadata.impl.BaseStorageServiceClientInformationComponent;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
/**
* clients administration flow test.
@@ -83,6 +84,7 @@ public class RegistrationManagementFlowTest extends AbstractOidcFlowTest {
Assert.assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_FOUND);
}
+ @SuppressWarnings("null")
@Test
public void testFetchingExistingClient() throws Exception {
clientId = "mockClientId";
@@ -96,6 +98,7 @@ public class RegistrationManagementFlowTest extends AbstractOidcFlowTest {
Assert.assertTrue(recordExists(clientId));
}
+ @SuppressWarnings("null")
@Test
public void testDeletingExistingClient() throws Exception {
clientId = "mockClientId";
@@ -109,6 +112,7 @@ public class RegistrationManagementFlowTest extends AbstractOidcFlowTest {
Assert.assertFalse(recordExists(clientId));
}
+ @SuppressWarnings("null")
@Test
public void testFetchinggNonExistingClient() throws Exception {
clientId = "mockClientId";
@@ -138,11 +142,11 @@ public class RegistrationManagementFlowTest extends AbstractOidcFlowTest {
Assert.assertEquals(metadata.getGrantTypes().iterator().next(), GrantType.AUTHORIZATION_CODE);
}
- protected boolean recordExists(final String clientId) throws Exception {
+ protected boolean recordExists(@Nonnull final String clientId) throws Exception {
return storageService.read(BaseStorageServiceClientInformationComponent.CONTEXT_NAME, clientId) != null;
}
- private String sampleRecord() {
+ @Nonnull @NotEmpty private String sampleRecord() {
return " {\n"
+ " \"scope\":\"openid profile\",\n"
+ " \"redirect_uris\":[\"https://example.org/redirect_uri\"],\n"
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWETest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWETest.java
index 351a0ca5..c3f70c8c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWETest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWETest.java
@@ -40,6 +40,7 @@ import com.nimbusds.jwt.PlainJWT;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.AuthenticationResponse;
import com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse;
+import com.nimbusds.openid.connect.sdk.OIDCClaimsRequest;
import com.nimbusds.openid.connect.sdk.claims.ClaimRequirement;
import com.nimbusds.openid.connect.sdk.claims.ClaimsSetRequest;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
@@ -269,6 +270,7 @@ public class RequestObjectJWETest extends IssuedEncryptedJWTTest {
}
}
+ @SuppressWarnings("null")
protected void assertSuccessRequestObjectResponse(final String requestObject,
final JWSAlgorithm requestObjectSigAlg, final JWEAlgorithm requestObjectEncAlg,
final EncryptionMethod requestObjectEncMethod, final String clientSecret, final PublicKey publicKey) {
@@ -319,18 +321,20 @@ public class RequestObjectJWETest extends IssuedEncryptedJWTTest {
}
if (StringSupport.trimOrNull(requestObject) != null) {
Assert.assertNotNull(code.getClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getIDTokenClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getUserInfoClaimsRequest());
- Assert.assertTrue(code.getClaimsRequest().getUserInfoClaimsRequest().getClaimNames(false)
+ final OIDCClaimsRequest claimsRequest = code.getClaimsRequest();
+ assert claimsRequest != null;
+ Assert.assertNotNull(claimsRequest.getIDTokenClaimsRequest());
+ Assert.assertNotNull(claimsRequest.getUserInfoClaimsRequest());
+ Assert.assertTrue(claimsRequest.getUserInfoClaimsRequest().getClaimNames(false)
.contains("family_name"));
- Assert.assertTrue(code.getClaimsRequest().getIDTokenClaimsRequest().getClaimNames(false)
+ Assert.assertTrue(claimsRequest.getIDTokenClaimsRequest().getClaimNames(false)
.contains("given_name"));
final ClaimsSetRequest.Entry familyName =
- code.getClaimsRequest().getUserInfoClaimsRequest().get("family_name", null);
+ claimsRequest.getUserInfoClaimsRequest().get("family_name", null);
Assert.assertEquals(familyName.getClaimName(), "family_name");
Assert.assertEquals(familyName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
final ClaimsSetRequest.Entry givenName =
- code.getClaimsRequest().getIDTokenClaimsRequest().get("given_name", null);
+ claimsRequest.getIDTokenClaimsRequest().get("given_name", null);
Assert.assertEquals(givenName.getClaimName(), "given_name");
Assert.assertEquals(givenName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWSTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWSTest.java
index 9f741f25..77b96207 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWSTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RequestObjectJWSTest.java
@@ -38,6 +38,7 @@ import com.nimbusds.jwt.PlainJWT;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.AuthenticationResponse;
import com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse;
+import com.nimbusds.openid.connect.sdk.OIDCClaimsRequest;
import com.nimbusds.openid.connect.sdk.claims.ClaimRequirement;
import com.nimbusds.openid.connect.sdk.claims.ClaimsSetRequest;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
@@ -124,6 +125,7 @@ public class RequestObjectJWSTest extends IssuedSignedJWTTest {
}
}
+ @SuppressWarnings("null")
protected void assertSuccessRequestObjectResponse(final String requestObject,
final JWSAlgorithm requestObjectSigAlg, final String clientSecret, final PublicKey publicKey) {
request.setMethod("GET");
@@ -171,18 +173,20 @@ public class RequestObjectJWSTest extends IssuedSignedJWTTest {
}
if (StringSupport.trimOrNull(requestObject) != null) {
Assert.assertNotNull(code.getClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getIDTokenClaimsRequest());
- Assert.assertNotNull(code.getClaimsRequest().getUserInfoClaimsRequest());
- Assert.assertTrue(code.getClaimsRequest().getUserInfoClaimsRequest().getClaimNames(false)
+ final OIDCClaimsRequest claimsRequest = code.getClaimsRequest();
+ assert claimsRequest != null;
+ Assert.assertNotNull(claimsRequest.getIDTokenClaimsRequest());
+ Assert.assertNotNull(claimsRequest.getUserInfoClaimsRequest());
+ Assert.assertTrue(claimsRequest.getUserInfoClaimsRequest().getClaimNames(false)
.contains("family_name"));
- Assert.assertTrue(code.getClaimsRequest().getIDTokenClaimsRequest().getClaimNames(false)
+ Assert.assertTrue(claimsRequest.getIDTokenClaimsRequest().getClaimNames(false)
.contains("given_name"));
final ClaimsSetRequest.Entry familyName =
- code.getClaimsRequest().getUserInfoClaimsRequest().get("family_name", null);
+ claimsRequest.getUserInfoClaimsRequest().get("family_name", null);
Assert.assertEquals(familyName.getClaimName(), "family_name");
Assert.assertEquals(familyName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
final ClaimsSetRequest.Entry givenName =
- code.getClaimsRequest().getIDTokenClaimsRequest().get("given_name", null);
+ claimsRequest.getIDTokenClaimsRequest().get("given_name", null);
Assert.assertEquals(givenName.getClaimName(), "given_name");
Assert.assertEquals(givenName.getClaimRequirement(), ClaimRequirement.ESSENTIAL);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RevocationFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RevocationFlowTest.java
index 1a9c8115..6021c7cf 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RevocationFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/RevocationFlowTest.java
@@ -315,6 +315,7 @@ public class RevocationFlowTest extends AbstractOidcClientAuthenticationFlowTest
parseSuccessResponse(result, OAuth2RevocationSuccessResponse.class);
}
+ @SuppressWarnings("null")
@Test
public void testSuccessJWTExpired() throws JOSEException, IOException {
setBasicAuth(clientId, clientSecret);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
index 60699e62..15176a3f 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
@@ -26,6 +26,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
+
import org.opensaml.storage.RevocationCache;
import org.opensaml.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +45,7 @@ import com.nimbusds.jose.EncryptionMethod;
import com.nimbusds.jose.JWEAlgorithm;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jwt.JWT;
+import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import com.nimbusds.oauth2.sdk.AccessTokenResponse;
import com.nimbusds.oauth2.sdk.AuthorizationCode;
@@ -77,6 +80,7 @@ import net.shibboleth.shared.security.impl.SecureRandomIdentifierGenerationStrat
/**
* Unit tests for the token flow.
*/
+ at SuppressWarnings("null")
public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
public static final String FLOW_ID = "oidc/token";
@@ -529,16 +533,20 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
final AccessTokenClaimsSet accessToken =
AccessTokenClaimsSet.parse(response.getTokens().getAccessToken().getValue(), getDataSealer());
- final String atCustomAtClaim = accessToken.getClaimsSet().getStringClaim("custom_access_token_claim");
- final String atCustomRtClaim = accessToken.getClaimsSet().getStringClaim("custom_refresh_token_claim");
+ final JWTClaimsSet atClaimsSet = accessToken.getClaimsSet();
+ assert atClaimsSet != null;
+ final String atCustomAtClaim = atClaimsSet.getStringClaim("custom_access_token_claim");
+ final String atCustomRtClaim = atClaimsSet.getStringClaim("custom_refresh_token_claim");
Assert.assertNotNull(atCustomAtClaim);
Assert.assertEquals(atCustomAtClaim, "value2");
Assert.assertNull(atCustomRtClaim);
final RefreshTokenClaimsSet refreshToken =
RefreshTokenClaimsSet.parse(response.getTokens().getRefreshToken().getValue(), getDataSealer());
- final String rtCustomAtClaim = refreshToken.getClaimsSet().getStringClaim("custom_access_token_claim");
- final String rtCustomRtClaim = refreshToken.getClaimsSet().getStringClaim("custom_refresh_token_claim");
+ final JWTClaimsSet rfClaimsSet = refreshToken.getClaimsSet();
+ assert rfClaimsSet != null;
+ final String rtCustomAtClaim = rfClaimsSet.getStringClaim("custom_access_token_claim");
+ final String rtCustomRtClaim = rfClaimsSet.getStringClaim("custom_refresh_token_claim");
Assert.assertNotNull(rtCustomRtClaim);
Assert.assertEquals(rtCustomRtClaim, "value3");
Assert.assertNull(rtCustomAtClaim);
@@ -609,9 +617,11 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
final AccessTokenClaimsSet token =
AccessTokenClaimsSet.parse(response.getTokens().getAccessToken().getValue(), getDataSealer());
- Assert.assertTrue(token.getScope().contains("openid"));
- Assert.assertTrue(token.getScope().contains("profile"));
- Assert.assertFalse(token.getScope().contains("email"));
+ final Scope scope = token.getScope();
+ assert scope != null;
+ Assert.assertTrue(scope.contains("openid"));
+ Assert.assertTrue(scope.contains("profile"));
+ Assert.assertFalse(scope.contains("email"));
}
@Test
@@ -647,8 +657,10 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
protected void validateConsentFromAccessToken(final OIDCTokenResponse response, final boolean value)
throws Exception {
final AccessTokenClaimsSet claims = unwrapAccessToken(response);
- Assert.assertTrue(claims.getClaimsSet().getClaims().containsKey(TokenClaimsSet.KEY_CONSENT_ENABLED));
- Assert.assertEquals(claims.getClaimsSet().getBooleanClaim(TokenClaimsSet.KEY_CONSENT_ENABLED).booleanValue(),
+ final JWTClaimsSet claimsSet = claims.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertTrue(claimsSet.getClaims().containsKey(TokenClaimsSet.KEY_CONSENT_ENABLED));
+ Assert.assertEquals(claimsSet.getBooleanClaim(TokenClaimsSet.KEY_CONSENT_ENABLED).booleanValue(),
value);
Assert.assertEquals(claims.isConsentEnabled(), value);
}
@@ -1005,10 +1017,14 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
final OIDCTokenResponse response = parseSuccessResponse(result, OIDCTokenResponse.class);
final AccessTokenClaimsSet claimsSet = unwrapAccessToken(response);
Assert.assertNotNull(claimsSet);
- final ClaimsSet dlClaimsSet = claimsSet.getUserinfoDeliveryClaims();
- Assert.assertNotNull(dlClaimsSet);
- Assert.assertEquals(dlClaimsSet.getClaim(claimName), claimValue);
- Assert.assertNull(claimsSet.getDeliveryClaims().getClaim(claimName));
+ assert claimsSet != null;
+ final ClaimsSet userInfoClaimsSet = claimsSet.getUserinfoDeliveryClaims();
+ Assert.assertNotNull(userInfoClaimsSet);
+ assert userInfoClaimsSet != null;
+ Assert.assertEquals(userInfoClaimsSet.getClaim(claimName), claimValue);
+ final ClaimsSet deliveryClaimsSet = claimsSet.getDeliveryClaims();
+ assert deliveryClaimsSet != null;
+ Assert.assertNull(deliveryClaimsSet.getClaim(claimName));
Assert.assertNull(claimsSet.getIDTokenDeliveryClaims());
}
@@ -1026,8 +1042,12 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
Assert.assertNotNull(claimsSet);
final ClaimsSet dlClaimsSet = claimsSet.getDeliveryClaims();
Assert.assertNotNull(dlClaimsSet);
+ assert dlClaimsSet != null;
Assert.assertEquals(dlClaimsSet.getClaim(claimName), claimValue);
- Assert.assertNull(claimsSet.getUserinfoDeliveryClaims().getClaim(claimName));
+ final ClaimsSet userInfoClaimsSet = claimsSet.getUserinfoDeliveryClaims();
+ Assert.assertNotNull(userInfoClaimsSet);
+ assert userInfoClaimsSet != null;
+ Assert.assertNull(userInfoClaimsSet.getClaim(claimName));
Assert.assertNull(claimsSet.getIDTokenDeliveryClaims());
}
@@ -1191,7 +1211,9 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
final OIDCTokenResponse response = parseSuccessResponse(result, OIDCTokenResponse.class);
final AccessToken accessToken = response.getTokens().getAccessToken();
Assert.assertNotNull(accessToken);
- Assert.assertTrue(unwrapAccessToken(response).getClaimsSet().getAudience().contains("https://rp.example.org"));
+ final JWTClaimsSet claimsSet = unwrapAccessToken(response).getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertTrue(claimsSet.getAudience().contains("https://rp.example.org"));
Assert.assertNotNull(response.getOIDCTokens().getIDToken());
Assert.assertNotNull(response.getOIDCTokens().getIDToken().getJWTClaimsSet().getClaim("at_hash"));
validateConsentFromAccessToken(response, false);
@@ -1274,13 +1296,16 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
};
}
- private AccessTokenClaimsSet unwrapAccessToken(final AccessTokenResponse tokenResponse) {
+ @Nonnull private AccessTokenClaimsSet unwrapAccessToken(final AccessTokenResponse tokenResponse) throws Exception {
final AccessToken accessToken = tokenResponse.getTokens().getAccessToken();
Assert.assertNotNull(accessToken);
try {
- return AccessTokenClaimsSet.parse(accessToken.getValue(), getDataSealer());
+ assert accessToken != null;
+ final String value = accessToken.getValue();
+ assert value != null;
+ return AccessTokenClaimsSet.parse(value, getDataSealer());
} catch (final java.text.ParseException | DataSealerException e) {
- return null;
+ throw e;
}
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/UserInfoTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/UserInfoTest.java
index 21b67e81..b23511fc 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/UserInfoTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/UserInfoTest.java
@@ -20,6 +20,8 @@ import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.List;
+import javax.annotation.Nonnull;
+
import org.opensaml.storage.RevocationCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -103,7 +105,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
public void testFailsUntrustedClient() throws URISyntaxException, NoSuchAlgorithmException, DataSealerException,
ComponentInitializationException {
final BearerAccessToken token = buildToken(idGenerator.generateIdentifier(), subject, new Scope());
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, OAuth2Error.ACCESS_DENIED_CODE);
}
@@ -112,7 +114,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
public void testSuccesUntrustedClient_policyCompliant_onlySubject() throws URISyntaxException, NoSuchAlgorithmException, DataSealerException,
ComponentInitializationException {
final BearerAccessToken token = buildToken("policyAcceptedClient1", subject, new Scope("openid"));
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -127,7 +129,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
public void testSuccesUntrustedClient_policyCompliant_profileEmailFilteredOut() throws URISyntaxException, NoSuchAlgorithmException, DataSealerException,
ComponentInitializationException {
final BearerAccessToken token = buildToken("policyAcceptedClient1", subject, new Scope("openid profile email"));
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -143,7 +145,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid"));
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -159,7 +161,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientId, subject, new Scope("profile"));
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, OAuth2Error.INVALID_SCOPE_CODE);
}
@@ -169,7 +171,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid profile"));
storeMetadata(storageService, clientId, "mockSecret", new Scope("profile"));
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, OAuth2Error.INVALID_SCOPE_CODE);
}
@@ -179,7 +181,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid profile"));
storeMetadata(storageService, clientId, "mockSecret", null);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, OAuth2Error.INVALID_SCOPE_CODE);
}
@@ -189,7 +191,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
ComponentInitializationException, IOException, com.nimbusds.oauth2.sdk.ParseException {
final BearerAccessToken token = buildLegacyToken(clientId, subject, new Scope("openid"));
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -206,7 +208,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
final BearerAccessToken token = buildJWTToken(clientId, subject , new Scope("openid"), null, signingKey.getPrivateKey(), "RS256");
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -224,7 +226,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
List.of("https://sp.example.org", "https://op.example.org"), signingKey.getPrivateKey(), "RS256");
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -242,7 +244,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
List.of("https://sp.example.org"), signingKey.getPrivateKey(), "RS256");
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, BearerTokenError.INVALID_TOKEN.getCode());
}
@@ -251,7 +253,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
public void testSuccessOnlySubjectSaml() throws URISyntaxException, NoSuchAlgorithmException, DataSealerException,
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientIdSaml, subject, new Scope("openid"));
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -266,7 +268,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
public void testSuccessEmailResolutionSaml() throws URISyntaxException, NoSuchAlgorithmException, DataSealerException,
ComponentInitializationException, IOException {
final BearerAccessToken token = buildToken(clientIdSaml, subject, new Scope("openid", "email"));
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertEquals(response.getUserInfo().getSubject().getValue(), subject);
@@ -285,7 +287,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid", "email", "profile"));
storeMetadata(storageService, clientId, "mockSecret", scope);
storeConsent(storageService, "jdoe", clientId, "mail");
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
final UserInfo userInfo = response.getUserInfo();
@@ -302,7 +304,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
final BearerAccessToken token = buildLegacyToken(clientId, subject, new Scope("openid", "email", "profile"));
storeMetadata(storageService, clientId, "mockSecret", scope);
storeConsent(storageService, "jdoe", clientId, "mail");
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
final UserInfo userInfo = response.getUserInfo();
@@ -320,7 +322,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
"mail");
storeMetadata(storageService, clientId, "mockSecret", scope);
storeConsent(storageService, "jdoe", clientId, "mail");
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
final UserInfo userInfo = response.getUserInfo();
@@ -339,7 +341,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
"not_mail");
storeMetadata(storageService, clientId, "mockSecret", scope);
storeConsent(storageService, "jdoe", clientId, "mail");
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
final UserInfo userInfo = response.getUserInfo();
@@ -357,7 +359,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
set.setClaim("nickname", "mockNickname");
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid", "profile"), set);
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
final UserInfo userInfo = response.getUserInfo();
@@ -375,7 +377,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
storeMetadata(storageService, clientId, "mockSecret", scope, null,
ClientAuthenticationMethod.CLIENT_SECRET_BASIC, JWSAlgorithm.RS256);
storeConsent(storageService, "jdoe", clientId, "mail");
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final UserInfoSuccessResponse response = parseSuccessResponse(result, UserInfoSuccessResponse.class);
Assert.assertNull(response.getUserInfo());
@@ -396,7 +398,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
revocationCache.revoke(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jti);
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid"), null, jti, rootId);
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, BearerTokenError.INVALID_TOKEN.getCode());
}
@@ -409,7 +411,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
revocationCache.revoke(RevocationCacheContexts.AUTHORIZATION_CODE, rootId);
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid"), null, jti, rootId);
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, BearerTokenError.INVALID_TOKEN.getCode());
}
@@ -421,7 +423,7 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
revocationCache.revoke(RevocationCacheContexts.AUTHORIZATION_CODE, jti);
final BearerAccessToken token = buildToken(clientId, subject, new Scope("openid"), null, jti, null);
storeMetadata(storageService, clientId, "mockSecret", scope);
- request.addHeader("Authorization", token.toAuthorizationHeader());
+ request.addHeader("Authorization", getTokenHeaderValue(token));
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertErrorCode(result, BearerTokenError.INVALID_TOKEN.getCode());
}
@@ -441,4 +443,9 @@ public class UserInfoTest extends AbstractOidcApiFlowTest {
};
}
+ @Nonnull private static String getTokenHeaderValue(final BearerAccessToken token) {
+ final String value = token.toAuthorizationHeader();
+ assert value != null;
+ return value;
+ }
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationRequestActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationRequestActionTest.java
index c8399e78..fa5f152f 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationRequestActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationRequestActionTest.java
@@ -38,6 +38,7 @@ public class AbstractOIDCAuthenticationRequestActionTest {
final RequestContext requestCtx = new RequestContextBuilder().buildRequestContext();
final ProfileRequestContext prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+ assert prc != null;
prc.setInboundMessageContext(null);
final MockOIDCRequestAction action = new MockOIDCRequestAction();
action.initialize();
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationResponseActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationResponseActionTest.java
index c53762e3..de19fa34 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationResponseActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCAuthenticationResponseActionTest.java
@@ -44,7 +44,8 @@ public class AbstractOIDCAuthenticationResponseActionTest {
requestCtx = new RequestContextBuilder().setInboundMessage(req).buildRequestContext();
final MessageContext msgCtx = new MessageContext();
final ProfileRequestContext prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- prc.getInboundMessageContext().addSubcontext(new OIDCMetadataContext());
+ assert prc != null;
+ prc.ensureInboundMessageContext().addSubcontext(new OIDCMetadataContext());
prc.setOutboundMessageContext(msgCtx);
action.initialize();
}
@@ -57,6 +58,7 @@ public class AbstractOIDCAuthenticationResponseActionTest {
@Test
public void testNoOutboundMessageContext() throws Exception {
final ProfileRequestContext prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+ assert prc != null;
prc.setOutboundMessageContext(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, EventIds.INVALID_MSG_CTX);
@@ -80,7 +82,8 @@ public class AbstractOIDCAuthenticationResponseActionTest {
@Test
public void testSuccess() throws Exception {
final ProfileRequestContext prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- prc.getOutboundMessageContext().addSubcontext(new OIDCAuthenticationResponseContext());
+ assert prc != null;
+ prc.ensureOutboundMessageContext().addSubcontext(new OIDCAuthenticationResponseContext());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCTokenResponseActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCTokenResponseActionTest.java
index c00e5fa4..f9aae414 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCTokenResponseActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AbstractOIDCTokenResponseActionTest.java
@@ -49,6 +49,7 @@ public class AbstractOIDCTokenResponseActionTest {
private ProfileRequestContext prc;
+ @SuppressWarnings("null")
@BeforeMethod
protected void setUp() throws Exception {
action = new MockOIDCTokenResponseAction();
@@ -61,7 +62,7 @@ public class AbstractOIDCTokenResponseActionTest {
requestCtx = new RequestContextBuilder().setInboundMessage(req).buildRequestContext();
final MessageContext msgCtx = new MessageContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- prc.getInboundMessageContext().addSubcontext(oIDCMetadataContext);
+ prc.ensureInboundMessageContext().addSubcontext(oIDCMetadataContext);
msgCtx.addSubcontext(oIDCAuthenticationResponseContext);
prc.setOutboundMessageContext(msgCtx);
action.initialize();
@@ -82,9 +83,10 @@ public class AbstractOIDCTokenResponseActionTest {
* Test that the action functions properly if there is no oidc response context.
*/
+ @SuppressWarnings("null")
@Test
public void testNoOidcResponseContext() throws Exception {
- prc.getOutboundMessageContext().removeSubcontext(oIDCAuthenticationResponseContext);
+ prc.ensureOutboundMessageContext().removeSubcontext(oIDCAuthenticationResponseContext);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, EventIds.INVALID_MSG_CTX);
}
@@ -93,9 +95,10 @@ public class AbstractOIDCTokenResponseActionTest {
* Test that the action functions properly if metadata context is missing.
*/
+ @SuppressWarnings("null")
@Test
public void testNoMetadataContext() throws Exception {
- prc.getInboundMessageContext().removeSubcontext(oIDCMetadataContext);
+ prc.ensureInboundMessageContext().removeSubcontext(oIDCMetadataContext);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAccessTokenHashToIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAccessTokenHashToIDTokenTest.java
index 2cf0039f..e83188dd 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAccessTokenHashToIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAccessTokenHashToIDTokenTest.java
@@ -30,6 +30,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddAccessTokenHashToIDToken} unit test. */
public class AddAccessTokenHashToIDTokenTest extends BaseOIDCResponseActionTest {
@@ -38,13 +39,14 @@ public class AddAccessTokenHashToIDTokenTest extends BaseOIDCResponseActionTest
SecurityParametersContext spCtx;
+ @SuppressWarnings("null")
private void init(String algo, Credential credential) throws ComponentInitializationException, URISyntaxException {
spCtx = new SecurityParametersContext();
final SignatureSigningParameters params = new SignatureSigningParameters();
spCtx.setSignatureSigningParameters(params);
params.setSigningCredential(credential);
params.setSignatureAlgorithm(algo);
- profileRequestCtx.getOutboundMessageContext().addSubcontext(spCtx);
+ profileRequestCtx.ensureOutboundMessageContext().addSubcontext(spCtx);
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
respCtx.setAccessToken("accesstoken", Duration.ofSeconds(100));
action = new AddAccessTokenHashToIDToken();
@@ -73,6 +75,7 @@ public class AddAccessTokenHashToIDTokenTest extends BaseOIDCResponseActionTest
* @throws ParseException
* @throws URISyntaxException
*/
+ @SuppressWarnings("null")
@Test
public void testNoAccessToken() throws ComponentInitializationException, ParseException, URISyntaxException {
init("RS256", credentialRSA);
@@ -93,7 +96,9 @@ public class AddAccessTokenHashToIDTokenTest extends BaseOIDCResponseActionTest
init("RS256", credentialRSA);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(respCtx.getIDToken().getStringClaim("at_hash"));
+ final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
+ Assert.assertNotNull(idToken.getStringClaim("at_hash"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAcrToIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAcrToIDTokenTest.java
index 27cc50eb..bca1d900 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAcrToIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAcrToIDTokenTest.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.openid.connect.sdk.claims.ACR;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddAcrToIDToken} unit test. */
public class AddAcrToIDTokenTest extends BaseOIDCResponseActionTest {
@@ -62,7 +63,9 @@ public class AddAcrToIDTokenTest extends BaseOIDCResponseActionTest {
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNull(respCtx.getIDToken().getACR());
+ final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
+ Assert.assertNull(idToken.getACR());
}
@@ -79,7 +82,9 @@ public class AddAcrToIDTokenTest extends BaseOIDCResponseActionTest {
respCtx.setAcr("acrValue");
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(respCtx.getIDToken().getACR(), new ACR("acrValue"));
+ final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
+ Assert.assertEquals(idToken.getACR(), new ACR("acrValue"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAttributesToClaimsSetTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAttributesToClaimsSetTest.java
index dd1fb420..a21a9fb1 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAttributesToClaimsSetTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAttributesToClaimsSetTest.java
@@ -34,6 +34,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
import net.shibboleth.idp.attribute.AttributesMapContainer;
import net.shibboleth.idp.attribute.IdPAttribute;
@@ -52,6 +53,7 @@ import net.shibboleth.oidc.attribute.transcoding.OIDCAttributeTranscoder;
import net.shibboleth.oidc.attribute.transcoding.impl.OIDCStringAttributeTranscoder;
import net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfiguration;
import net.shibboleth.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.testing.MockApplicationContext;
import net.shibboleth.shared.testing.MockReloadableService;
@@ -66,7 +68,7 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
@BeforeMethod
public void setup() throws ComponentInitializationException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setAlwaysIncludedAttributes(
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setAlwaysIncludedAttributes(
Set.of("test1", "test3", "test4"));
registry = new AttributeTranscoderRegistryImpl();
@@ -99,7 +101,7 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
new BasicNamingFunction<>(transcoder.getEncodedType(),
new AbstractOIDCAttributeTranscoder.NamingFunction())));
- registry.setTranscoderRegistry(List.of(
+ registry.setTranscoderRegistry(CollectionSupport.listOf(
new TranscodingRule(rule1),
new TranscodingRule(rule2),
new TranscodingRule(rule3),
@@ -161,7 +163,8 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
attributes.add(attribute4);
attributes.add(attribute5);
attributeCtx.setIdPAttributes(attributes);
- prc.getSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
+ assert prc != null;
+ prc.ensureSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
}
/**
@@ -201,11 +204,13 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
setAttributeContext();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getClaim("test1").equals("value1 value2"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test2"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test3claim").equals("value3"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test4claim").equals("value4"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test5claim"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test1").equals("value1 value2"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test2"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test3claim").equals("value3"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test4claim").equals("value4"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test5claim"));
}
/**
@@ -224,11 +229,13 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
setAttributeContext();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getClaim("test1").equals("value1 value2"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test2").equals("value"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test3claim").equals("value3"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test4claim").equals("value4"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test5claim"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test1").equals("value1 value2"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test2").equals("value"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test3claim").equals("value3"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test4claim").equals("value4"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test5claim"));
}
/**
@@ -247,11 +254,13 @@ public class AddAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
ctx.getConsentedAttributes().add("test4");
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getClaim("test1").equals("value1 value2"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test2"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test3claim"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("test4claim").equals("value4"));
- Assert.assertNull(respCtx.getIDToken().getClaim("test5claim"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test1").equals("value1 value2"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test2"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test3claim"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("test4claim").equals("value4"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("test5claim"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthTimeToIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthTimeToIDTokenTest.java
index 785eecf2..48f21005 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthTimeToIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthTimeToIDTokenTest.java
@@ -26,6 +26,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddAuthTimeToIDToken} unit test. */
public class AddAuthTimeToIDTokenTest extends BaseOIDCResponseActionTest {
@@ -61,7 +62,9 @@ public class AddAuthTimeToIDTokenTest extends BaseOIDCResponseActionTest {
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNull(respCtx.getIDToken().getAuthenticationTime());
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertNull(idTokenClaimsSet.getAuthenticationTime());
}
/**
@@ -77,7 +80,9 @@ public class AddAuthTimeToIDTokenTest extends BaseOIDCResponseActionTest {
respCtx.setAuthTime(now);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(respCtx.getIDToken().getAuthenticationTime(), Date.from(now));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertEquals(idTokenClaimsSet.getAuthenticationTime(), Date.from(now));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthorizationCodeHashToIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthorizationCodeHashToIDTokenTest.java
index 8056b041..f1dc4be8 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthorizationCodeHashToIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddAuthorizationCodeHashToIDTokenTest.java
@@ -31,6 +31,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddAuthorizationCodeHashToIDToken} unit test. */
public class AddAuthorizationCodeHashToIDTokenTest extends BaseOIDCResponseActionTest {
@@ -39,6 +40,7 @@ public class AddAuthorizationCodeHashToIDTokenTest extends BaseOIDCResponseActio
SecurityParametersContext spCtx;
+ @SuppressWarnings("null")
private void init(final String algo, final Credential credential)
throws ComponentInitializationException, URISyntaxException {
spCtx = new SecurityParametersContext();
@@ -46,7 +48,7 @@ public class AddAuthorizationCodeHashToIDTokenTest extends BaseOIDCResponseActio
spCtx.setSignatureSigningParameters(params);
params.setSigningCredential(credential);
params.setSignatureAlgorithm(algo);
- profileRequestCtx.getOutboundMessageContext().addSubcontext(spCtx);
+ profileRequestCtx.ensureOutboundMessageContext().addSubcontext(spCtx);
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
respCtx.setAuthorizationCode("authcode");
final DefaultComputeAuthorizationCodeHashFunction hashFunction =
@@ -100,7 +102,9 @@ public class AddAuthorizationCodeHashToIDTokenTest extends BaseOIDCResponseActio
init("RS256", credentialRSA);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(respCtx.getIDToken().getStringClaim("c_hash"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertNotNull(idTokenClaimsSet.getStringClaim("c_hash"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddGrantTypeToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddGrantTypeToClientMetadataTest.java
index f221e8ea..37d98726 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddGrantTypeToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddGrantTypeToClientMetadataTest.java
@@ -14,12 +14,12 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.webflow.execution.Event;
@@ -33,6 +33,7 @@ import com.nimbusds.oauth2.sdk.GrantType;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
/**
@@ -72,13 +73,13 @@ public class AddGrantTypeToClientMetadataTest extends BaseOIDCClientMetadataPopu
@Test
public void testNotSupported() throws ComponentInitializationException {
- testGrantTypes(Arrays.asList(new GrantType[] { GrantType.CLIENT_CREDENTIALS }), EventIds.INVALID_MESSAGE,
+ testGrantTypes(CollectionSupport.arrayAsList(new GrantType[] { GrantType.CLIENT_CREDENTIALS }), EventIds.INVALID_MESSAGE,
GrantType.CLIENT_CREDENTIALS);
}
@Test
public void testOneNotSupported() throws ComponentInitializationException {
- testGrantTypes(Arrays.asList(new GrantType[] { GrantType.CLIENT_CREDENTIALS }), null,
+ testGrantTypes(CollectionSupport.arrayAsList(new GrantType[] { GrantType.CLIENT_CREDENTIALS }), null,
GrantType.AUTHORIZATION_CODE, GrantType.CLIENT_CREDENTIALS);
}
@@ -108,10 +109,10 @@ public class AddGrantTypeToClientMetadataTest extends BaseOIDCClientMetadataPopu
}
protected void testGrantTypes(final GrantType... grantTypes) throws ComponentInitializationException {
- testGrantTypes(Collections.emptyList(), null, grantTypes);
+ testGrantTypes(CollectionSupport.emptyList(), null, grantTypes);
}
- protected void testGrantTypes(final List<GrantType> ignoredTypes, final String expectedEventId,
+ protected void testGrantTypes(@Nonnull final List<GrantType> ignoredTypes, final String expectedEventId,
final GrantType... grantTypes) throws ComponentInitializationException {
final OIDCClientMetadata request = new OIDCClientMetadata();
request.setGrantTypes(new HashSet<GrantType>(List.of(grantTypes)));
@@ -125,7 +126,7 @@ public class AddGrantTypeToClientMetadataTest extends BaseOIDCClientMetadataPopu
Assert.assertNull(event);
final Set<GrantType> resultTypes = result.getGrantTypes();
Assert.assertNotNull(resultTypes);
- final int length = (ignoredTypes == null) ? grantTypes.length : grantTypes.length - ignoredTypes.size();
+ final int length = grantTypes.length - ignoredTypes.size();
Assert.assertEquals(resultTypes.size(), length);
for (final GrantType grantType : grantTypes) {
if (ignoredTypes.contains(grantType)) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddIDTokenShellTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddIDTokenShellTest.java
index c07aec8f..b53c738d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddIDTokenShellTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddIDTokenShellTest.java
@@ -23,6 +23,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.id.Audience;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
import com.nimbusds.openid.connect.sdk.claims.SessionID;
/** {@link AddIDTokenShell} unit test. */
@@ -48,9 +49,11 @@ public class AddIDTokenShellTest extends BaseOIDCResponseActionTest {
public void testSuccess() throws ComponentInitializationException {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getAudience().contains(new Audience(request.getClientID())));
- Assert.assertEquals(respCtx.getIDToken().getSubject().getValue(), subject);
- Assert.assertNull(respCtx.getIDToken().getSessionID());
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getAudience().contains(new Audience(request.getClientID())));
+ Assert.assertEquals(idTokenClaimsSet.getSubject().getValue(), subject);
+ Assert.assertNull(idTokenClaimsSet.getSessionID());
}
/**
@@ -63,9 +66,11 @@ public class AddIDTokenShellTest extends BaseOIDCResponseActionTest {
respCtx.setSessionId("mockSid");
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getAudience().contains(new Audience(request.getClientID())));
- Assert.assertEquals(respCtx.getIDToken().getSubject().getValue(), subject);
- Assert.assertEquals(respCtx.getIDToken().getSessionID(), new SessionID("mockSid"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getAudience().contains(new Audience(request.getClientID())));
+ Assert.assertEquals(idTokenClaimsSet.getSubject().getValue(), subject);
+ Assert.assertEquals(idTokenClaimsSet.getSessionID(), new SessionID("mockSid"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddJwksToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddJwksToClientMetadataTest.java
index 0e43c196..7190e86e 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddJwksToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddJwksToClientMetadataTest.java
@@ -20,6 +20,8 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
+import javax.annotation.Nonnull;
+
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -62,7 +64,7 @@ public class AddJwksToClientMetadataTest extends BaseOIDCClientMetadataPopulatio
action.initialize();
}
- protected HttpClient buildMockHttpClient(String contents) throws ClientProtocolException, IOException {
+ @Nonnull protected HttpClient buildMockHttpClient(String contents) throws ClientProtocolException, IOException {
ClassicHttpResponse mockResponse = Mockito.mock(ClassicHttpResponse.class);
Mockito.when(mockResponse.getEntity()).thenReturn(new StringEntity(contents));
HttpClient mockClient = Mockito.mock(HttpClient.class);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddNonceToIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddNonceToIDTokenTest.java
index 48356757..6f6ffa40 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddNonceToIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddNonceToIDTokenTest.java
@@ -25,6 +25,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddNonceToIDToken} unit test. */
public class AddNonceToIDTokenTest extends BaseOIDCResponseActionTest {
@@ -61,7 +62,9 @@ public class AddNonceToIDTokenTest extends BaseOIDCResponseActionTest {
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(respCtx.getIDToken().getNonce(), request.getNonce());
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertEquals(idTokenClaimsSet.getNonce(), request.getNonce());
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRemainingClaimsToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRemainingClaimsToClientMetadataTest.java
index f95439bb..eefad6da 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRemainingClaimsToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRemainingClaimsToClientMetadataTest.java
@@ -16,6 +16,8 @@ package net.shibboleth.idp.plugin.oidc.op.profile.impl;
import java.util.Map;
+import javax.annotation.Nonnull;
+
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -45,12 +47,12 @@ public class AddRemainingClaimsToClientMetadataTest extends BaseOIDCClientMetada
return new AddRemainingClaimsToClientMetadata();
}
- protected void setUpContext(final OIDCClientMetadata input, final OIDCClientMetadata output,
+ protected void setUpContext(@Nonnull final OIDCClientMetadata input, @Nonnull final OIDCClientMetadata output,
final Map<String, MetadataPolicy> metadataPolicy)
throws ComponentInitializationException {
super.setUpContext(input, output);
- final OIDCClientRegistrationMetadataPolicyContext policyCtx = profileRequestCtx.getInboundMessageContext()
- .getSubcontext(OIDCClientRegistrationMetadataPolicyContext.class);;
+ final OIDCClientRegistrationMetadataPolicyContext policyCtx = profileRequestCtx.ensureInboundMessageContext()
+ .ensureSubcontext(OIDCClientRegistrationMetadataPolicyContext.class);;
policyCtx.setMetadataPolicy(metadataPolicy);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRequestObjectSecurityConfigurationToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRequestObjectSecurityConfigurationToClientMetadataTest.java
index 1088fb13..d16212e4 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRequestObjectSecurityConfigurationToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddRequestObjectSecurityConfigurationToClientMetadataTest.java
@@ -17,6 +17,8 @@ package net.shibboleth.idp.plugin.oidc.op.profile.impl;
import java.util.Arrays;
import java.util.List;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.action.EventIds;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
@@ -51,7 +53,7 @@ public class AddRequestObjectSecurityConfigurationToClientMetadataTest extends B
return new AddRequestObjectSecurityConfigurationToClientMetadata();
}
- protected void setUpContext(final OIDCClientMetadata input, final OIDCClientMetadata output,
+ protected void setUpContext(@Nonnull final OIDCClientMetadata input, @Nonnull final OIDCClientMetadata output,
final List<String> signingAlgs, final List<String> encryptionAlgs, final List<String> encryptionEncs) throws ComponentInitializationException {
super.setUpContext(input, output);
AddSecurityConfigurationToClientMetadataTest.initializeRpCtx(profileRequestCtx, signingAlgs, encryptionAlgs, encryptionEncs);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddResponseTypesToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddResponseTypesToClientMetadataTest.java
index 56c55fd5..001cfbf5 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddResponseTypesToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddResponseTypesToClientMetadataTest.java
@@ -23,6 +23,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.webflow.execution.Event;
@@ -36,6 +38,7 @@ import com.nimbusds.openid.connect.sdk.OIDCResponseTypeValue;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
/**
@@ -84,14 +87,14 @@ public class AddResponseTypesToClientMetadataTest extends BaseOIDCClientMetadata
@Test
public void testNotSupported() throws ComponentInitializationException {
- testResponseTypes(Arrays.asList(new ResponseType[] { new ResponseType(OIDCResponseTypeValue.NONE) }),
+ testResponseTypes(CollectionSupport.arrayAsList(new ResponseType[] { new ResponseType(OIDCResponseTypeValue.NONE) }),
EventIds.INVALID_MESSAGE,
new ResponseType(OIDCResponseTypeValue.NONE));
}
@Test
public void testOneNotSupported() throws ComponentInitializationException {
- testResponseTypes(Arrays.asList(new ResponseType[] { new ResponseType(OIDCResponseTypeValue.NONE) }), null,
+ testResponseTypes(CollectionSupport.arrayAsList(new ResponseType[] { new ResponseType(OIDCResponseTypeValue.NONE) }), null,
new ResponseType(OIDCResponseTypeValue.ID_TOKEN), new ResponseType(OIDCResponseTypeValue.NONE));
}
@@ -126,7 +129,7 @@ public class AddResponseTypesToClientMetadataTest extends BaseOIDCClientMetadata
testResponseTypes(new ArrayList<ResponseType>(), null, responseTypes);
}
- protected void testResponseTypes(List<ResponseType> ignoredTypes, String expectedEventId,
+ protected void testResponseTypes(@Nonnull List<ResponseType> ignoredTypes, String expectedEventId,
ResponseType... responseTypes)
throws ComponentInitializationException {
OIDCClientMetadata request = new OIDCClientMetadata();
@@ -141,7 +144,7 @@ public class AddResponseTypesToClientMetadataTest extends BaseOIDCClientMetadata
Assert.assertNull(event);
Set<ResponseType> resultTypes = result.getResponseTypes();
Assert.assertNotNull(resultTypes);
- int length = (ignoredTypes == null) ? responseTypes.length : responseTypes.length - ignoredTypes.size();
+ int length = responseTypes.length - ignoredTypes.size();
Assert.assertEquals(resultTypes.size(), length);
for (ResponseType responseType : responseTypes) {
if (ignoredTypes.contains(responseType)) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
index 33644d5a..bee2d981 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
@@ -23,7 +23,6 @@ import com.nimbusds.openid.connect.sdk.OIDCScopeValue;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
/**
* Unit test for {@link AddScopeToClientMetadata}.
@@ -43,12 +42,6 @@ public class AddScopeToClientMetadataTest extends BaseOIDCClientMetadataPopulati
return new AddScopeToClientMetadata();
}
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullDefault() {
- action = new AddScopeToClientMetadata();
- action.setDefaultScope(null);
- }
-
@Test
public void testNullScope() throws ComponentInitializationException {
OIDCClientMetadata input = new OIDCClientMetadata();
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddSecurityConfigurationToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddSecurityConfigurationToClientMetadataTest.java
index 85e5af77..45abca53 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddSecurityConfigurationToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddSecurityConfigurationToClientMetadataTest.java
@@ -17,6 +17,8 @@ package net.shibboleth.idp.plugin.oidc.op.profile.impl;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nonnull;
+
import org.mockito.Mockito;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -71,10 +73,11 @@ public class AddSecurityConfigurationToClientMetadataTest extends BaseOIDCClient
Mockito.when(encryptionConfig.getKeyTransportEncryptionAlgorithms()).thenReturn(encyrptionAlgs);
Mockito.when(secConfig.getJwtEncryptionConfiguration()).thenReturn(encryptionConfig);
Mockito.when(profileConfig.getSecurityConfiguration(profileRequestCtx)).thenReturn(secConfig);
+ assert rpCtx != null;
rpCtx.setProfileConfig(profileConfig);
}
- protected void setUpContext(final OIDCClientMetadata input, final OIDCClientMetadata output,
+ protected void setUpContext(@Nonnull final OIDCClientMetadata input, @Nonnull final OIDCClientMetadata output,
final List<String> signingAlgs, final List<String> encryptionAlgs, final List<String> encryptionEncs)
throws ComponentInitializationException {
super.setUpContext(input, output);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddTokenDeliveryAttributesToClaimsSetTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddTokenDeliveryAttributesToClaimsSetTest.java
index c8454c24..37fe907a 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddTokenDeliveryAttributesToClaimsSetTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddTokenDeliveryAttributesToClaimsSetTest.java
@@ -27,6 +27,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
/** {@link AddTokenDeliveryAttributesToClaimsSet} unit test. */
public class AddTokenDeliveryAttributesToClaimsSetTest extends BaseOIDCResponseActionTest {
@@ -68,6 +69,7 @@ public class AddTokenDeliveryAttributesToClaimsSetTest extends BaseOIDCResponseA
@Test
public void testNoTokenDeliveryAttributes() throws ComponentInitializationException, ParseException {
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
+ assert tokenClaimsCtx != null;
respCtx.removeSubcontext(tokenClaimsCtx);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
@@ -100,9 +102,11 @@ public class AddTokenDeliveryAttributesToClaimsSetTest extends BaseOIDCResponseA
setIdTokenToResponseContext("iss", "sub", "aud", Instant.now(), Instant.now());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getClaim("gen").equals("value1"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("idtoken").equals("value2"));
- Assert.assertNull(respCtx.getIDToken().getClaim("userinfo"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getClaim("gen").equals("value1"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("idtoken").equals("value2"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("userinfo"));
}
/**
@@ -120,9 +124,11 @@ public class AddTokenDeliveryAttributesToClaimsSetTest extends BaseOIDCResponseA
action.initialize();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getIDToken().getClaim("gen").equals("value1"));
- Assert.assertTrue(respCtx.getIDToken().getClaim("userinfo").equals("value3"));
- Assert.assertNull(respCtx.getIDToken().getClaim("idtoken"));
+ final IDTokenClaimsSet idTokenClaimsSet = respCtx.getIDToken();
+ assert idTokenClaimsSet != null;
+ Assert.assertTrue(idTokenClaimsSet.getClaim("gen").equals("value1"));
+ Assert.assertTrue(idTokenClaimsSet.getClaim("userinfo").equals("value3"));
+ Assert.assertNull(idTokenClaimsSet.getClaim("idtoken"));
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCClientMetadataPopulationTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCClientMetadataPopulationTest.java
index 5afc3346..89e327f7 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCClientMetadataPopulationTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCClientMetadataPopulationTest.java
@@ -14,6 +14,8 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
+import javax.annotation.Nonnull;
+
import org.mockito.Mockito;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.context.navigate.ContextDataLookupFunction;
@@ -31,7 +33,6 @@ import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileR
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.idp.profile.testing.RequestContextBuilder;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
/**
* Base class for testing actions extending {@link AbstractOIDCClientMetadataPopulationAction}.
@@ -43,7 +44,7 @@ public abstract class BaseOIDCClientMetadataPopulationTest {
protected RequestContext requestCtx;
protected ProfileRequestContext profileRequestCtx;
- protected void setUpContext(final OIDCClientMetadata input, final OIDCClientMetadata output)
+ protected void setUpContext(@Nonnull final OIDCClientMetadata input, @Nonnull final OIDCClientMetadata output)
throws ComponentInitializationException {
final OIDCClientRegistrationRequest request = new OIDCClientRegistrationRequest(null, input, null);
requestCtx = new RequestContextBuilder().setInboundMessage(request).buildRequestContext();
@@ -51,23 +52,11 @@ public abstract class BaseOIDCClientMetadataPopulationTest {
profileRequestCtx.setOutboundMessageContext(new MessageContext());
final OIDCClientRegistrationResponseContext responseCtx = new OIDCClientRegistrationResponseContext();
final OIDCClientRegistrationMetadataPolicyContext policyCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(
OIDCClientRegistrationMetadataPolicyContext.class);
responseCtx.setClientMetadata(output);
policyCtx.setPolicyEnforcedMetadata(input);
- profileRequestCtx.getOutboundMessageContext().addSubcontext(responseCtx);
- }
-
- @Test(expectedExceptions = ConstraintViolationException.class)
- protected void testNullInputStrategy() {
- action = constructAction();
- action.setOidcInputMetadataLookupStrategy(null);
- }
-
- @Test(expectedExceptions = ConstraintViolationException.class)
- protected void testNullOutputStrategy() {
- action = constructAction();
- action.setOidcOutputMetadataLookupStrategy(null);
+ profileRequestCtx.ensureOutboundMessageContext().addSubcontext(responseCtx);
}
@Test
@@ -86,6 +75,7 @@ public abstract class BaseOIDCClientMetadataPopulationTest {
ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_MSG_CTX);
}
+ @Nonnull
protected ContextDataLookupFunction<ProfileRequestContext,OIDCClientMetadata> initializeNullLookup()
throws ComponentInitializationException {
setUpContext(new OIDCClientMetadata(), new OIDCClientMetadata());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
index 6885b99e..0d985269 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
@@ -143,6 +143,7 @@ public abstract class BaseOIDCResponseActionTest extends OpenSAMLInitBaseTestCas
*
* @throws Exception
*/
+ @SuppressWarnings("null")
@BeforeMethod
protected void setUp() throws Exception {
request = AuthenticationRequest.parse(
@@ -152,8 +153,8 @@ public abstract class BaseOIDCResponseActionTest extends OpenSAMLInitBaseTestCas
profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
profileRequestCtx.setOutboundMessageContext(msgCtx);
respCtx = new OIDCAuthenticationResponseContext();
- profileRequestCtx.getOutboundMessageContext().addSubcontext(respCtx);
- metadataCtx = (OIDCMetadataContext) profileRequestCtx.getInboundMessageContext()
+ profileRequestCtx.ensureOutboundMessageContext().addSubcontext(respCtx);
+ metadataCtx = (OIDCMetadataContext) profileRequestCtx.ensureInboundMessageContext()
.addSubcontext(new OIDCMetadataContext());
final OIDCClientInformation information =
new OIDCClientInformation(new ClientID(clientId), new Date(), new OIDCClientMetadata(), new Secret());
@@ -165,15 +166,15 @@ public abstract class BaseOIDCResponseActionTest extends OpenSAMLInitBaseTestCas
}
protected void setAuthenticationRequest(final AuthenticationRequest req) {
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
}
protected void setTokenRequest(final TokenRequest req) {
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
}
protected void setUserInfoRequest(final UserInfoRequest req) {
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
}
protected void setIdTokenToResponseContext(final String iss, final String sub, final String aud, final Instant exp, final Instant iat) {
@@ -186,8 +187,11 @@ public abstract class BaseOIDCResponseActionTest extends OpenSAMLInitBaseTestCas
protected void signIdTokenInResponseContext() throws ParseException, JOSEException {
SignedJWT jwt = null;
+ assert respCtx != null;
+ final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
jwt = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID("id").build(),
- respCtx.getIDToken().toJWTClaimsSet());
+ idToken.toJWTClaimsSet());
jwt.sign(new RSASSASigner(credentialRSA.getPrivateKey()));
respCtx.setProcessedToken(jwt);
}
@@ -199,19 +203,24 @@ public abstract class BaseOIDCResponseActionTest extends OpenSAMLInitBaseTestCas
protected void signUserInfoResponseInResponseContext() throws ParseException, JOSEException {
SignedJWT jwt = null;
+ assert respCtx != null;
+ final UserInfo userInfo = respCtx.getUserInfo();
+ assert userInfo != null;
jwt = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID("id").build(),
- respCtx.getUserInfo().toJWTClaimsSet());
+ userInfo.toJWTClaimsSet());
jwt.sign(new RSASSASigner(credentialRSA.getPrivateKey()));
respCtx.setProcessedToken(jwt);
}
- public DataSealer getDataSealer() throws ComponentInitializationException, NoSuchAlgorithmException {
+ @Nonnull public DataSealer getDataSealer() throws ComponentInitializationException, NoSuchAlgorithmException {
if (dataSealer == null) {
dataSealer = initializeDataSealer();
}
+ assert dataSealer != null;
return dataSealer;
}
+ @SuppressWarnings("null")
public static DataSealer initializeDataSealer() throws ComponentInitializationException, NoSuchAlgorithmException {
final BasicKeystoreKeyStrategy strategy = new BasicKeystoreKeyStrategy();
strategy.setKeystoreResource(ResourceHelper.of(new ClassPathResource("credentials/sealer.jks")));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildClientInformationTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildClientInformationTest.java
index 267c8dac..21603ff3 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildClientInformationTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildClientInformationTest.java
@@ -27,6 +27,7 @@ import org.testng.annotations.Test;
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod;
import com.nimbusds.oauth2.sdk.auth.Secret;
import com.nimbusds.oauth2.sdk.id.ClientID;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformationResponse;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
@@ -60,7 +61,8 @@ public class BuildClientInformationTest {
messageCtx = new MessageContext();
Assert.assertNull(messageCtx.getMessage());
profileRequestCtx.setOutboundMessageContext(messageCtx);
- registrationCtx = profileRequestCtx.getOutboundMessageContext().ensureSubcontext(OIDCClientRegistrationResponseContext.class);
+ registrationCtx = profileRequestCtx.ensureOutboundMessageContext()
+ .ensureSubcontext(OIDCClientRegistrationResponseContext.class);
clientId = "mockClientId";
clientSecret = "mockSecret";
metadata = new OIDCClientMetadata();
@@ -87,21 +89,27 @@ public class BuildClientInformationTest {
@Test
public void noClientIdInContext() {
registrationCtx.setClientId(null);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
+ assert profileRequestCtx != null;
ActionTestingSupport.assertEvent(profileRequestCtx, EventIds.INVALID_MSG_CTX);
}
@Test
public void noClientMetadataInContext() {
registrationCtx.setClientMetadata(null);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
+ assert profileRequestCtx != null;
ActionTestingSupport.assertEvent(profileRequestCtx, EventIds.INVALID_MSG_CTX);
}
@Test
public void noClientSecretInContextWhenRequired() {
registrationCtx.setClientSecret(null);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
+ assert profileRequestCtx != null;
ActionTestingSupport.assertEvent(profileRequestCtx, EventIds.INVALID_MSG_CTX);
}
@@ -109,12 +117,14 @@ public class BuildClientInformationTest {
public void noClientSecretInContextRequiredWithPrivateKeyJWT() {
registrationCtx.setClientSecret(null);
metadata.setTokenEndpointAuthMethod(ClientAuthenticationMethod.PRIVATE_KEY_JWT);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse(false);
}
@Test
public void noTokenEndpointAuthMethodCreatesSecret() {
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse();
}
@@ -122,6 +132,7 @@ public class BuildClientInformationTest {
@Test
public void basicTokenEndpointAuthMethodCreatesSecret() {
metadata.setTokenEndpointAuthMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse();
}
@@ -129,6 +140,7 @@ public class BuildClientInformationTest {
@Test
public void postTokenEndpointAuthMethodCreatesSecret() {
metadata.setTokenEndpointAuthMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse();
}
@@ -136,6 +148,7 @@ public class BuildClientInformationTest {
@Test
public void jwtSecretTokenEndpointAuthMethodCreatesSecret() {
metadata.setTokenEndpointAuthMethod(ClientAuthenticationMethod.CLIENT_SECRET_JWT);
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse();
}
@@ -143,6 +156,7 @@ public class BuildClientInformationTest {
@Test
public void noTokenEndpointAuthMethodCreatesSecret_expirationTimeIgnored() {
registrationCtx.setClientSecretExpiresAt(Instant.now().plusSeconds(60));
+ assert profileRequestCtx != null;
action.execute(profileRequestCtx);
assertSuccessfulResponse();
}
@@ -152,10 +166,14 @@ public class BuildClientInformationTest {
}
protected void assertSuccessfulResponse(boolean secret) {
+ assert profileRequestCtx != null;
ActionTestingSupport.assertProceedEvent(profileRequestCtx);
final OIDCClientInformationResponse response = (OIDCClientInformationResponse) messageCtx.getMessage();
Assert.assertNotNull(response);
- Assert.assertEquals(response.getOIDCClientInformation().getID(), new ClientID(clientId));
+ assert response != null;
+ final OIDCClientInformation clientInformation = response.getOIDCClientInformation();
+ assert clientInformation != null;
+ Assert.assertEquals(clientInformation.getID(), new ClientID(clientId));
if (secret) {
assertSecret(response);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildJSONErrorResponseFromEventTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildJSONErrorResponseFromEventTest.java
index 101ea6a6..2dfd8cfe 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildJSONErrorResponseFromEventTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BuildJSONErrorResponseFromEventTest.java
@@ -14,11 +14,12 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
+import javax.annotation.Nonnull;
+
import org.mockito.Mockito;
import org.opensaml.profile.context.EventContext;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -32,6 +33,7 @@ import com.nimbusds.oauth2.sdk.ErrorObject;
import net.shibboleth.idp.plugin.oidc.op.messaging.JSONErrorResponse;
import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
/**
@@ -44,7 +46,7 @@ public class BuildJSONErrorResponseFromEventTest {
String eventId = "mockEventId";
- protected BuildJSONErrorResponseFromEvent initializeAction(Map<String, ErrorObject> mappedErrors, String eventId)
+ protected BuildJSONErrorResponseFromEvent initializeAction(@Nonnull Map<String, ErrorObject> mappedErrors, String eventId)
throws ComponentInitializationException {
BuildJSONErrorResponseFromEvent action = new BuildJSONErrorResponseFromEvent();
if (eventId != null) {
@@ -84,6 +86,7 @@ public class BuildJSONErrorResponseFromEventTest {
@Test
public void doPreExecute_shouldReturnTrueWithOutboundMessageContext() throws ComponentInitializationException {
BuildJSONErrorResponseFromEvent action = initializeAction();
+ assert profileRequestCtx != null;
Assert.assertTrue(action.doPreExecute(profileRequestCtx));
}
@@ -91,17 +94,18 @@ public class BuildJSONErrorResponseFromEventTest {
public void execute_shouldNotSetMessageWhenNoEventContext() throws ComponentInitializationException {
BuildJSONErrorResponseFromEvent action = initializeAction();
action.execute(requestCtx);
- Assert.assertNull(profileRequestCtx.getOutboundMessageContext().getMessage());
+ Assert.assertNull(profileRequestCtx.ensureOutboundMessageContext().getMessage());
}
@Test
public void execute_shouldSetMessageWhenEventContext() throws ComponentInitializationException {
BuildJSONErrorResponseFromEvent action = initializeAction(eventId);
action.execute(requestCtx);
- Object rawMessage = profileRequestCtx.getOutboundMessageContext().getMessage();
+ Object rawMessage = profileRequestCtx.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(rawMessage);
Assert.assertTrue(rawMessage instanceof JSONErrorResponse);
JSONErrorResponse response = (JSONErrorResponse) rawMessage;
+ assert response != null;
ErrorObject error = response.getErrorObject();
Assert.assertEquals(error.getCode(), AbstractBuildErrorResponseFromEvent.DEFAULT_ERROR_CODE);
Assert.assertEquals(error.getDescription(), eventId);
@@ -113,13 +117,15 @@ public class BuildJSONErrorResponseFromEventTest {
String errorCode = "mockCode";
String errorDescription = "mockDescription";
int errorStatusCode = 503;
- BuildJSONErrorResponseFromEvent action = initializeAction(Collections.singletonMap(eventId,
+ assert eventId != null;
+ BuildJSONErrorResponseFromEvent action = initializeAction(CollectionSupport.singletonMap(eventId,
new ErrorObject(errorCode, errorDescription, errorStatusCode)), eventId);
action.execute(requestCtx);
- Object rawMessage = profileRequestCtx.getOutboundMessageContext().getMessage();
+ Object rawMessage = profileRequestCtx.ensureOutboundMessageContext().getMessage();
Assert.assertNotNull(rawMessage);
Assert.assertTrue(rawMessage instanceof JSONErrorResponse);
JSONErrorResponse response = (JSONErrorResponse) rawMessage;
+ assert response != null;
ErrorObject error = response.getErrorObject();
Assert.assertEquals(error.getCode(), errorCode);
Assert.assertEquals(error.getDescription(), errorDescription);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
index 3bd45282..0a292b87 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
@@ -22,6 +22,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import javax.annotation.Nonnull;
+
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -156,14 +158,14 @@ public class CheckRedirectUrisTest extends BaseOIDCRegistrationRequestTest {
action.initialize();
}
- protected void initializeActionWithClient(final HttpClient httpClient) throws ComponentInitializationException {
+ protected void initializeActionWithClient(@Nonnull final HttpClient httpClient) throws ComponentInitializationException {
action = new CheckRedirectURIs();
action.setHttpClient(httpClient);
action.setObjectMapper(new ObjectMapper());
action.initialize();
}
- protected HttpClient buildMockHttpClient(final String contents) throws ClientProtocolException, IOException {
+ @Nonnull protected HttpClient buildMockHttpClient(final String contents) throws ClientProtocolException, IOException {
final HttpClient mockClient = Mockito.mock(HttpClient.class);
if (contents == null) {
Mockito.when(mockClient.executeOpen(Mockito.any(), (ClassicHttpRequest)Mockito.any(), Mockito.any())).thenThrow(new IOException("mock"));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundAuthenticationResponseMessageTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundAuthenticationResponseMessageTest.java
index 13e5fe58..a66eff51 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundAuthenticationResponseMessageTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundAuthenticationResponseMessageTest.java
@@ -62,7 +62,9 @@ public class FormOutboundAuthenticationResponseMessageTest extends BaseOIDCRespo
signIdTokenInResponseContext();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(((MessageContext) respCtx.getParent()).getMessage() instanceof AuthenticationSuccessResponse);
+ final MessageContext parentCtx = (MessageContext) respCtx.getParent();
+ assert parentCtx != null;
+ Assert.assertTrue(parentCtx.getMessage() instanceof AuthenticationSuccessResponse);
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundDiscoveryResponseTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundDiscoveryResponseTest.java
index cbc515b0..ea4932bf 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundDiscoveryResponseTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundDiscoveryResponseTest.java
@@ -18,6 +18,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nonnull;
+
import org.mockito.Mockito;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.core.io.ClassPathResource;
@@ -94,7 +96,8 @@ public class FormOutboundDiscoveryResponseTest {
return action;
}
- protected ProviderMetadataResolver initMetadataResolver() throws Exception {
+ @Nonnull protected ProviderMetadataResolver initMetadataResolver() throws Exception {
+ assert opfile != null;
final FilesystemProviderMetadataResolver resolver = new FilesystemProviderMetadataResolver(opfile);
resolver.setId("mockStaticResolver");
resolver.initialize();
@@ -106,9 +109,10 @@ public class FormOutboundDiscoveryResponseTest {
action.setMetadataResolver(initMetadataResolver());
action.initialize();
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
- Assert.assertTrue(profileRequestCtx.getOutboundMessageContext().getMessage() instanceof JSONSuccessResponse);
+ Assert.assertTrue(profileRequestCtx.ensureOutboundMessageContext().getMessage() instanceof JSONSuccessResponse);
final JSONSuccessResponse resp =
- (JSONSuccessResponse) profileRequestCtx.getOutboundMessageContext().getMessage();
+ (JSONSuccessResponse) profileRequestCtx.ensureOutboundMessageContext().getMessage();
+ assert resp != null;
Assert.assertTrue(resp.indicatesSuccess());
final OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(resp.toHTTPResponse().getContent());
assertFileContents(metadata);
@@ -123,7 +127,8 @@ public class FormOutboundDiscoveryResponseTest {
action.initialize();
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final JSONSuccessResponse resp =
- (JSONSuccessResponse) profileRequestCtx.getOutboundMessageContext().getMessage();
+ (JSONSuccessResponse) profileRequestCtx.ensureOutboundMessageContext().getMessage();
+ assert resp != null;
final OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(resp.toHTTPResponse().getContent());
assertFileContents(metadata);
Assert.assertNotNull(metadata.getCustomParameter(dynamicClaim));
@@ -156,8 +161,9 @@ public class FormOutboundDiscoveryResponseTest {
"eduPersonPrincipalName", "eduPersonAffiliation", "mail"));
}
- protected ProviderMetadataResolver initMetadataResolver(final Map<String, MetadataValueResolver> map)
+ @Nonnull protected ProviderMetadataResolver initMetadataResolver(final Map<String, MetadataValueResolver> map)
throws Exception {
+ assert opfile != null;
final DynamicFilesystemProviderMetadataResolver resolver =
new DynamicFilesystemProviderMetadataResolver(opfile);
resolver.setDynamicValueResolvers(map);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundTokenResponseMessageTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundTokenResponseMessageTest.java
index 8268f1aa..a6a119c5 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundTokenResponseMessageTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/FormOutboundTokenResponseMessageTest.java
@@ -46,6 +46,7 @@ public class FormOutboundTokenResponseMessageTest extends BaseOIDCResponseAction
* @throws ParseException
* @throws JOSEException
*/
+ @SuppressWarnings("null")
@BeforeMethod
public void init() throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
action = new FormOutboundTokenResponseMessage();
@@ -68,7 +69,9 @@ public class FormOutboundTokenResponseMessageTest extends BaseOIDCResponseAction
throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(((MessageContext) respCtx.getParent()).getMessage() instanceof TokenResponse);
+ final MessageContext parentCtx = (MessageContext) respCtx.getParent();
+ assert parentCtx != null;
+ Assert.assertTrue(parentCtx.getMessage() instanceof TokenResponse);
}
/**
@@ -85,7 +88,9 @@ public class FormOutboundTokenResponseMessageTest extends BaseOIDCResponseAction
respCtx.setProcessedToken(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(((MessageContext) respCtx.getParent()).getMessage() instanceof TokenResponse);
+ final MessageContext parentCtx = (MessageContext) respCtx.getParent();
+ assert parentCtx != null;
+ Assert.assertTrue(parentCtx.getMessage() instanceof TokenResponse);
}
/**
@@ -96,6 +101,7 @@ public class FormOutboundTokenResponseMessageTest extends BaseOIDCResponseAction
* @throws ParseException
* @throws JOSEException
*/
+ @SuppressWarnings("null")
@Test
public void testFailNoAccessToken()
throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeAuthenticationContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeAuthenticationContextTest.java
index a3178d09..0935a7bd 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeAuthenticationContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeAuthenticationContextTest.java
@@ -21,7 +21,7 @@ import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileR
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.idp.profile.testing.RequestContextBuilder;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
+import net.shibboleth.shared.logic.PredicateSupport;
import java.net.URI;
import java.time.Duration;
@@ -35,7 +35,6 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import com.google.common.base.Predicates;
import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.oauth2.sdk.ResponseType;
import com.nimbusds.oauth2.sdk.Scope;
@@ -65,7 +64,7 @@ public class InitializeAuthenticationContextTest {
final AuthenticationContext existingContext = new AuthenticationContext();
existingContext.setAuthenticationResult(new AuthenticationResult("flowId", new Subject()));
prc.addSubcontext(existingContext);
- prc.getOutboundMessageContext().addSubcontext(new OIDCAuthenticationResponseContext());
+ prc.ensureOutboundMessageContext().addSubcontext(new OIDCAuthenticationResponseContext());
}
/**
@@ -75,7 +74,7 @@ public class InitializeAuthenticationContextTest {
public void testOIDCAuthnRequestForcedWithHintedName() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext authnCtx = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext authnCtx = prc.ensureSubcontext(AuthenticationContext.class);
Assert.assertNotNull(authnCtx);
Assert.assertTrue(authnCtx.isForceAuthn());
Assert.assertFalse(authnCtx.isPassive());
@@ -91,10 +90,10 @@ public class InitializeAuthenticationContextTest {
final AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).state(new State())
.prompt(new Prompt(Prompt.Type.NONE)).maxAge(5).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext authnCtx = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext authnCtx = prc.ensureSubcontext(AuthenticationContext.class);
Assert.assertNotNull(authnCtx);
Assert.assertFalse(authnCtx.isForceAuthn());
Assert.assertTrue(authnCtx.isPassive());
@@ -105,10 +104,10 @@ public class InitializeAuthenticationContextTest {
public void testOIDCAuthnRequestWithoutPrompt() {
final AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext authnCtx = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext authnCtx = prc.ensureSubcontext(AuthenticationContext.class);
Assert.assertNotNull(authnCtx);
Assert.assertFalse(authnCtx.isForceAuthn());
Assert.assertFalse(authnCtx.isPassive());
@@ -118,36 +117,19 @@ public class InitializeAuthenticationContextTest {
@Test
public void testOIDCAuthnRequestWithoutPromptForceAuthnViaPredicate() throws ComponentInitializationException {
action = new InitializeAuthenticationContext();
- action.setForceAuthnPredicate(Predicates.alwaysTrue());
+ action.setForceAuthnPredicate(PredicateSupport.alwaysTrue());
action.initialize();
final AuthenticationRequest req = new AuthenticationRequest.Builder(new ResponseType("code"), new Scope("openid"),
new ClientID("000123"), URI.create("https://example.com/callback")).state(new State()).build();
- prc.getInboundMessageContext().setMessage(req);
+ prc.ensureInboundMessageContext().setMessage(req);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- final AuthenticationContext authnCtx = prc.getSubcontext(AuthenticationContext.class);
+ final AuthenticationContext authnCtx = prc.ensureSubcontext(AuthenticationContext.class);
Assert.assertNotNull(authnCtx);
+ assert authnCtx != null;
Assert.assertTrue(authnCtx.isForceAuthn());
Assert.assertFalse(authnCtx.isPassive());
Assert.assertNull(authnCtx.getMaxAge());
}
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testSetNullLoginHintLookupStrategy() throws Exception {
- action = new InitializeAuthenticationContext();
- action.setLoginHintLookupStrategy(null);
- }
-
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testSetNullPromptLookupStrategy() throws Exception {
- action = new InitializeAuthenticationContext();
- action.setPromptLookupStrategy(null);
- }
-
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testSetNullMaxAgeLookupStrategy() throws Exception {
- action = new InitializeAuthenticationContext();
- action.setMaxAgeLookupStrategy(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeOutboundAuthenticationResponseMessageContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeOutboundAuthenticationResponseMessageContextTest.java
index 54f60806..95ea827b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeOutboundAuthenticationResponseMessageContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeOutboundAuthenticationResponseMessageContextTest.java
@@ -25,13 +25,16 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date;
+import java.util.List;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.saml.common.messaging.context.SAMLMetadataContext;
import org.opensaml.saml.ext.saml2mdui.UIInfo;
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.opensaml.saml.saml2.metadata.Extensions;
+import org.opensaml.saml.saml2.metadata.RoleDescriptor;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
import org.testng.Assert;
@@ -67,7 +70,7 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
requestCtx = new RequestContextBuilder().setInboundMessage(request).buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
prc.ensureSubcontext(RelyingPartyContext.class);
- metadataCtx = (OIDCMetadataContext) prc.getInboundMessageContext().addSubcontext(new OIDCMetadataContext());
+ metadataCtx = (OIDCMetadataContext) prc.ensureInboundMessageContext().addSubcontext(new OIDCMetadataContext());
OIDCClientInformation information =
new OIDCClientInformation(new ClientID("clientId"), new Date(), new OIDCClientMetadata(), new Secret());
metadataCtx.setClientInformation(information);
@@ -78,24 +81,30 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
public void testSuccess() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
final SAMLMetadataContext samlContext = new SAMLMetadataContextLookupFunction().apply(prc);
- Assert.assertEquals(samlContext.getEntityDescriptor().getEntityID(), "clientId");
+ assert samlContext != null;
+ final EntityDescriptor entityDescriptor = samlContext.getEntityDescriptor();
+ assert entityDescriptor != null;
+ Assert.assertEquals(entityDescriptor.getEntityID(), "clientId");
}
@Test
public void testSuccessWithUnregistered() {
- prc.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ prc.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
final SAMLMetadataContext samlContext = new SAMLMetadataContextLookupFunction().apply(prc);
- Assert.assertEquals(samlContext.getEntityDescriptor().getEntityID(), "s6BhdRkqt3");
+ assert samlContext != null;
+ final EntityDescriptor entityDescriptor = samlContext.getEntityDescriptor();
+ assert entityDescriptor != null;
+ Assert.assertEquals(entityDescriptor.getEntityID(), "s6BhdRkqt3");
}
@Test
public void testNoClientIdWithUnregistered() throws ComponentInitializationException {
- prc.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ prc.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
action = new InitializeOutboundAuthenticationResponseMessageContext();
action.setUnregisteredClientIdLookupStrategy(prc -> null);
action.initialize();
@@ -106,34 +115,48 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
/** Test that action copes with non existent logo. */
@Test
public void nonExistentLogo() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata().setLogoURI(new URI("file:/nonexistent.png"));
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setLogoURI(new URI("file:/nonexistent.png"));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
}
/** Test that action copes with invalid logo. */
@Test
public void emptyLogo() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata()
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata()
.setLogoURI(new URI(getClass().getResource("/misc/invalidlogo.png").toString()));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
}
/** Test that action sets valid logo. */
@Test
public void successLogo() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata()
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata()
.setLogoURI(new URI(getClass().getResource("/misc/logo.png").toString()));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
SAMLMetadataContext ctx = new SAMLMetadataContextLookupFunction().apply(prc);
- final Extensions exts = ctx.getRoleDescriptor().getExtensions();
+ assert ctx != null;
+ final RoleDescriptor roleDescriptor = ctx.getRoleDescriptor();
+ assert roleDescriptor != null;
+ final Extensions exts = roleDescriptor.getExtensions();
if (exts != null) {
- for (final XMLObject object : exts.getOrderedChildren()) {
+ final List<XMLObject> objects = exts.getOrderedChildren();
+ assert objects != null;
+ for (final XMLObject object : objects) {
if (object instanceof UIInfo) {
Assert.assertTrue(((UIInfo) object).getLogos().size() == 1);
return;
@@ -146,14 +169,22 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
/** Test that action populates policy uri to privacy statement element . */
@Test
public void successPolicy() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata().setPolicyURI(new URI("http://policy.example.com"));
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setPolicyURI(new URI("http://policy.example.com"));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
SAMLMetadataContext ctx = new SAMLMetadataContextLookupFunction().apply(prc);
- final Extensions exts = ctx.getRoleDescriptor().getExtensions();
+ assert ctx != null;
+ final RoleDescriptor roleDescriptor = ctx.getRoleDescriptor();
+ assert roleDescriptor != null;
+ final Extensions exts = roleDescriptor.getExtensions();
if (exts != null) {
- for (final XMLObject object : exts.getOrderedChildren()) {
+ final List<XMLObject> objects = exts.getOrderedChildren();
+ assert objects != null;
+ for (final XMLObject object : objects) {
if (object instanceof UIInfo) {
Assert.assertTrue(((UIInfo) object).getPrivacyStatementURLs().size() == 1);
Assert.assertEquals("http://policy.example.com",
@@ -168,14 +199,22 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
/** Test that action populates tos to information element . */
@Test
public void successTos() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata().setTermsOfServiceURI(new URI("http://tos.example.com"));
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setTermsOfServiceURI(new URI("http://tos.example.com"));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
SAMLMetadataContext ctx = new SAMLMetadataContextLookupFunction().apply(prc);
- final Extensions exts = ctx.getRoleDescriptor().getExtensions();
+ assert ctx != null;
+ final RoleDescriptor roleDescriptor = ctx.getRoleDescriptor();
+ assert roleDescriptor != null;
+ final Extensions exts = roleDescriptor.getExtensions();
if (exts != null) {
- for (final XMLObject object : exts.getOrderedChildren()) {
+ final List<XMLObject> objects = exts.getOrderedChildren();
+ assert objects != null;
+ for (final XMLObject object : objects) {
if (object instanceof UIInfo) {
Assert.assertTrue(((UIInfo) object).getInformationURLs().size() == 1);
Assert.assertEquals("http://tos.example.com",
@@ -190,30 +229,44 @@ public class InitializeOutboundAuthenticationResponseMessageContextTest {
/** Test that action populates contacts element . */
@Test
public void successContacts() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata()
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata()
.setEmailContacts(Arrays.asList("contact1 at example.com", "contact2 at example.com"));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
SAMLMetadataContext ctx = new SAMLMetadataContextLookupFunction().apply(prc);
- Assert.assertEquals(2, ctx.getEntityDescriptor().getContactPersons().size());
+ assert ctx != null;
+ final EntityDescriptor entityDescriptor = ctx.getEntityDescriptor();
+ assert entityDescriptor != null;
+ Assert.assertEquals(2, entityDescriptor.getContactPersons().size());
Assert.assertEquals("mailto:contact1 at example.com",
- ctx.getEntityDescriptor().getContactPersons().get(0).getEmailAddresses().get(0).getURI());
+ entityDescriptor.getContactPersons().get(0).getEmailAddresses().get(0).getURI());
Assert.assertEquals("mailto:contact2 at example.com",
- ctx.getEntityDescriptor().getContactPersons().get(1).getEmailAddresses().get(0).getURI());
+ entityDescriptor.getContactPersons().get(1).getEmailAddresses().get(0).getURI());
}
/** Test that action populates service information element . */
@Test
public void successService() throws URISyntaxException {
- metadataCtx.getClientInformation().getOIDCMetadata().setName("test rp");
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setName("test rp");
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertNotNull(prc.getOutboundMessageContext());
+ Assert.assertNotNull(prc.ensureOutboundMessageContext());
SAMLMetadataContext ctx = new SAMLMetadataContextLookupFunction().apply(prc);
- final Extensions exts = ctx.getRoleDescriptor().getExtensions();
+ assert ctx != null;
+ final RoleDescriptor roleDescriptor = ctx.getRoleDescriptor();
+ assert roleDescriptor != null;
+ final Extensions exts = roleDescriptor.getExtensions();
if (exts != null) {
- for (final XMLObject object : exts.getOrderedChildren()) {
+ final List<XMLObject> objects = exts.getOrderedChildren();
+ assert objects != null;
+ for (final XMLObject object : objects) {
if (object instanceof UIInfo) {
Assert.assertTrue(((UIInfo) object).getDisplayNames().size() == 1);
Assert.assertEquals("test rp", ((UIInfo) object).getDisplayNames().get(0).getValue());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeRelyingPartyContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeRelyingPartyContextTest.java
index 370b486b..73697e7d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeRelyingPartyContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeRelyingPartyContextTest.java
@@ -41,7 +41,6 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
/** {@link InitializeRelyingPartyContext} unit test. */
public class InitializeRelyingPartyContextTest {
@@ -62,7 +61,7 @@ public class InitializeRelyingPartyContextTest {
new ClientID("000123"), URI.create("https://example.com/callback")).state(new State()).build();
requestCtx = new RequestContextBuilder().setInboundMessage(req).buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- metadataCtx = (OIDCMetadataContext) prc.getInboundMessageContext().addSubcontext(new OIDCMetadataContext());
+ metadataCtx = (OIDCMetadataContext) prc.ensureInboundMessageContext().addSubcontext(new OIDCMetadataContext());
final OIDCClientInformation information =
new OIDCClientInformation(new ClientID("000123"), new Date(), new OIDCClientMetadata(), new Secret());
metadataCtx.setClientInformation(information);
@@ -73,8 +72,8 @@ public class InitializeRelyingPartyContextTest {
public void testSuccessVerified() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(prc.getSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
- Assert.assertTrue(prc.getSubcontext(RelyingPartyContext.class).isVerified());
+ Assert.assertEquals(prc.ensureSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
+ Assert.assertTrue(prc.ensureSubcontext(RelyingPartyContext.class).isVerified());
}
/** Test that rp context has been initialized and rp is not verified. */
@@ -83,18 +82,18 @@ public class InitializeRelyingPartyContextTest {
metadataCtx.setClientInformation(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(prc.getSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
- Assert.assertFalse(prc.getSubcontext(RelyingPartyContext.class).isVerified());
+ Assert.assertEquals(prc.ensureSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
+ Assert.assertFalse(prc.ensureSubcontext(RelyingPartyContext.class).isVerified());
}
/** Test that rp context has been initialized and rp is not verified, no metadata context set. */
@Test
public void testSuccessUnverifiedNoMetadata() {
- prc.getInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
+ prc.ensureInboundMessageContext().removeSubcontext(OIDCMetadataContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(prc.getSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
- Assert.assertFalse(prc.getSubcontext(RelyingPartyContext.class).isVerified());
+ Assert.assertEquals(prc.ensureSubcontext(RelyingPartyContext.class).getRelyingPartyId(), "000123");
+ Assert.assertFalse(prc.ensureSubcontext(RelyingPartyContext.class).isVerified());
}
/** Test case of not being able to get client id from the request. */
@@ -105,26 +104,4 @@ public class InitializeRelyingPartyContextTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, EventIds.INVALID_MSG_CTX);
}
-
- /** Test case of setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testFailsNullOidcMetadataContextLookupStrategy() {
- action = new InitializeRelyingPartyContext();
- action.setOidcMetadataContextLookupStrategy(null);
- }
-
- /** Test case of setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testFailsNullClientIDLookupStrategy() {
- action = new InitializeRelyingPartyContext();
- action.setClientIDLookupStrategy(null);
- }
-
- /** Test case of setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testFailsNullRelyingPartyContextCreationStrategy() {
- action = new InitializeRelyingPartyContext();
- action.setRelyingPartyContextCreationStrategy(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeSubjectContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeSubjectContextTest.java
index 0a925795..27f1a909 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeSubjectContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeSubjectContextTest.java
@@ -62,6 +62,7 @@ public class InitializeSubjectContextTest extends BaseOIDCResponseActionTest {
* @throws ComponentInitializationException
* @throws URISyntaxException
*/
+ @SuppressWarnings("null")
@Test
public void testSuccess() throws ComponentInitializationException, URISyntaxException {
init();
@@ -79,7 +80,7 @@ public class InitializeSubjectContextTest extends BaseOIDCResponseActionTest {
.build();
respCtx.setAuthorizationGrantClaimsSet(claims);
final Event event = action.execute(requestCtx);
- final SubjectContext ctx = profileRequestCtx.getSubcontext(SubjectContext.class);
+ final SubjectContext ctx = profileRequestCtx.ensureSubcontext(SubjectContext.class);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertEquals(ctx.getPrincipalName(), "userPrin");
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeUnverifiedRelyingPartyContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeUnverifiedRelyingPartyContextTest.java
index d31b3d5a..f5b3aec7 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeUnverifiedRelyingPartyContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/InitializeUnverifiedRelyingPartyContextTest.java
@@ -27,7 +27,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
/** {@link InitializeUnverifiedRelyingPartyContext} unit test. */
public class InitializeUnverifiedRelyingPartyContextTest {
@@ -51,14 +50,6 @@ public class InitializeUnverifiedRelyingPartyContextTest {
public void testSuccessUnverified() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertFalse(prc.getSubcontext(RelyingPartyContext.class).isVerified());
+ Assert.assertFalse(prc.ensureSubcontext(RelyingPartyContext.class).isVerified());
}
-
- /** Test case of setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testFailsNullRelyingPartyContextCreationStrategy() {
- action = new InitializeUnverifiedRelyingPartyContext();
- action.setRelyingPartyContextCreationStrategy(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ManipulateClaimsForIDTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ManipulateClaimsForIDTokenTest.java
index 503b8b3b..ff942111 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ManipulateClaimsForIDTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ManipulateClaimsForIDTokenTest.java
@@ -66,11 +66,15 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
public void testSuccessSameMapDoesntChangeContents() throws ComponentInitializationException, ParseException {
final Instant now = Instant.now();
setIdTokenToResponseContext("iss", "sub", "aud", now, now);
- Assert.assertEquals(respCtx.getIDToken().toJSONObject().size(), 5);
+ assert respCtx != null;
+ final IDTokenClaimsSet initialIdToken = respCtx.getIDToken();
+ assert initialIdToken != null;
+ Assert.assertEquals(initialIdToken.toJSONObject().size(), 5);
init((prc, map) -> map);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
Assert.assertEquals(idToken.toJSONObject().size(), 5);
Assert.assertEquals(idToken.getSubject().getValue(), "sub");
Assert.assertEquals(idToken.getIssuer().getValue(), "iss");
@@ -83,13 +87,17 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
public void testSuccessManipulationForIss() throws ComponentInitializationException, ParseException {
final Instant now = Instant.now();
setIdTokenToResponseContext("iss", "sub", "aud", now, now);
- Assert.assertEquals(respCtx.getIDToken().toJSONObject().size(), 5);
+ assert respCtx != null;
+ final IDTokenClaimsSet initialIdToken = respCtx.getIDToken();
+ assert initialIdToken != null;
+ Assert.assertEquals(initialIdToken.toJSONObject().size(), 5);
final Map<String, Object> manipulatedClaims = Map.of("iss", "manipulatedIss", "sub", "sub", "aud",
List.of("aud"), "exp", now.getEpochSecond(), "iat", now.getEpochSecond());
init(mockFunction(manipulatedClaims));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
Assert.assertEquals(idToken.toJSONObject().size(), 5);
Assert.assertEquals(idToken.getSubject().getValue(), "sub");
Assert.assertEquals(idToken.getIssuer().getValue(), "manipulatedIss");
@@ -102,7 +110,10 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
public void testSuccessManipulationAddStandardClaims() throws ComponentInitializationException, ParseException {
final Instant now = Instant.now();
setIdTokenToResponseContext("iss", "sub", "aud", now, now);
- Assert.assertEquals(respCtx.getIDToken().toJSONObject().size(), 5);
+ assert respCtx != null;
+ final IDTokenClaimsSet initialIdToken = respCtx.getIDToken();
+ assert initialIdToken != null;
+ Assert.assertEquals(initialIdToken.toJSONObject().size(), 5);
final Map<String, Object> manipulatedClaims = Map.of("iss", "manipulatedIss", "sub", "sub", "aud",
List.of("aud"), "exp", now.getEpochSecond(), "iat", now.getEpochSecond(), "acr", "password",
"amr", List.of("face"));
@@ -110,6 +121,7 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
Assert.assertEquals(idToken.toJSONObject().size(), 7);
Assert.assertEquals(idToken.getSubject().getValue(), "sub");
Assert.assertEquals(idToken.getIssuer().getValue(), "manipulatedIss");
@@ -124,7 +136,10 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
public void testSuccessManipulationAddCustomClaims() throws ComponentInitializationException, ParseException {
final Instant now = Instant.now();
setIdTokenToResponseContext("iss", "sub", "aud", now, now);
- Assert.assertEquals(respCtx.getIDToken().toJSONObject().size(), 5);
+ assert respCtx != null;
+ final IDTokenClaimsSet initialIdToken = respCtx.getIDToken();
+ assert initialIdToken != null;
+ Assert.assertEquals(initialIdToken.toJSONObject().size(), 5);
final Map<String, Object> manipulatedClaims = Map.of("iss", "manipulatedIss", "sub", "sub", "aud",
List.of("aud"), "exp", now.getEpochSecond(), "iat", now.getEpochSecond(), "custom1", 3,
"custom2", List.of("customV1", "customV2"));
@@ -132,6 +147,7 @@ public class ManipulateClaimsForIDTokenTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
final IDTokenClaimsSet idToken = respCtx.getIDToken();
+ assert idToken != null;
Assert.assertEquals(idToken.toJSONObject().size(), 7);
Assert.assertEquals(idToken.getSubject().getValue(), "sub");
Assert.assertEquals(idToken.getIssuer().getValue(), "manipulatedIss");
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ProcessRequestedAuthnContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ProcessRequestedAuthnContextTest.java
index e465e0c6..30b5df38 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ProcessRequestedAuthnContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ProcessRequestedAuthnContextTest.java
@@ -102,6 +102,7 @@ public class ProcessRequestedAuthnContextTest extends BaseOIDCResponseActionTest
PreferredPrincipalContext rpCtx = ctx.getSubcontext(PreferredPrincipalContext.class);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(rpCtx);
+ assert rpCtx != null;
Assert.assertTrue(rpCtx.getPreferredPrincipals().contains(new AuthenticationContextClassReferencePrincipal("1")));
Assert.assertTrue(rpCtx.getPreferredPrincipals().contains(new AuthenticationContextClassReferencePrincipal("2")));
}
@@ -127,6 +128,7 @@ public class ProcessRequestedAuthnContextTest extends BaseOIDCResponseActionTest
PreferredPrincipalContext ppCtx = ctx.getSubcontext(PreferredPrincipalContext.class);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(ppCtx);
+ assert ppCtx != null;
Assert.assertTrue(ppCtx.getPreferredPrincipals().contains(new AuthenticationContextClassReferencePrincipal("1")));
}
@@ -154,6 +156,7 @@ public class ProcessRequestedAuthnContextTest extends BaseOIDCResponseActionTest
RequestedPrincipalContext rpCtx = ctx.getSubcontext(RequestedPrincipalContext.class);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(rpCtx);
+ assert rpCtx != null;
Assert.assertTrue(rpCtx.getRequestedPrincipals().contains(new AuthenticationContextClassReferencePrincipal("1")));
Assert.assertTrue(rpCtx.getRequestedPrincipals().contains(new AuthenticationContextClassReferencePrincipal("2")));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContextTest.java
index c89a52f2..a617682c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContextTest.java
@@ -40,6 +40,7 @@ public class SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContex
private SetAuthenticationContextClassReferenceFromAuthzCodeToResponseContext action;
+ @SuppressWarnings("null")
@BeforeMethod
private void init() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException {
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
index bf7f2a6b..3d446c01 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
@@ -59,6 +59,7 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
final RequestedPrincipalContext rpCtx = new RequestedPrincipalContext();
rpCtx.setOperator(AuthnContextComparisonTypeEnumeration.EXACT.toString());
+ assert principals != null;
rpCtx.setRequestedPrincipals(principals);
profileRequestCtx.ensureSubcontext(AuthenticationContext.class).addSubcontext(rpCtx, true);
@@ -66,7 +67,7 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
authSubject.getPrincipals().add(new AuthenticationContextClassReferencePrincipal("2"));
authSubject.getPrincipals().add(new AuthenticationContextClassReferencePrincipal("4"));
final AuthenticationResult result = new AuthenticationResult("flowId", authSubject);
- profileRequestCtx.getSubcontext(AuthenticationContext.class).setAuthenticationResult(result);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).setAuthenticationResult(result);
final AuthenticationFlowDescriptor descriptor = new AuthenticationFlowDescriptor();
descriptor.setId("flowId");
@@ -74,7 +75,7 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
descriptor.setResultSerializer(new DefaultAuthenticationResultSerializer());
descriptor.initialize();
- profileRequestCtx.getSubcontext(AuthenticationContext.class).getAvailableFlows().put("flowId", descriptor);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).getAvailableFlows().put("flowId", descriptor);
}
/**
@@ -92,8 +93,9 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
*/
@Test
public void testSuccessPreferredACR() {
- profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
+ assert principals != null;
ppCtx.setPreferredPrincipals(principals);
profileRequestCtx.ensureSubcontext(AuthenticationContext.class).addSubcontext(ppCtx, true);
final Event event = action.execute(requestCtx);
@@ -106,15 +108,18 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
*/
@Test
public void testSuccessPreferredACRNotMatching() {
- profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
principals.clear();
principals.add(new AuthenticationContextClassReferencePrincipal("1"));
+ assert principals != null;
ppCtx.setPreferredPrincipals(principals);
profileRequestCtx.ensureSubcontext(AuthenticationContext.class).addSubcontext(ppCtx, true);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getAcr().equals(new ACR("2")));
+ final ACR acr = respCtx.getAcr();
+ assert acr != null;
+ Assert.assertTrue(acr.equals(new ACR("2")));
}
/**
@@ -122,14 +127,15 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
*/
@Test
public void testSuccessPreferredACRNotMatching2() {
- profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
principals.clear();
principals.add(new AuthenticationContextClassReferencePrincipal("1"));
+ assert principals != null;
ppCtx.setPreferredPrincipals(principals);
profileRequestCtx.ensureSubcontext(AuthenticationContext.class).addSubcontext(ppCtx, true);
AuthenticationResult result = new AuthenticationResult("flowId", new Subject());
- profileRequestCtx.getSubcontext(AuthenticationContext.class).setAuthenticationResult(result);
+ profileRequestCtx.ensureSubcontext(AuthenticationContext.class).setAuthenticationResult(result);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNull(respCtx.getAcr());
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationTimeToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationTimeToResponseContextTest.java
index 47171db6..433b46ce 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationTimeToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetAuthenticationTimeToResponseContextTest.java
@@ -55,6 +55,7 @@ public class SetAuthenticationTimeToResponseContextTest extends BaseOIDCResponse
*
* @throws ComponentInitializationException
*/
+ @SuppressWarnings("null")
@Test
public void testSuccess() throws ComponentInitializationException {
init();
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentFromTokenToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentFromTokenToResponseContextTest.java
index 729b3a08..acfab10b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentFromTokenToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentFromTokenToResponseContextTest.java
@@ -60,6 +60,7 @@ public class SetConsentFromTokenToResponseContextTest extends BaseOIDCResponseAc
*
* @throws URISyntaxException
*/
+ @SuppressWarnings("null")
@Test
public void testSuccess() throws URISyntaxException {
final JSONArray consentedClaims = new JSONArray();
@@ -83,6 +84,7 @@ public class SetConsentFromTokenToResponseContextTest extends BaseOIDCResponseAc
final OIDCAuthenticationResponseConsentContext ctx =
respCtx.getSubcontext(OIDCAuthenticationResponseConsentContext.class);
Assert.assertNotNull(ctx);
+ assert ctx != null;
Assert.assertEquals(ctx.getConsentedAttributes(), consentedClaims);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentToResponseContextTest.java
index fff36836..4dd15279 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetConsentToResponseContextTest.java
@@ -21,8 +21,7 @@ import org.springframework.webflow.execution.Event;
import org.testng.Assert;
import org.testng.annotations.Test;
-import com.google.common.base.Predicates;
-
+import net.minidev.json.JSONArray;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.context.AttributeContext;
import net.shibboleth.idp.plugin.oidc.op.messaging.context.OIDCAuthenticationResponseConsentContext;
@@ -30,6 +29,7 @@ import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfiguration;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.PredicateSupport;
/** {@link SetConsentToResponseContext} unit test. */
public class SetConsentToResponseContextTest extends BaseOIDCResponseActionTest {
@@ -45,9 +45,9 @@ public class SetConsentToResponseContextTest extends BaseOIDCResponseActionTest
attributes.add(new IdPAttribute("2"));
attributeCtx.setIdPAttributes(attributes);
rpCtx.addSubcontext(attributeCtx);
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setEncodeConsentInTokens(encodeConsent);
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setEncodeConsentInTokens(encodeConsent);
action = new SetConsentToResponseContext();
- action.setConsentEnabledPredicate(consentEnabled ? Predicates.alwaysTrue() : Predicates.alwaysFalse());
+ action.setConsentEnabledPredicate(consentEnabled ? PredicateSupport.alwaysTrue() : PredicateSupport.alwaysFalse());
action.initialize();
}
@@ -73,7 +73,7 @@ public class SetConsentToResponseContextTest extends BaseOIDCResponseActionTest
@Test
public void testFailNoAttributeContext() throws ComponentInitializationException {
init(true, true);
- profileRequestCtx.getSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
+ profileRequestCtx.ensureSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNull(respCtx.getSubcontext(OIDCAuthenticationResponseConsentContext.class));
@@ -105,9 +105,12 @@ public class SetConsentToResponseContextTest extends BaseOIDCResponseActionTest
final OIDCAuthenticationResponseConsentContext ctx =
respCtx.getSubcontext(OIDCAuthenticationResponseConsentContext.class);
Assert.assertNotNull(ctx);
- Assert.assertTrue(ctx.getConsentedAttributes().contains("1"));
- Assert.assertTrue(ctx.getConsentedAttributes().contains("2"));
- Assert.assertTrue(ctx.getConsentedAttributes().size() == 2);
+ assert ctx != null;
+ final JSONArray consentedAttributes = ctx.getConsentedAttributes();
+ assert consentedAttributes != null;
+ Assert.assertTrue(consentedAttributes.contains("1"));
+ Assert.assertTrue(consentedAttributes.contains("2"));
+ Assert.assertTrue(consentedAttributes.size() == 2);
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRefreshTokenToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRefreshTokenToResponseContextTest.java
index fcb2dd60..df52fb4e 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRefreshTokenToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRefreshTokenToResponseContextTest.java
@@ -39,6 +39,8 @@ import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
+import javax.annotation.Nonnull;
+
import org.mockito.Mockito;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -52,6 +54,7 @@ import org.testng.annotations.Test;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.oauth2.sdk.id.ClientID;
+import com.nimbusds.oauth2.sdk.token.RefreshToken;
import com.nimbusds.openid.connect.sdk.OIDCScopeValue;
import com.nimbusds.openid.connect.sdk.claims.ACR;
@@ -71,6 +74,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
private Map<String, BiFunction<ProfileRequestContext,RefreshTokenClaimsSet,String>> serializers =
Mockito.mock(Map.class);
+ @SuppressWarnings("null")
@BeforeMethod
private void init() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException {
final Scope scope = new Scope();
@@ -101,6 +105,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
action = initAction(null);
}
+ @SuppressWarnings("null")
protected SetRefreshTokenToResponseContext initAction(final Function<ProfileRequestContext,
BiFunction<ProfileRequestContext,Map<String,Object>,Map<String,Object>>> manipulationStrategy)
throws ComponentInitializationException, NoSuchAlgorithmException {
@@ -133,12 +138,11 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
@Test
public void testSuccessViaCode() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
- final String jit = respCtx.getAuthorizationGrantClaimsSet().getID();
+ final String jit = parseJti();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), jit);
@@ -147,26 +151,31 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
@Test
public void testSuccessViaCodeCustomSerializer() throws ComponentInitializationException, NoSuchAlgorithmException,
URISyntaxException, ParseException, DataSealerException {
- final String jit = respCtx.getAuthorizationGrantClaimsSet().getID();
+ final String jit = parseJti();
Mockito.when(refreshTokenTypeLookupStrategy.apply(Mockito.any())).thenReturn("customType");
Mockito.when(serializers.get(Mockito.eq("customType"))).thenReturn(mockSerializer());
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), jit);
- Assert.assertEquals(rt.getClaimsSet().getBooleanClaim("customFlag"), true);
+ final JWTClaimsSet claimsSet = rt.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertEquals(claimsSet.getBooleanClaim("customFlag"), true);
}
protected BiFunction<ProfileRequestContext,RefreshTokenClaimsSet,String> mockSerializer() {
return (prc, claimsSet) -> {
try {
- final Map<String,Object> jwtClaimsSet = claimsSet.getClaimsSet().toJSONObject();
+ final JWTClaimsSet jwtSet = claimsSet.getClaimsSet();
+ assert jwtSet != null;
+ final Map<String,Object> jwtClaimsSet = jwtSet.toJSONObject();
jwtClaimsSet.put("customFlag", true);
- claimsSet.setClaimsSet(JWTClaimsSet.parse(jwtClaimsSet));
+ final JWTClaimsSet finalSet = JWTClaimsSet.parse(jwtClaimsSet);
+ assert finalSet != null;
+ claimsSet.setClaimsSet(finalSet);
return claimsSet.serialize(getDataSealer());
} catch (NoSuchAlgorithmException | DataSealerException | ComponentInitializationException
| ParseException e) {
@@ -180,20 +189,22 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
@Test
public void testSuccessViaCodeWithCustomClaim() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
- final String jit = respCtx.getAuthorizationGrantClaimsSet().getID();
+ final String jit = parseJti();
action = initAction(prc -> ((prc2, map) -> addEntryToMap(map, "custom_claim", "custom_value")));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), jit);
- Assert.assertNotNull(rt.getClaimsSet().getClaim("custom_claim"));
- Assert.assertEquals(rt.getClaimsSet().getStringClaim("custom_claim"), "custom_value");
+ final JWTClaimsSet claimsSet = rt.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNotNull(claimsSet.getClaim("custom_claim"));
+ Assert.assertEquals(claimsSet.getStringClaim("custom_claim"), "custom_value");
}
+ @SuppressWarnings("null")
@Test
public void testSuccessViaRefresh() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
@@ -217,12 +228,13 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), rootTokenId);
- Assert.assertTrue(rt.getChainExp().isAfter(Instant.now()));
+ final Instant expiration = rt.getChainExp();
+ assert expiration != null;
+ Assert.assertTrue(expiration.isAfter(Instant.now()));
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jit));
}
@@ -230,6 +242,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
public void testSuccessViaRefreshCustomSerializer() throws ComponentInitializationException,
NoSuchAlgorithmException, URISyntaxException, ParseException, DataSealerException {
final String rootTokenId = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new RefreshTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -251,14 +264,18 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), rootTokenId);
- Assert.assertTrue(rt.getChainExp().isAfter(Instant.now()));
+ final Instant expiration = rt.getChainExp();
+ assert expiration != null;
+ Assert.assertTrue(expiration.isAfter(Instant.now()));
+ assert jit != null;
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jit));
- Assert.assertEquals(rt.getClaimsSet().getBooleanClaim("customFlag"), true);
+ final JWTClaimsSet claimsSet = rt.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertEquals(claimsSet.getBooleanClaim("customFlag"), true);
}
@Test
@@ -266,6 +283,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
ParseException, DataSealerException {
final String rootTokenId = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
final Instant chainExp = Instant.now().plusSeconds(300).truncatedTo(ChronoUnit.SECONDS);
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new RefreshTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -286,12 +304,12 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), rootTokenId);
Assert.assertEquals(rt.getChainExp(), chainExp);
+ assert jit != null;
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jit));
}
@@ -299,6 +317,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
public void testSuccessViaRefreshWithCustomClaim() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
final String rootTokenId = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new RefreshTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -319,17 +338,22 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), rootTokenId);
- Assert.assertTrue(rt.getChainExp().isAfter(Instant.now()));
+ final Instant expiration = rt.getChainExp();
+ assert expiration != null;
+ Assert.assertTrue(expiration.isAfter(Instant.now()));
+ assert jit != null;
Assert.assertFalse(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jit));
- Assert.assertNotNull(rt.getClaimsSet().getClaim("custom_claim"));
- Assert.assertEquals(rt.getClaimsSet().getStringClaim("custom_claim"), "custom_value");
+ final JWTClaimsSet claimsSet = rt.getClaimsSet();
+ assert claimsSet != null;
+ Assert.assertNotNull(claimsSet.getClaim("custom_claim"));
+ Assert.assertEquals(claimsSet.getStringClaim("custom_claim"), "custom_value");
}
+ @SuppressWarnings("null")
@Test
public void testSuccessViaRefreshRotationEnforced() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
@@ -354,12 +378,13 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertNotNull(respCtx.getRefreshToken());
- final RefreshTokenClaimsSet rt =
- RefreshTokenClaimsSet.parse(respCtx.getRefreshToken().getValue(), getDataSealer());
+ final RefreshTokenClaimsSet rt = parseRefreshTokenClaimsSet();
Assert.assertNotNull(rt);
Assert.assertNotEquals(rt.getID(), jit);
Assert.assertEquals(rt.getRootTokenIdentifier(), rootTokenId);
- Assert.assertTrue(rt.getChainExp().isAfter(Instant.now()));
+ final Instant expiration = rt.getChainExp();
+ assert expiration != null;
+ Assert.assertTrue(expiration.isAfter(Instant.now()));
Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jit));
}
@@ -367,6 +392,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
public void testFailWithExpiredRefreshRotationEnforced() throws ComponentInitializationException, NoSuchAlgorithmException, URISyntaxException,
ParseException, DataSealerException {
final String rootTokenId = new SecureRandomIdentifierGenerationStrategy().generateIdentifier();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new RefreshTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -413,6 +439,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
public void testFailNoProfileConf()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
final RelyingPartyContext rpCtx = profileRequestCtx.getSubcontext(RelyingPartyContext.class);
+ assert rpCtx != null;
rpCtx.setProfileConfig(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_PROFILE_CONFIG);
@@ -428,6 +455,7 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
@Test
public void testFailTokenNotCodeOrRefresh()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException {
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new AccessTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -460,4 +488,23 @@ public class SetRefreshTokenToResponseContextTest extends BaseOIDCResponseAction
ActionTestingSupport.assertEvent(event, EventIds.INVALID_PROFILE_CTX);
}
+ @Nonnull private RefreshTokenClaimsSet parseRefreshTokenClaimsSet()
+ throws NoSuchAlgorithmException, ParseException, DataSealerException, ComponentInitializationException {
+ final RefreshToken refreshToken = respCtx.getRefreshToken();
+ assert refreshToken != null;
+ final String value = refreshToken.getValue();
+ assert value != null;
+ final RefreshTokenClaimsSet claimsSet = RefreshTokenClaimsSet.parse(value, getDataSealer());
+ assert claimsSet != null;
+ return claimsSet;
+ }
+
+ @Nonnull private String parseJti() {
+ final TokenClaimsSet tokenClaimsSet = respCtx.getAuthorizationGrantClaimsSet();
+ assert tokenClaimsSet != null;
+ final String jti = tokenClaimsSet.getID();
+ assert jti != null;
+ return jti;
+ }
+
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRequestedClaimsToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRequestedClaimsToResponseContextTest.java
index d6f0d58f..425af326 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRequestedClaimsToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetRequestedClaimsToResponseContextTest.java
@@ -23,6 +23,7 @@ import org.springframework.webflow.execution.Event;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.oauth2.sdk.id.ClientID;
import com.nimbusds.openid.connect.sdk.OIDCClaimsRequest;
@@ -33,6 +34,7 @@ import net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistry
import net.shibboleth.idp.authn.context.SubjectContext;
import net.shibboleth.idp.plugin.oidc.op.profile.context.navigate.TokenRequestRequestedClaimsLookupFunction;
import net.shibboleth.idp.plugin.oidc.op.token.support.AuthorizeCodeClaimsSet;
+import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.testing.MockReloadableService;
@@ -48,6 +50,7 @@ public class SetRequestedClaimsToResponseContextTest extends BaseOIDCResponseAct
com.nimbusds.oauth2.sdk.ParseException {
respCtx.setScope(new Scope());
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -86,8 +89,11 @@ public class SetRequestedClaimsToResponseContextTest extends BaseOIDCResponseAct
init();
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- final JSONObject claims =
- (JSONObject) respCtx.getAuthorizationGrantClaimsSet().getClaimsSet().getClaim("claims");
+ final TokenClaimsSet tokenClaimsSet = respCtx.getAuthorizationGrantClaimsSet();
+ assert tokenClaimsSet != null;
+ final JWTClaimsSet claimsSet = tokenClaimsSet.getClaimsSet();
+ assert claimsSet != null;
+ final JSONObject claims = (JSONObject) claimsSet.getClaim("claims");
Assert.assertTrue(isEssential(claims, "id_token", "email"));
Assert.assertTrue(isEssential(claims, "userinfo", "name"));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSectorIdentifierForAttributeResolutionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSectorIdentifierForAttributeResolutionTest.java
index 0108b07a..9bbf0849 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSectorIdentifierForAttributeResolutionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSectorIdentifierForAttributeResolutionTest.java
@@ -21,7 +21,6 @@ import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.oidc.profile.core.OidcEventIds;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
import org.springframework.webflow.execution.Event;
import org.testng.Assert;
@@ -29,6 +28,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.openid.connect.sdk.SubjectType;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
/** {@link SetSectorIdentifierForAttributeResolution} unit test. */
public class SetSectorIdentifierForAttributeResolutionTest extends BaseOIDCResponseActionTest {
@@ -40,8 +40,10 @@ public class SetSectorIdentifierForAttributeResolutionTest extends BaseOIDCRespo
private void init() throws ComponentInitializationException, URISyntaxException {
action = new SetSectorIdentifierForAttributeResolution();
action.initialize();
- metadataCtx.getClientInformation().getOIDCMetadata().setSubjectType(SubjectType.PUBLIC);
- metadataCtx.getClientInformation().getOIDCMetadata().setRedirectionURI(new URI("http://example.com"));
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setSubjectType(SubjectType.PUBLIC);
+ clientInformation.getOIDCMetadata().setRedirectionURI(new URI("http://example.com"));
}
/**
@@ -65,7 +67,9 @@ public class SetSectorIdentifierForAttributeResolutionTest extends BaseOIDCRespo
*/
@Test
public void testSuccessPairwise() throws ComponentInitializationException {
- metadataCtx.getClientInformation().getOIDCMetadata().setSubjectType(SubjectType.PAIRWISE);
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setSubjectType(SubjectType.PAIRWISE);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
final AttributeResolutionContext attribCtx =
@@ -80,28 +84,12 @@ public class SetSectorIdentifierForAttributeResolutionTest extends BaseOIDCRespo
*/
@Test
public void testFailPairwiseNoSectorIdentifier() throws ComponentInitializationException {
- metadataCtx.getClientInformation().getOIDCMetadata().setSubjectType(SubjectType.PAIRWISE);
- metadataCtx.getClientInformation().getOIDCMetadata().setRedirectionURI(null);
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setSubjectType(SubjectType.PAIRWISE);
+ clientInformation.getOIDCMetadata().setRedirectionURI(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.MISSING_REDIRECT_URIS);
}
- /**
- * Test setting null strategy for sector identifier.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullStrategySectorIdentifier() {
- action = new SetSectorIdentifierForAttributeResolution();
- action.setSectorIdentifierLookupStrategy(null);
- }
-
- /**
- * Test setting null strategy for subject type.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullStrategySubjectType() {
- action = new SetSectorIdentifierForAttributeResolution();
- action.setSubjectTypeLookupStrategy(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSessionIdToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSessionIdToResponseContextTest.java
index 1505b146..0849e41b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSessionIdToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSessionIdToResponseContextTest.java
@@ -20,7 +20,6 @@ import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.component.UnmodifiableComponentException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -28,6 +27,8 @@ import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.function.Function;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.webflow.execution.Event;
import org.testng.Assert;
@@ -45,22 +46,13 @@ public class SetSessionIdToResponseContextTest extends BaseOIDCResponseActionTes
init(new TokenRequestSessionIdLookupFunction());
}
- private void init(final Function<ProfileRequestContext, String> strategy)
+ private void init(@Nonnull final Function<ProfileRequestContext, String> strategy)
throws ComponentInitializationException {
action = new SetSessionIdToResponseContext();
action.setSessionIdLookupStrategy(strategy);
action.initialize();
}
- /**
- * Test that action throws error when null strategy is set.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNoStrategy() {
- action = new SetSessionIdToResponseContext();
- action.setSessionIdLookupStrategy(null);
- }
-
/**
* Test that action throws error when strategy is being set when already initialized.
*
@@ -82,6 +74,7 @@ public class SetSessionIdToResponseContextTest extends BaseOIDCResponseActionTes
@Test
public void testSuccessWithoutValue() throws ComponentInitializationException, URISyntaxException {
init();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new AccessTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -109,6 +102,7 @@ public class SetSessionIdToResponseContextTest extends BaseOIDCResponseActionTes
@Test
public void testSuccessWithValue() throws ComponentInitializationException, URISyntaxException {
init();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new AccessTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSubjectToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSubjectToResponseContextTest.java
index b7d02c06..15576968 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSubjectToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetSubjectToResponseContextTest.java
@@ -21,7 +21,6 @@ import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.oidc.profile.core.OidcEventIds;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.component.UnmodifiableComponentException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -57,15 +56,6 @@ public class SetSubjectToResponseContextTest extends BaseOIDCResponseActionTest
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_SUBJECT);
}
- /**
- * Test that action throws error when null strategy is set.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNoStrategy() {
- action = new SetSubjectToResponseContext();
- action.setSubjectLookupStrategy(null);
- }
-
/**
* Test that action throws error when strategy is being set when already initialized.
*
@@ -87,6 +77,7 @@ public class SetSubjectToResponseContextTest extends BaseOIDCResponseActionTest
@Test
public void testSuccess() throws ComponentInitializationException, URISyntaxException {
init();
+ @SuppressWarnings("null")
final TokenClaimsSet claims = new AccessTokenClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesFromTokenToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesFromTokenToResponseContextTest.java
index 63a790ec..af5f6622 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesFromTokenToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesFromTokenToResponseContextTest.java
@@ -18,7 +18,6 @@ import net.shibboleth.idp.plugin.oidc.op.messaging.context.OIDCAuthenticationRes
import net.shibboleth.idp.plugin.oidc.op.token.support.AuthorizeCodeClaimsSet;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -47,6 +46,7 @@ public class SetTokenDeliveryAttributesFromTokenToResponseContextTest extends Ba
dlClaimsUI.setClaim("deliveryClaimUI", "deliveryClaimUIValue");
final ClaimsSet dlClaimsID = new ClaimsSet();
dlClaimsID.setClaim("deliveryClaimID", "deliveryClaimIDValue");
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet acClaims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -79,9 +79,16 @@ public class SetTokenDeliveryAttributesFromTokenToResponseContextTest extends Ba
final OIDCAuthenticationResponseTokenClaimsContext respTokenClaims =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
Assert.assertNotNull(respTokenClaims);
- Assert.assertEquals(respTokenClaims.getUserinfoClaims().getClaim("deliveryClaimUI"), "deliveryClaimUIValue");
- Assert.assertEquals(respTokenClaims.getIdtokenClaims().getClaim("deliveryClaimID"), "deliveryClaimIDValue");
- Assert.assertEquals(respTokenClaims.getClaims().getClaim("deliveryClaim"), "deliveryClaimValue");
+ assert respTokenClaims != null;
+ final ClaimsSet userInfoClaims = respTokenClaims.getUserinfoClaims();
+ final ClaimsSet idTokenClaims = respTokenClaims.getIdtokenClaims();
+ final ClaimsSet deliveryClaims = respTokenClaims.getClaims();
+ assert userInfoClaims != null;
+ assert idTokenClaims != null;
+ assert deliveryClaims != null;
+ Assert.assertEquals(userInfoClaims.getClaim("deliveryClaimUI"), "deliveryClaimUIValue");
+ Assert.assertEquals(idTokenClaims.getClaim("deliveryClaimID"), "deliveryClaimIDValue");
+ Assert.assertEquals(deliveryClaims.getClaim("deliveryClaim"), "deliveryClaimValue");
}
/**
@@ -101,15 +108,6 @@ public class SetTokenDeliveryAttributesFromTokenToResponseContextTest extends Ba
Assert.assertNull(respTokenClaims);
}
- /**
- * Test setting null strategy for delivery claims.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullStrategyDClaims() {
- action = new SetTokenDeliveryAttributesFromTokenToResponseContext();
- action.setDeliveryClaimsLookupStrategy(null);
- }
-
/**
* Test setting null strategy for id token delivery claims.
*
@@ -127,9 +125,16 @@ public class SetTokenDeliveryAttributesFromTokenToResponseContextTest extends Ba
final OIDCAuthenticationResponseTokenClaimsContext respTokenClaims =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
Assert.assertNotNull(respTokenClaims);
- Assert.assertEquals(respTokenClaims.getUserinfoClaims().getClaim("deliveryClaimUI"), "deliveryClaimUIValue");
- Assert.assertNull(respTokenClaims.getIdtokenClaims().getClaim("deliveryClaimID"));
- Assert.assertEquals(respTokenClaims.getClaims().getClaim("deliveryClaim"), "deliveryClaimValue");
+ assert respTokenClaims != null;
+ final ClaimsSet userInfoClaims = respTokenClaims.getUserinfoClaims();
+ final ClaimsSet idTokenClaims = respTokenClaims.getIdtokenClaims();
+ final ClaimsSet deliveryClaims = respTokenClaims.getClaims();
+ assert userInfoClaims != null;
+ assert idTokenClaims != null;
+ assert deliveryClaims != null;
+ Assert.assertEquals(userInfoClaims.getClaim("deliveryClaimUI"), "deliveryClaimUIValue");
+ Assert.assertNull(idTokenClaims.getClaim("deliveryClaimID"));
+ Assert.assertEquals(deliveryClaims.getClaim("deliveryClaim"), "deliveryClaimValue");
}
/**
@@ -149,8 +154,15 @@ public class SetTokenDeliveryAttributesFromTokenToResponseContextTest extends Ba
final OIDCAuthenticationResponseTokenClaimsContext respTokenClaims =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
Assert.assertNotNull(respTokenClaims);
- Assert.assertNull(respTokenClaims.getUserinfoClaims().getClaim("deliveryClaimUI"));
- Assert.assertEquals(respTokenClaims.getIdtokenClaims().getClaim("deliveryClaimID"), "deliveryClaimIDValue");
- Assert.assertEquals(respTokenClaims.getClaims().getClaim("deliveryClaim"), "deliveryClaimValue");
+ assert respTokenClaims != null;
+ final ClaimsSet userInfoClaims = respTokenClaims.getUserinfoClaims();
+ final ClaimsSet idTokenClaims = respTokenClaims.getIdtokenClaims();
+ final ClaimsSet deliveryClaims = respTokenClaims.getClaims();
+ assert userInfoClaims != null;
+ assert idTokenClaims != null;
+ assert deliveryClaims != null;
+ Assert.assertNull(userInfoClaims.getClaim("deliveryClaimUI"));
+ Assert.assertEquals(idTokenClaims.getClaim("deliveryClaimID"), "deliveryClaimIDValue");
+ Assert.assertEquals(deliveryClaims.getClaim("deliveryClaim"), "deliveryClaimValue");
}
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesToResponseContextTest.java
index d270e226..2c9e677d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/SetTokenDeliveryAttributesToResponseContextTest.java
@@ -47,6 +47,7 @@ import net.shibboleth.oidc.attribute.transcoding.OIDCAttributeTranscoder;
import net.shibboleth.oidc.attribute.transcoding.impl.OIDCStringAttributeTranscoder;
import net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfiguration;
import net.shibboleth.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.testing.MockApplicationContext;
import net.shibboleth.shared.testing.MockReloadableService;
@@ -61,13 +62,13 @@ public class SetTokenDeliveryAttributesToResponseContextTest extends BaseOIDCRes
@BeforeMethod
public void setup() throws ComponentInitializationException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setEncodedAttributes(
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setEncodedAttributes(
Set.of("test1", "test2", "test3", "test4"));
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setAlwaysIncludedAttributes(
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setAlwaysIncludedAttributes(
Set.of("test2", "test3"));
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setDeniedUserInfoAttributes(
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setDeniedUserInfoAttributes(
Set.of("test2", "test4"));
registry = new AttributeTranscoderRegistryImpl();
@@ -100,7 +101,7 @@ public class SetTokenDeliveryAttributesToResponseContextTest extends BaseOIDCRes
new BasicNamingFunction<>(transcoder.getEncodedType(),
new AbstractOIDCAttributeTranscoder.NamingFunction())));
- registry.setTranscoderRegistry(List.of(
+ registry.setTranscoderRegistry(CollectionSupport.listOf(
new TranscodingRule(rule1),
new TranscodingRule(rule2),
new TranscodingRule(rule3),
@@ -152,7 +153,7 @@ public class SetTokenDeliveryAttributesToResponseContextTest extends BaseOIDCRes
attributes.add(attribute3);
attributes.add(attribute4);
attributeCtx.setIdPAttributes(attributes);
- profileRequestCtx.getSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
+ profileRequestCtx.ensureSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
}
/**
@@ -176,7 +177,7 @@ public class SetTokenDeliveryAttributesToResponseContextTest extends BaseOIDCRes
final OIDCAuthenticationResponseTokenClaimsContext respTokenClaims =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
Assert.assertNotNull(respTokenClaims);
-
+ assert respTokenClaims != null;
Assert.assertNull(respTokenClaims.getClaims().getClaim("test1"));
Assert.assertNull(respTokenClaims.getIdtokenClaims().getClaim("test1"));
Assert.assertEquals(respTokenClaims.getUserinfoClaims().getClaim("test1"), "value1 value2");
@@ -210,6 +211,7 @@ public class SetTokenDeliveryAttributesToResponseContextTest extends BaseOIDCRes
final OIDCAuthenticationResponseTokenClaimsContext respTokenClaims =
respCtx.getSubcontext(OIDCAuthenticationResponseTokenClaimsContext.class);
Assert.assertNotNull(respTokenClaims);
+ assert respTokenClaims != null;
Assert.assertEquals(respTokenClaims.getClaims().getClaim("test1"), "value1 value2");
Assert.assertNull(respTokenClaims.getIdtokenClaims().getClaim("test1"));
Assert.assertNull(respTokenClaims.getUserinfoClaims().getClaim("test1"));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTest.java
index 4539ebe5..e3083841 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTest.java
@@ -24,7 +24,7 @@ import net.shibboleth.idp.profile.IdPEventIds;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.oidc.profile.core.OidcEventIds;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
+import net.shibboleth.shared.logic.PredicateSupport;
import net.shibboleth.shared.security.DataSealerException;
import net.shibboleth.shared.security.impl.SecureRandomIdentifierGenerationStrategy;
@@ -48,7 +48,6 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import com.google.common.base.Predicates;
import com.nimbusds.oauth2.sdk.AuthorizationCode;
import com.nimbusds.oauth2.sdk.AuthorizationCodeGrant;
import com.nimbusds.oauth2.sdk.AuthorizationGrant;
@@ -105,6 +104,7 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
init(refreshTokensEnabled, revocationCache, revocationLifetimeLookup, Instant.now(), null);
}
+ @SuppressWarnings("null")
private void init(boolean refreshTokensEnabled, final RevocationCache revocationCache,
final Function<ProfileRequestContext, Duration> revocationLifetimeLookup,
final Instant authenticationTime,
@@ -135,7 +135,7 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
rfGrant = new RefreshTokenGrant(rfToken);
// by default we create authz code request
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), codeGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
action = new ValidateGrant(getDataSealer());
if (revocationLifetimeLookup != null) {
action.setChainRevocationLifetimeLookupStrategy(revocationLifetimeLookup);
@@ -148,9 +148,9 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
replayCache.setStorage(storageService);
action.setReplayCache(replayCache);
if (refreshTokensEnabled) {
- action.setRefreshTokensEnabledPredicate(Predicates.alwaysTrue());
+ action.setRefreshTokensEnabledPredicate(PredicateSupport.alwaysTrue());
} else {
- action.setRefreshTokensEnabledPredicate(Predicates.alwaysFalse());
+ action.setRefreshTokensEnabledPredicate(PredicateSupport.alwaysFalse());
}
action.initialize();
}
@@ -191,6 +191,7 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
return new AuthorizationCode(acClaims.serialize(new ValidateGrantTest().getDataSealer()));
}
+ @SuppressWarnings("null")
static public TokenClaimsSet buildTokenClaimsSet(final String clientId, final String issuer,
final String userPrincipal, final String sub, final String callbackUrl, final String codeChallenge,
final JSONObject deliveryClaims, final JSONObject deliveryClaimsIDToken,
@@ -230,7 +231,7 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
init();
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNotNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -245,10 +246,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenSuccess() throws Exception {
init();
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNotNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -257,7 +258,7 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
init();
final RefreshToken customToken = new RefreshToken("customPrefix" + rfGrant.getRefreshToken().getValue());
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), new RefreshTokenGrant(customToken));
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
}
@@ -269,7 +270,9 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
@Override
public RefreshTokenClaimsSet apply(final ProfileRequestContext prc, final String value ) {
try {
- return RefreshTokenClaimsSet.parse(value.substring("customPrefix".length()), getDataSealer());
+ final String strippedValue = value.substring("customPrefix".length());
+ assert strippedValue != null;
+ return RefreshTokenClaimsSet.parse(strippedValue, getDataSealer());
} catch (NoSuchAlgorithmException | ParseException | DataSealerException
| ComponentInitializationException e) {
Assert.fail("Could not decrypt the custom refresh token", e);
@@ -281,10 +284,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
init(true, new MockRevocationCache(false, true), null, Instant.now(), deserializers);
final RefreshToken customToken = new RefreshToken("customPrefix" + rfGrant.getRefreshToken().getValue());
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), new RefreshTokenGrant(customToken));
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNotNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -292,10 +295,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenChainExpired() throws Exception {
init(Instant.now().minus(Duration.ofHours(2)));
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -303,10 +306,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenNotEnabled() throws Exception {
init(false);
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -314,11 +317,11 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenReplayed() throws Exception {
init();
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNotNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -326,13 +329,14 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenAuthorizationGrantRevoked() throws Exception {
final RevocationCache revocationCache = buildRevocationCache();
init(true, revocationCache, null);
- Assert.assertTrue(revocationCache.revoke(RevocationCacheContexts.AUTHORIZATION_CODE,
- rfClaims.getRootTokenIdentifier()));
+ final String rootJti = rfClaims.getRootTokenIdentifier();
+ assert rootJti != null;
+ Assert.assertTrue(revocationCache.revoke(RevocationCacheContexts.AUTHORIZATION_CODE, rootJti));
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -340,26 +344,30 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
public void testRefreshTokenRevokedShouldRevokeAuthorizationCode() throws Exception {
final RevocationCache revocationCache = buildRevocationCache();
init(true, revocationCache, null);
- Assert.assertTrue(revocationCache.revoke(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS,
- rfClaims.getID()));
+ final String jti = rfClaims.getID();
+ assert jti != null;
+ Assert.assertTrue(revocationCache.revoke(RevocationCacheContexts.SINGLE_ACCESS_OR_REFRESH_TOKENS, jti));
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
- Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE,
- rfClaims.getRootTokenIdentifier()));
+ final String rootJti = rfClaims.getRootTokenIdentifier();
+ assert rootJti != null;
+ Assert.assertTrue(revocationCache.isRevoked(RevocationCacheContexts.AUTHORIZATION_CODE, rootJti));
}
protected RevocationCache buildRevocationCache() throws ComponentInitializationException {
final StorageServiceRevocationCache revocationCache = new StorageServiceRevocationCache();
revocationCache.setId("mockCache");
+ assert storageService != null;
revocationCache.setStorage(storageService);
revocationCache.initialize();
return revocationCache;
}
+ @SuppressWarnings("null")
@Test
public void testTokenRevocationViaRevokedTokenFailsReturnsInvalidProfileConfig() throws Exception {
RevocationCache revocationCache = Mockito.mock(RevocationCache.class);
@@ -370,10 +378,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
Mockito.when(revocationCache.revoke(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
init(true, revocationCache, prc -> null);
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId), rfGrant);
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -382,10 +390,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
init();
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId),
new RefreshTokenGrant(new RefreshToken(acClaims.serialize(getDataSealer()))));
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -396,13 +404,14 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
buildAuthorizationCode("clientIdWrong", "issuer", "userPrin", "subject", "http://example.com");
final TokenRequest req =
new TokenRequest(callback, new ClientID(clientId), new AuthorizationCodeGrant(code, callback));
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
+ @SuppressWarnings("null")
@Test
public void testExpired() throws Exception {
init();
@@ -410,10 +419,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
rfClaims = new RefreshTokenClaimsSet.Builder(acClaims, now, now.minusMillis(10)).build();
final TokenRequest req = new TokenRequest(callback, new ClientID(clientId),
new RefreshTokenGrant(new RefreshToken(rfClaims.serialize(getDataSealer()))));
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertEvent(action.execute(requestCtx), OidcEventIds.INVALID_GRANT);
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -423,10 +432,10 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
final TokenRequest req = new TokenRequest(callback,
new ClientSecretBasic(new ClientID(clientId), new Secret("foo")),
new ClientCredentialsGrant());
- profileRequestCtx.getInboundMessageContext().setMessage(req);
+ profileRequestCtx.ensureInboundMessageContext().setMessage(req);
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
final OIDCAuthenticationResponseContext arc =
- profileRequestCtx.getOutboundMessageContext().getSubcontext(OIDCAuthenticationResponseContext.class);
+ profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertNull(arc.getAuthorizationGrantClaimsSet());
}
@@ -449,11 +458,6 @@ public class ValidateGrantTest extends BaseOIDCResponseActionTest {
action.initialize();
}
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNoDataSealer() {
- action = new ValidateGrant(null);
- }
-
private static class DeliveryClaimsSet extends ClaimsSet {
public DeliveryClaimsSet(final JSONObject claims) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTypeTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTypeTest.java
index cac6c94f..4a8fa9b1 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTypeTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidateGrantTypeTest.java
@@ -15,7 +15,6 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
import java.net.URI;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -37,6 +36,7 @@ import net.shibboleth.oidc.metadata.context.OIDCMetadataContext;
import net.shibboleth.oidc.profile.core.OidcEventIds;
import net.shibboleth.oidc.profile.oauth2.config.impl.DefaultOAuth2TokenConfiguration;
import net.shibboleth.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.collection.CollectionSupport;
/** {@link ValidateGrantType} unit test. */
public class ValidateGrantTypeTest extends BaseOIDCResponseActionTest {
@@ -55,7 +55,7 @@ public class ValidateGrantTypeTest extends BaseOIDCResponseActionTest {
action = new ValidateGrantType();
action.initialize();
final OIDCMetadataContext oidcCtx =
- profileRequestCtx.getInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class);
metaData = new OIDCClientMetadata();
final Set<GrantType> grantTypes = new HashSet<>();
grantTypes.add(GrantType.parse("refresh_token"));
@@ -84,8 +84,8 @@ public class ValidateGrantTypeTest extends BaseOIDCResponseActionTest {
*/
@Test
public void testSuccessNoMetadata() {
- profileRequestCtx.getInboundMessageContext().removeSubcontext(
- profileRequestCtx.getInboundMessageContext().getSubcontext(OIDCMetadataContext.class));
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class));
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
}
@@ -93,14 +93,15 @@ public class ValidateGrantTypeTest extends BaseOIDCResponseActionTest {
/**
* Test that action accepts the "refresh_token" grant type based on profile config.
*/
+ @SuppressWarnings("null")
@Test
public void testFailureNoMetadata() {
- profileRequestCtx.getInboundMessageContext().removeSubcontext(
- profileRequestCtx.getInboundMessageContext().getSubcontext(OIDCMetadataContext.class));
+ profileRequestCtx.ensureInboundMessageContext().removeSubcontext(
+ profileRequestCtx.ensureInboundMessageContext().ensureSubcontext(OIDCMetadataContext.class));
final DefaultOAuth2TokenConfiguration config = new DefaultOAuth2TokenConfiguration();
- config.setGrantTypes(Collections.singleton(GrantType.AUTHORIZATION_CODE.toString()));
- profileRequestCtx.getSubcontext(RelyingPartyContext.class).setProfileConfig(config);
+ config.setGrantTypes(CollectionSupport.singleton(GrantType.AUTHORIZATION_CODE.toString()));
+ profileRequestCtx.ensureSubcontext(RelyingPartyContext.class).setProfileConfig(config);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, OidcEventIds.INVALID_GRANT_TYPE);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidatePKCETest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidatePKCETest.java
index d8b3d753..dfe5a8c1 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidatePKCETest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/ValidatePKCETest.java
@@ -61,6 +61,7 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
new AuthorizationCodeGrant(new AuthorizationCode("mockCode"), new URI("https://client.com/callback"),
new CodeVerifier(codeVerifier)));
setTokenRequest(req);
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -110,6 +111,7 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testFailPlainNotAllowed() throws URISyntaxException {
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -137,7 +139,8 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testSuccessPlain() throws URISyntaxException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setAllowPKCEPlain(true);
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setAllowPKCEPlain(true);
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -165,7 +168,8 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testFailPlain() throws URISyntaxException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setAllowPKCEPlain(true);
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setAllowPKCEPlain(true);
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -196,6 +200,7 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
final TokenRequest req = new TokenRequest(new URI("https://client.com/callback"), new ClientID(clientId),
new AuthorizationCodeGrant(new AuthorizationCode("mockCode"), new URI("https://client.com/callback")));
setTokenRequest(req);
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -221,10 +226,11 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testFailureNoPKCE() throws URISyntaxException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setForcePKCE(true);
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setForcePKCE(true);
final TokenRequest req = new TokenRequest(new URI("https://client.com/callback"), new ClientID(clientId),
new AuthorizationCodeGrant(new AuthorizationCode("mockCode"), new URI("https://client.com/callback")));
setTokenRequest(req);
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
@@ -265,10 +271,11 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testSuccessNoAuthzCode() throws URISyntaxException {
- ((DefaultOIDCAuthorizationConfiguration) rpCtx.getProfileConfig()).setForcePKCE(true);
+ ((DefaultOIDCAuthorizationConfiguration) rpCtx.ensureProfileConfig()).setForcePKCE(true);
final TokenRequest req = new TokenRequest(new URI("https://client.com/callback"), new ClientID(clientId),
new RefreshTokenGrant(new RefreshToken()));
setTokenRequest(req);
+ @SuppressWarnings("null")
final RefreshTokenClaimsSet claims = new RefreshTokenClaimsSet.Builder(
new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
@@ -296,6 +303,7 @@ public class ValidatePKCETest extends BaseOIDCResponseActionTest {
*/
@Test
public void testFailUnknownType() throws URISyntaxException {
+ @SuppressWarnings("null")
final AuthorizeCodeClaimsSet claims = new AuthorizeCodeClaimsSet.Builder()
.setJWTID(idGenerator)
.setClientID(new ClientID())
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/AttributeResolutionSubjectLookupFunctionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/AttributeResolutionSubjectLookupFunctionTest.java
index 382a1666..2db5fc8a 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/AttributeResolutionSubjectLookupFunctionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/AttributeResolutionSubjectLookupFunctionTest.java
@@ -37,8 +37,9 @@ import net.shibboleth.oidc.attribute.transcoding.AbstractOIDCAttributeTranscoder
import net.shibboleth.oidc.attribute.transcoding.OIDCAttributeTranscoder;
import net.shibboleth.oidc.attribute.transcoding.impl.OIDCStringAttributeTranscoder;
import net.shibboleth.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
+import net.shibboleth.shared.logic.PredicateSupport;
import net.shibboleth.shared.testing.MockApplicationContext;
import net.shibboleth.shared.testing.MockReloadableService;
@@ -50,8 +51,6 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import com.google.common.base.Predicates;
-
/** {@link AttributeResolutionSubjectLookupFunction} unit test. */
public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBaseTestCase {
@@ -81,7 +80,7 @@ public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBa
rule2.put(OIDCAttributeTranscoder.PROP_NAME, "sub");
final OIDCStringAttributeTranscoder offTranscoder = new OIDCStringAttributeTranscoder();
- offTranscoder.setActivationCondition(Predicates.alwaysFalse());
+ offTranscoder.setActivationCondition(PredicateSupport.alwaysFalse());
offTranscoder.initialize();
final Map<String,Object> rule3 = new HashMap<>();
@@ -116,7 +115,7 @@ public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBa
stringAttributeValues2.add(new StringAttributeValue("joe"));
attribute2.setValues(stringAttributeValues2);
- registry.setTranscoderRegistry(List.of(
+ registry.setTranscoderRegistry(CollectionSupport.listOf(
new TranscodingRule(rule1),
new TranscodingRule(rule2),
new TranscodingRule(rule3),
@@ -157,7 +156,7 @@ public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBa
*/
@Test
public void testNoAttributeCtx() {
- prc.getSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
+ prc.ensureSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
Assert.assertNull(lookup.apply(prc));
}
@@ -166,25 +165,16 @@ public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBa
*/
@Test
public void testNoAttributes() {
- prc.ensureSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class).setIdPAttributes(null);
+ prc.ensureSubcontext(RelyingPartyContext.class).ensureSubcontext(AttributeContext.class).setIdPAttributes(null);
Assert.assertNull(lookup.apply(prc));
}
- /**
- * Test that lookup does not accept null strategy.
- */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testFailNullStrategy() {
- lookup = new AttributeResolutionSubjectLookupFunction();
- lookup.setAttributeContextLookupStrategy(null);
- }
-
/**
* Test that lookup is not picking subs with inactive or wrong type of encoders.
*/
@Test
public void testOnlyActive() {
- prc.getSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
+ prc.ensureSubcontext(RelyingPartyContext.class).removeSubcontext(AttributeContext.class);
// sub attribute, not active encoder
final IdPAttribute attribute1 = new IdPAttribute("test3");
@@ -210,7 +200,7 @@ public class AttributeResolutionSubjectLookupFunctionTest extends OpenSAMLInitBa
attributes.add(attribute2);
attributes.add(attribute3);
attributeCtx.setIdPAttributes(attributes);
- prc.getSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
+ prc.ensureSubcontext(RelyingPartyContext.class).addSubcontext(attributeCtx);
Assert.assertNull(lookup.apply(prc));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultTokenRevocationLifetimeLookupStrategyTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultTokenRevocationLifetimeLookupStrategyTest.java
index a5bc8902..2f41ac5c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultTokenRevocationLifetimeLookupStrategyTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultTokenRevocationLifetimeLookupStrategyTest.java
@@ -32,6 +32,7 @@ public class DefaultTokenRevocationLifetimeLookupStrategyTest {
protected void initFunction(final Duration clockSkew) {
function = new DefaultTokenRevocationLifetimeLookupStrategy();
+ assert clockSkew != null;
function.setClockSkew(clockSkew);
}
@@ -70,6 +71,7 @@ public class DefaultTokenRevocationLifetimeLookupStrategyTest {
public void testExpiredButWithinClockSkewReturnsNonZero() {
initFunction(Duration.ofSeconds(10));
final Duration result = function.apply(buildClaimsSet(Instant.now().minusSeconds(5)));
+ assert result != null;
Assert.assertFalse(result.isZero() || result.isNegative());
}
@@ -77,6 +79,7 @@ public class DefaultTokenRevocationLifetimeLookupStrategyTest {
public void testUnExpiredButWithoutClockSkewReturnsNonZero() {
initFunction(Duration.ZERO);
final Duration result = function.apply(buildClaimsSet(Instant.now().plusSeconds(5)));
+ assert result != null;
Assert.assertFalse(result.isZero() || result.isNegative());
}
@@ -85,6 +88,7 @@ public class DefaultTokenRevocationLifetimeLookupStrategyTest {
final Instant now = Instant.now();
initFunction(Duration.ofMinutes(5));
final Duration result = function.apply(buildClaimsSet(now.plusSeconds(5)));
+ assert result != null;
Assert.assertFalse(result.minus(Duration.ofMinutes(10)).isNegative());
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultUnregisteredClientResponseTypesLookupFunctionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultUnregisteredClientResponseTypesLookupFunctionTest.java
index 987037fa..ffcb0414 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultUnregisteredClientResponseTypesLookupFunctionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultUnregisteredClientResponseTypesLookupFunctionTest.java
@@ -15,9 +15,7 @@
package net.shibboleth.idp.plugin.oidc.op.profile.logic;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -28,10 +26,12 @@ import com.nimbusds.oauth2.sdk.ResponseType;
import net.shibboleth.oidc.metadata.policy.MetadataPolicy;
import net.shibboleth.oidc.metadata.policy.UnregisteredClientPolicy;
+import net.shibboleth.shared.collection.CollectionSupport;
/**
* Unit tests for {@link DefaultUnregisteredClientResponseTypesLookupFunction}.
*/
+ at SuppressWarnings({"deprecation", "removal"})
public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
DefaultUnregisteredClientResponseTypesLookupFunction function;
@@ -39,25 +39,32 @@ public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
public void setup(final UnregisteredClientPolicy policy) {
function = new DefaultUnregisteredClientResponseTypesLookupFunction();
function.setUnregisteredClientPolicyLookupStrategy(prc -> policy == null ?
- Collections.emptyMap() : Map.of("response_type", policy));
+ CollectionSupport.emptyMap() : CollectionSupport.singletonMap("response_type", policy));
}
@Test
public void testNoPolicy() {
setup(null);
- Assert.assertTrue(function.apply(new ProfileRequestContext()).isEmpty());
+ assert function != null;
+ final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
+ Assert.assertTrue(result.isEmpty());
}
@Test
public void testNoResponseTypePolicy() {
setup(new UnregisteredClientPolicy(new MetadataPolicy()));
- Assert.assertTrue(function.apply(new ProfileRequestContext()).isEmpty());
+ assert function != null;
+ final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
+ Assert.assertTrue(result.isEmpty());
}
@Test
public void testWithIntegers() {
setup(buildOneOfPolicy(List.of(1, 2)));
final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
Assert.assertEquals(result.size(), 2);
Assert.assertTrue(result.contains(new ResponseType("1")));
Assert.assertTrue(result.contains(new ResponseType("2")));
@@ -67,6 +74,7 @@ public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
public void testWithStrings() {
setup(buildOneOfPolicy(List.of("code", "id_token")));
final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
Assert.assertEquals(result.size(), 2);
Assert.assertTrue(result.contains(new ResponseType(ResponseType.Value.CODE)));
Assert.assertTrue(result.contains(ResponseType.IDTOKEN));
@@ -78,6 +86,7 @@ public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
list.add(null);
setup(buildOneOfPolicy(list));
final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
Assert.assertEquals(result.size(), 2);
Assert.assertTrue(result.contains(new ResponseType(ResponseType.Value.CODE)));
Assert.assertTrue(result.contains(ResponseType.IDTOKEN));
@@ -87,6 +96,7 @@ public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
public void testWithLists() {
setup(buildOneOfPolicy(List.of(List.of("1"), List.of("2"))));
final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
Assert.assertEquals(result.size(), 2);
Assert.assertTrue(result.contains(new ResponseType(List.of("1").toString())));
Assert.assertTrue(result.contains(new ResponseType(List.of("2").toString())));
@@ -96,6 +106,7 @@ public class DefaultUnregisteredClientResponseTypesLookupFunctionTest {
public void testWithMixedContent() {
setup(buildOneOfPolicy(List.of(1, List.of("2"), "code")));
final Set<ResponseType> result = function.apply(new ProfileRequestContext());
+ assert result != null;
Assert.assertEquals(result.size(), 3);
Assert.assertTrue(result.contains(new ResponseType("1")));
Assert.assertTrue(result.contains(new ResponseType(List.of("2").toString())));
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/MetadataValueEqualsConditionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/MetadataValueEqualsConditionTest.java
index 59fde8c1..22300e3b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/MetadataValueEqualsConditionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/MetadataValueEqualsConditionTest.java
@@ -31,6 +31,7 @@ public class MetadataValueEqualsConditionTest {
MetadataValueEqualsCondition predicate;
+ @SuppressWarnings("null")
public void setup(final OIDCClientMetadata metadata, final String key, final Object value, final Object defValue)
throws ComponentInitializationException {
predicate = new MetadataValueEqualsCondition();
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/SubjectActivationConditionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/SubjectActivationConditionTest.java
index 926629c8..b2214ad8 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/SubjectActivationConditionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/SubjectActivationConditionTest.java
@@ -34,6 +34,7 @@ public class SubjectActivationConditionTest {
protected OIDCAuthenticationResponseContext respCtx;
+ @SuppressWarnings("null")
@BeforeMethod
public void setup() throws ComponentInitializationException {
lookup = new SubjectActivationCondition();
@@ -41,7 +42,7 @@ public class SubjectActivationConditionTest {
prc.setOutboundMessageContext(new MessageContext());
respCtx = new OIDCAuthenticationResponseContext();
respCtx.setSubject("joe");
- prc.getOutboundMessageContext().addSubcontext(respCtx);
+ prc.ensureOutboundMessageContext().addSubcontext(respCtx);
}
/**
@@ -66,7 +67,7 @@ public class SubjectActivationConditionTest {
*/
@Test
public void testNoOIDCResponseCtx() {
- prc.getOutboundMessageContext().removeSubcontext(OIDCAuthenticationResponseContext.class);
+ prc.ensureOutboundMessageContext().removeSubcontext(OIDCAuthenticationResponseContext.class);
Assert.assertTrue(lookup.test(prc));
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/TokenExtensionFactoryTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/TokenExtensionFactoryTest.java
index 0a3cf07b..364ba5a3 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/TokenExtensionFactoryTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/TokenExtensionFactoryTest.java
@@ -42,6 +42,7 @@ public class TokenExtensionFactoryTest {
TokenExtensionFactory factory;
@Nonnull String beanId = "mockBeanId";
+ @SuppressWarnings("null")
public void initFactory(@Nonnull final TokenExtensionType type, @Nullable final Object bean,
final boolean isPrototype, final boolean nonPrototypeAllowed) {
ApplicationContext applicationContext = mock(ApplicationContext.class);
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/relyingparty/metadata/impl/ReloadProviderResolverServiceConfigurationTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/relyingparty/metadata/impl/ReloadProviderResolverServiceConfigurationTest.java
index 2d12a1e6..f8877ef0 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/relyingparty/metadata/impl/ReloadProviderResolverServiceConfigurationTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/relyingparty/metadata/impl/ReloadProviderResolverServiceConfigurationTest.java
@@ -70,6 +70,7 @@ public class ReloadProviderResolverServiceConfigurationTest {
new ProviderMetadataResolverServiceStrategy());
service.setFailFast(true);
service.setId("mockId");
+ assert serviceConfigurations != null;
service.setServiceConfigurations(serviceConfigurations);
service.initialize();
}
@@ -118,7 +119,7 @@ public class ReloadProviderResolverServiceConfigurationTest {
final HttpServletResponse response) throws ComponentInitializationException {
final ReloadServiceConfiguration action = new ReloadServiceConfiguration();
action.setHttpServletResponseSupplier(new NonnullSupplier<> () {
- public HttpServletResponse get() { return response;}
+ public HttpServletResponse get() { assert response != null; return response;}
});
action.setServiceLookupStrategy(new Function<ProfileRequestContext,ReloadableService<?>>() {
public ReloadableService<?> apply(ProfileRequestContext input) {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/session/impl/OIDCRPSessionCreationStrategyTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/session/impl/OIDCRPSessionCreationStrategyTest.java
index 487941c0..b73b6d3d 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/session/impl/OIDCRPSessionCreationStrategyTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/session/impl/OIDCRPSessionCreationStrategyTest.java
@@ -62,6 +62,7 @@ public class OIDCRPSessionCreationStrategyTest {
public void setup(final Duration lifetime, final OIDCMetadataContext metadataContext,
final OIDCAuthenticationResponseContext responseContext, final String clientId) {
+ assert lifetime != null;
function = new OIDCRPSessionCreationStrategy(lifetime);
if (metadataContext != null) {
function.setOidcMetadataContextLookupStrategy(prc -> metadataContext);
@@ -98,6 +99,7 @@ public class OIDCRPSessionCreationStrategyTest {
.claim("sid", sessionIdentifier)
.subject(subject)
.build();
+ assert claimsSet != null;
final TokenClaimsSet tokenClaimsSet = new TokenClaimsSet(claimsSet) { };
setup(Duration.ofDays(1), null, mockResponseContext(tokenClaimsSet, null), clientId);
Assert.assertNull(function.apply(new ProfileRequestContext()));
@@ -110,6 +112,7 @@ public class OIDCRPSessionCreationStrategyTest {
.claim("sid", sessionIdentifier)
.claim("root_jti", rootId)
.build();
+ assert claimsSet != null;
final TokenClaimsSet tokenClaimsSet = new TokenClaimsSet(claimsSet) { };
setup(Duration.ofDays(1), null, mockResponseContext(tokenClaimsSet, null), clientId);
Assert.assertNull(function.apply(new ProfileRequestContext()));
@@ -122,6 +125,7 @@ public class OIDCRPSessionCreationStrategyTest {
.subject(subject)
.jwtID(jwtId)
.build();
+ assert claimsSet != null;
final TokenClaimsSet tokenClaimsSet = new TokenClaimsSet(claimsSet) { };
setup(Duration.ofDays(1), null, mockResponseContext(tokenClaimsSet, null), clientId);
Assert.assertNull(function.apply(new ProfileRequestContext()));
@@ -251,6 +255,7 @@ public class OIDCRPSessionCreationStrategyTest {
.jwtID(jwtId)
.subject(subject)
.build();
+ assert claimsSet != null;
return new TokenClaimsSet(claimsSet) { };
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AbstractOIDCUserInfoResponseActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AbstractOIDCUserInfoResponseActionTest.java
index 253ac4e9..fcfef020 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AbstractOIDCUserInfoResponseActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AbstractOIDCUserInfoResponseActionTest.java
@@ -45,6 +45,7 @@ public class AbstractOIDCUserInfoResponseActionTest {
private ProfileRequestContext prc;
+ @SuppressWarnings("null")
@BeforeMethod
protected void setUp() throws Exception {
action = new MockOIDCUserInfoResponseAction();
@@ -55,7 +56,7 @@ public class AbstractOIDCUserInfoResponseActionTest {
requestCtx = new RequestContextBuilder().setInboundMessage(req).buildRequestContext();
final MessageContext msgCtx = new MessageContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- prc.getInboundMessageContext().addSubcontext(oIDCMetadataContext);
+ prc.ensureInboundMessageContext().addSubcontext(oIDCMetadataContext);
msgCtx.addSubcontext(oIDCAuthenticationResponseContext);
prc.setOutboundMessageContext(msgCtx);
action.initialize();
@@ -76,9 +77,10 @@ public class AbstractOIDCUserInfoResponseActionTest {
* Test that the action functions properly if there is no oidc response context.
*/
+ @SuppressWarnings("null")
@Test
public void testNoOidcResponseContext() throws Exception {
- prc.getOutboundMessageContext().removeSubcontext(oIDCAuthenticationResponseContext);
+ prc.ensureOutboundMessageContext().removeSubcontext(oIDCAuthenticationResponseContext);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, EventIds.INVALID_MSG_CTX);
}
@@ -87,9 +89,10 @@ public class AbstractOIDCUserInfoResponseActionTest {
* Test that the action functions properly in success case.
*/
+ @SuppressWarnings("null")
@Test
public void testNoMetadataContext() throws Exception {
- prc.getInboundMessageContext().removeSubcontext(oIDCMetadataContext);
+ prc.ensureInboundMessageContext().removeSubcontext(oIDCMetadataContext);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, EventIds.INVALID_MSG_CTX);
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AddUserInfoShellTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AddUserInfoShellTest.java
index a127dcb3..1a3f51f3 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AddUserInfoShellTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/AddUserInfoShellTest.java
@@ -20,7 +20,6 @@ import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.logic.ConstraintViolationException;
import org.springframework.webflow.execution.Event;
import org.testng.Assert;
@@ -28,6 +27,8 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.jose.JWSAlgorithm;
+import com.nimbusds.openid.connect.sdk.claims.UserInfo;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
/** {@link AddUserInfoShell} unit test. */
public class AddUserInfoShellTest extends BaseOIDCResponseActionTest {
@@ -48,9 +49,12 @@ public class AddUserInfoShellTest extends BaseOIDCResponseActionTest {
public void testSuccess() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(respCtx.getUserInfo().getClaim("sub"), subject);
- Assert.assertNull(respCtx.getUserInfo().getClaim("aud"));
- Assert.assertNull(respCtx.getUserInfo().getIssuer());
+ assert respCtx != null;
+ final UserInfo userInfo = respCtx.getUserInfo();
+ assert userInfo != null;
+ Assert.assertEquals(userInfo.getClaim("sub"), subject);
+ Assert.assertNull(userInfo.getClaim("aud"));
+ Assert.assertNull(userInfo.getIssuer());
}
/**
@@ -58,12 +62,18 @@ public class AddUserInfoShellTest extends BaseOIDCResponseActionTest {
*/
@Test
public void testSuccessForSigned() {
- metadataCtx.getClientInformation().getOIDCMetadata().setUserInfoJWSAlg(JWSAlgorithm.HS256);
+ assert metadataCtx != null;
+ final OIDCClientInformation clientInformation = metadataCtx.getClientInformation();
+ assert clientInformation != null;
+ clientInformation.getOIDCMetadata().setUserInfoJWSAlg(JWSAlgorithm.HS256);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(respCtx.getUserInfo().getClaim("sub"), subject);
- Assert.assertNotNull(respCtx.getUserInfo().getClaim("sub"));
- Assert.assertNotNull(respCtx.getUserInfo().getIssuer());
+ assert respCtx != null;
+ final UserInfo userInfo = respCtx.getUserInfo();
+ assert userInfo != null;
+ Assert.assertEquals(userInfo.getClaim("sub"), subject);
+ Assert.assertNotNull(userInfo.getClaim("sub"));
+ Assert.assertNotNull(userInfo.getIssuer());
}
/**
@@ -75,26 +85,4 @@ public class AddUserInfoShellTest extends BaseOIDCResponseActionTest {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_RELYING_PARTY_CTX);
}
-
- /** Test setting null stategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullIssuerLookupStrategy() {
- action = new AddUserInfoShell();
- action.setIssuerLookupStrategy(null);
- }
-
- /** Test setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNullRelyingPartyContextLookupStrategy() {
- action = new AddUserInfoShell();
- action.setRelyingPartyContextLookupStrategy(null);
- }
-
- /** Test setting null strategy. */
- @Test(expectedExceptions = ConstraintViolationException.class)
- public void testNulltUserInfoSigningAlgLookupStrategy() {
- action = new AddUserInfoShell();
- action.setUserInfoSigningAlgLookupStrategy(null);
- }
-
}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/FormOutboundUserInfoResponseMessageTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/FormOutboundUserInfoResponseMessageTest.java
index 1cd99332..737fdbfa 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/FormOutboundUserInfoResponseMessageTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/FormOutboundUserInfoResponseMessageTest.java
@@ -51,11 +51,16 @@ public class FormOutboundUserInfoResponseMessageTest extends BaseOIDCResponseAct
throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- UserInfoResponse resp = (UserInfoResponse) ((MessageContext) respCtx.getParent()).getMessage();
- Assert.assertNotNull(resp);
- // a signed jwt
- Assert.assertNotNull(resp.toSuccessResponse().getUserInfoJWT());
- Assert.assertNull(resp.toSuccessResponse().getUserInfo());
+ if (respCtx.getParent() instanceof MessageContext messageContext) {
+ if (messageContext.getMessage() instanceof UserInfoResponse userInfoResponse) {
+ Assert.assertNotNull(userInfoResponse.toSuccessResponse().getUserInfoJWT());
+ Assert.assertNull(userInfoResponse.toSuccessResponse().getUserInfo());
+ } else {
+ Assert.fail();
+ }
+ } else {
+ Assert.fail();
+ }
}
/**
@@ -67,11 +72,16 @@ public class FormOutboundUserInfoResponseMessageTest extends BaseOIDCResponseAct
respCtx.setProcessedToken(null);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- UserInfoResponse resp = (UserInfoResponse) ((MessageContext) respCtx.getParent()).getMessage();
- Assert.assertNotNull(resp);
- // a plain text response
- Assert.assertNotNull(resp.toSuccessResponse().getUserInfo());
- Assert.assertNull(resp.toSuccessResponse().getUserInfoJWT());
+ if (respCtx.getParent() instanceof MessageContext messageContext) {
+ if (messageContext.getMessage() instanceof UserInfoResponse userInfoResponse) {
+ Assert.assertNotNull(userInfoResponse.toSuccessResponse().getUserInfo());
+ Assert.assertNull(userInfoResponse.toSuccessResponse().getUserInfoJWT());
+ } else {
+ Assert.fail();
+ }
+ } else {
+ Assert.fail();
+ }
}
/**
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ParseAccessTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ParseAccessTokenTest.java
index ef1fe4b9..b8dbfb67 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ParseAccessTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ParseAccessTokenTest.java
@@ -21,6 +21,7 @@ import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.oidc.profile.core.OidcEventIds;
import net.shibboleth.oidc.security.credential.BasicJWKCredential;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
@@ -34,7 +35,6 @@ import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.time.Instant;
-import java.util.Collections;
import org.opensaml.security.credential.Credential;
import org.opensaml.security.credential.CredentialResolver;
@@ -91,9 +91,12 @@ public class ParseAccessTokenTest extends BaseOIDCResponseActionTest {
action.setCredentialResolver(new CredentialResolver() {
public Iterable<Credential> resolve(CriteriaSet criteria) throws ResolverException {
- return Collections.singletonList(resolveSingle(criteria));
+ final Credential credential = resolveSingle(criteria);
+ assert credential != null;
+ return CollectionSupport.singletonList(credential);
}
+ @SuppressWarnings("null")
public Credential resolveSingle(CriteriaSet criteria) throws ResolverException {
final BasicJWKCredential cred = new BasicJWKCredential();
cred.setPublicKey(rsaPublicKey);
@@ -113,6 +116,7 @@ public class ParseAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws URISyntaxException
* @throws DataSealerException
*/
+ @SuppressWarnings("null")
@Test
public void testSuccess()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException {
@@ -145,6 +149,7 @@ public class ParseAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws DataSealerException
* @throws JOSEException
*/
+ @SuppressWarnings("null")
@Test
public void testJWT()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException, JOSEException {
@@ -212,6 +217,7 @@ public class ParseAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws URISyntaxException
* @throws DataSealerException
*/
+ @SuppressWarnings("null")
@Test
public void testFailsNotAccessToken()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException {
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ValidateAccessTokenTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ValidateAccessTokenTest.java
index 2651cbc4..fb32d395 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ValidateAccessTokenTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/userinfo/profile/impl/ValidateAccessTokenTest.java
@@ -67,6 +67,7 @@ public class ValidateAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws URISyntaxException
* @throws DataSealerException
*/
+ @SuppressWarnings("null")
@Test
public void testSuccess()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException {
@@ -96,6 +97,7 @@ public class ValidateAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws URISyntaxException
* @throws DataSealerException
*/
+ @SuppressWarnings("null")
@Test
public void testFailsAudience()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException {
@@ -126,6 +128,7 @@ public class ValidateAccessTokenTest extends BaseOIDCResponseActionTest {
* @throws URISyntaxException
* @throws DataSealerException
*/
+ @SuppressWarnings("null")
@Test
public void testFailsExpired()
throws NoSuchAlgorithmException, ComponentInitializationException, URISyntaxException, DataSealerException {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list