Class OIDCRPFlowTest
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.springframework.webflow.test.execution.AbstractFlowExecutionTests
-
- org.springframework.webflow.test.execution.AbstractExternalizedFlowExecutionTests
-
- net.shibboleth.idp.plugin.authn.test.spring.CustomAbstractXmlFlowExecutionTests
-
- net.shibboleth.idp.plugin.authn.test.flow.AbstractAuthnXmlFlowExecutionTests
-
- net.shibboleth.idp.plugin.authn.oidc.rp.impl.OIDCRPFlowTest
-
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
OIDCRPFlowFromAuthenticationResponseTest,OIDCRPFlowPreRedirectTest
public class OIDCRPFlowTest extends AbstractAuthnXmlFlowExecutionTests
Abstract class to test the OIDC relying party flow.Note, the profile configuration which normal exists in oidc-commons i.e. inside the relying-party/postconfig.xml, is in the test resources tree in the /conf directory.
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringCLIENT_IDThe client_id.protected static StringCLIENT_SECRETThe client_secret.protected static StringFLOWPath to the flow to be tested.protected Map<String,String>flowResourcesMap of flow resources that support building the flow to test.protected static ClassPathResourceGOOD_PROVIDER_CONFIGURATION_INFOExample of good provider metadata.protected static ClassPathResourceGOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECTExample of good provider metadata.protected static ClassPathResourceGOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_ENCRYPTExample of good provider metadata.protected static ClassPathResourceGOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_HS512_SIGExample of good provider metadata.protected static ClassPathResourceGOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_RSA256_SIGExample of good provider metadata.private org.slf4j.LoggerlogClass logger.protected static StringOP_ISSUER_IDThe Default OP Issuer to use.protected static StringOP_ISSUER_ID_REQUESTOBJECT_TRUEThe OP Issuer to use with an override in the config to use the request object authn param.protected static StringOP_ISSUER_ID_REQUESTOBJECT_TRUE_ENCRYPTThe OP Issuer to use with an override in the config to use the request object authn param which is to be encrypted.protected static StringOP_ISSUER_ID_REQUESTOBJECT_TRUE_HS512_SIGThe OP Issuer to use with an override in the config to use the request object authn param signed using HS512.protected static StringOP_ISSUER_ID_REQUESTOBJECT_TRUE_RSA256_SIGThe OP Issuer to use with an override in the config to use the request object authn param signed using RS256.protected static StringREDIRECT_URI_OVERRIDEA redirect_uri override.protected static ClassPathResourceREMOTE_JWKSET_RESPONSEA JWKSet resource.protected List<Flow>subflowsList of mocked subflows.-
Fields inherited from class net.shibboleth.idp.plugin.authn.test.flow.AbstractAuthnXmlFlowExecutionTests
externalContext, mockRequest, mockResponse
-
-
Constructor Summary
Constructors Constructor Description OIDCRPFlowTest()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddACRAndAMRFunctions(ProfileRequestContext prc)protected voidassertEndUserClaimsVerified(ProfileRequestContext nestedPrc)Assert end-user claims exist, and the claims are accurate.protected voidassertFlowEndedInErrorConditions(ProfileRequestContext rootPrc)Assert the conditions expected when the flow has ended in error.protected voidassertFlowEndedInErrorConditions(ProfileRequestContext rootPrc, String error)Assert the conditions expected when the flow has ended in error.protected voidassertIdTokenSignatureAndClaimsVerified(ProfileRequestContext nestedPrc)Assert the id_token exists, has had its signature verified, and the claims contained in the token are accurate.protected voidassertPlainJSONObjectUserInfoToken(ProfileRequestContext nestedPrc)Assert a plain JSON object user info response.protected voidassertPreviousEventContextError(ProfileRequestContext rootPrc, String error)Assert that a previous event context exists and that the event recorded is a string with the value given.protected ProfileRequestContextassertStandardAuthenticationRedirectFlowSuccessConditions(ProfileRequestContext rootPrc)Assert the basic set of conditions expected when the authentication flow is at the authentication redirect.protected ProfileRequestContextassertStandardEndFlowSuccessConditions(ProfileRequestContext rootPrc)Assert the basic set of conditions expected at the end of the entire authentication flow.protected voidassertStandardEndUserClaimsSuccessCondition(com.nimbusds.openid.connect.sdk.claims.ClaimsSet claims)Assert the standard set of claims exist in the end-user context claimsset.protected voidassertStandardIdTokenClaimsSuccessCondition(com.nimbusds.jwt.JWTClaimsSet claims)Assert the standard set of claims exist in the id_token's claimsset.protected voidassertStandardRequestObjectSuccessConditions(com.nimbusds.openid.connect.sdk.claims.ClaimsSet roClaims, String audience)Assert the claims (belonging to the request object) have the correct set of basic claims.protected voidassertUserInfoTokenSignatureVerified(ProfileRequestContext nestedPrc)Assert the user info response JWT exists, and has had its signature verified.protected ProfileRequestContextbuildProfileRequestContext(String flowId, boolean forceAuthn, boolean addC14Context)Build aProfileRequestContextby configuring a suitable context tree e.g.protected net.shibboleth.oidc.profile.core.OIDCAuthenticationRequestcreateAuthenticationRequest()Create an OIDC authentication request.protected com.nimbusds.openid.connect.sdk.AuthenticationResponsecreateAuthenticationResponse()Create an authentication response.protected net.shibboleth.oidc.profile.config.JSONSecurityConfigurationcreateBasicSecurityConfigAndValidationParams()Create a basic security configuration, which can be overriden per test if required.protected net.shibboleth.idp.plugin.authn.oidc.rp.context.OAuth2ClientContextcreateOAuth2ClientContext(String clientId, URI redirectOverride)protected net.shibboleth.oidc.profile.messaging.context.OIDCPeerEntityContextcreatePeerContext()Create anOIDCPeerEntityContext.protected okhttp3.mockwebserver.MockWebServercreateSimpleServer()Create a running server that mimics responses from an OpenID Connect provider.protected net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfigurationgetRelyingPartyProfileConfig(ProfileRequestContext prc)Return the Profile configuration from the relying party context.protected ProfileRequestContextpopulateBasicContextTreeFromAuthnResponse(FlowExecutionImpl flowExecution)protected voidregisterMockBeanDefinitions(MockFlowBuilderContext builderContext)Register Shibboleth IdP requred mock beans that are not necessary to configure for authentication testing but are required for authentication flows to proceed.protected voidregisterMockPropertySource(MockFlowBuilderContext builderContext)-
Methods inherited from class net.shibboleth.idp.plugin.authn.test.flow.AbstractAuthnXmlFlowExecutionTests
addBeanDefinition, addBeanSingleton, addHttpBasicAuthHeader, configureFlowBuilderContext, getModelResources, getResource, loadBeanDefinitionsFromXmlFile, setFlowModelResources, setFlowPath, setMockProperties, setSubflows, setUp
-
Methods inherited from class net.shibboleth.idp.plugin.authn.test.spring.CustomAbstractXmlFlowExecutionTests
createFlowBuilder, registerMockFlowBeans
-
Methods inherited from class org.springframework.webflow.test.execution.AbstractExternalizedFlowExecutionTests
buildFlow, createResourceLoader, getFlow, getFlowDefinition, getFlowDefinitionRegistry, getResourceFactory, isCacheFlowDefinition, setCacheFlowDefinition, setFlowExecutionAttributes, setFlowExecutionListener, setFlowExecutionListeners
-
Methods inherited from class org.springframework.webflow.test.execution.AbstractFlowExecutionTests
assertActiveFlowEquals, assertCurrentStateEquals, assertFlowExecutionActive, assertFlowExecutionEnded, assertFlowExecutionOutcomeEquals, assertResponseWrittenEquals, createFlowExecutionFactory, getConversationAttribute, getConversationScope, getFlowAttribute, getFlowExecution, getFlowExecutionFactory, getFlowExecutionOutcome, getFlowScope, getRequiredConversationAttribute, getRequiredConversationAttribute, getRequiredFlowAttribute, getRequiredFlowAttribute, getRequiredViewAttribute, getRequiredViewAttribute, getViewAttribute, getViewScope, resumeFlow, setCurrentState, startFlow, startFlow, updateFlowExecution
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, tearDown, toString
-
-
-
-
Field Detail
-
OP_ISSUER_ID
protected static final String OP_ISSUER_ID
The Default OP Issuer to use.- See Also:
- Constant Field Values
-
OP_ISSUER_ID_REQUESTOBJECT_TRUE
protected static final String OP_ISSUER_ID_REQUESTOBJECT_TRUE
The OP Issuer to use with an override in the config to use the request object authn param.- See Also:
- Constant Field Values
-
OP_ISSUER_ID_REQUESTOBJECT_TRUE_RSA256_SIG
protected static final String OP_ISSUER_ID_REQUESTOBJECT_TRUE_RSA256_SIG
The OP Issuer to use with an override in the config to use the request object authn param signed using RS256.- See Also:
- Constant Field Values
-
OP_ISSUER_ID_REQUESTOBJECT_TRUE_HS512_SIG
protected static final String OP_ISSUER_ID_REQUESTOBJECT_TRUE_HS512_SIG
The OP Issuer to use with an override in the config to use the request object authn param signed using HS512.- See Also:
- Constant Field Values
-
OP_ISSUER_ID_REQUESTOBJECT_TRUE_ENCRYPT
protected static final String OP_ISSUER_ID_REQUESTOBJECT_TRUE_ENCRYPT
The OP Issuer to use with an override in the config to use the request object authn param which is to be encrypted.- See Also:
- Constant Field Values
-
REDIRECT_URI_OVERRIDE
protected static final String REDIRECT_URI_OVERRIDE
A redirect_uri override.- See Also:
- Constant Field Values
-
CLIENT_ID
protected static final String CLIENT_ID
The client_id.- See Also:
- Constant Field Values
-
CLIENT_SECRET
protected static final String CLIENT_SECRET
The client_secret.- See Also:
- Constant Field Values
-
REMOTE_JWKSET_RESPONSE
protected static final ClassPathResource REMOTE_JWKSET_RESPONSE
A JWKSet resource.
-
GOOD_PROVIDER_CONFIGURATION_INFO
protected static final ClassPathResource GOOD_PROVIDER_CONFIGURATION_INFO
Example of good provider metadata. Endpoints are localhost to support the mock server that is started.
-
GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT
protected static final ClassPathResource GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT
Example of good provider metadata. Endpoints are localhost to support the mock server that is started. This OP supports the use of the request object.
-
GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_ENCRYPT
protected static final ClassPathResource GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_ENCRYPT
Example of good provider metadata. Endpoints are localhost to support the mock server that is started. This OP supports the use of the request object.
-
GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_RSA256_SIG
protected static final ClassPathResource GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_RSA256_SIG
Example of good provider metadata. Only supports RS256 signature alg for request object.
-
GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_HS512_SIG
protected static final ClassPathResource GOOD_PROVIDER_CONFIGURATION_INFO_USE_REQUEST_OBJECT_HS512_SIG
Example of good provider metadata. Only supports HS512 signature alg for request object.
-
FLOW
@Nonnull protected static final String FLOW
Path to the flow to be tested.- See Also:
- Constant Field Values
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
subflows
@Nonnull @NonnullElements @Unmodifiable protected final List<Flow> subflows
List of mocked subflows.
-
flowResources
@Nonnull @NonnullElements @Unmodifiable protected final Map<String,String> flowResources
Map of flow resources that support building the flow to test. These are only for parent flows, not subflows.Note, these are all local to the RP, as copied from the IdP. These might need updating in the futre.
-
-
Method Detail
-
registerMockPropertySource
protected void registerMockPropertySource(@Nonnull MockFlowBuilderContext builderContext)Description copied from class:AbstractAuthnXmlFlowExecutionTestsRegister aMockPropertySourcewith theEnvironmentof the current flow buildersApplicationContext. Set properties required to run an authentication flow.- Overrides:
registerMockPropertySourcein classAbstractAuthnXmlFlowExecutionTests- Parameters:
builderContext- the builder context to attach the mock property source to.
-
registerMockBeanDefinitions
protected void registerMockBeanDefinitions(@Nonnull MockFlowBuilderContext builderContext)Description copied from class:AbstractAuthnXmlFlowExecutionTestsRegister Shibboleth IdP requred mock beans that are not necessary to configure for authentication testing but are required for authentication flows to proceed.Project specific tests should override this method, making sure to also call super().
- Overrides:
registerMockBeanDefinitionsin classAbstractAuthnXmlFlowExecutionTests- Parameters:
builderContext- the context used to register the beans.
-
createSimpleServer
protected okhttp3.mockwebserver.MockWebServer createSimpleServer() throws UnknownHostExceptionCreate a running server that mimics responses from an OpenID Connect provider. Creates a new self-signed certificate.- Returns:
- the simple server.
- Throws:
UnknownHostException- on error.
-
createPeerContext
protected net.shibboleth.oidc.profile.messaging.context.OIDCPeerEntityContext createPeerContext() throws com.nimbusds.oauth2.sdk.ParseExceptionCreate anOIDCPeerEntityContext.- Returns:
- the peer entity context.
- Throws:
com.nimbusds.oauth2.sdk.ParseException- on error.
-
createAuthenticationRequest
protected net.shibboleth.oidc.profile.core.OIDCAuthenticationRequest createAuthenticationRequest()
Create an OIDC authentication request.- Returns:
- the authentication request.
-
createOAuth2ClientContext
protected net.shibboleth.idp.plugin.authn.oidc.rp.context.OAuth2ClientContext createOAuth2ClientContext(@Nonnull String clientId, @Nullable URI redirectOverride)
-
createBasicSecurityConfigAndValidationParams
protected net.shibboleth.oidc.profile.config.JSONSecurityConfiguration createBasicSecurityConfigAndValidationParams()
Create a basic security configuration, which can be overriden per test if required.- Returns:
- the basic security configuration.
-
createAuthenticationResponse
protected com.nimbusds.openid.connect.sdk.AuthenticationResponse createAuthenticationResponse() throws ExceptionCreate an authentication response.- Returns:
- the OIDC authentication response.
- Throws:
Exception- on error.
-
buildProfileRequestContext
@Nonnull protected ProfileRequestContext buildProfileRequestContext(@Nonnull String flowId, @Nonnull boolean forceAuthn, @Nonnull boolean addC14Context)
Description copied from class:AbstractAuthnXmlFlowExecutionTestsBuild aProfileRequestContextby configuring a suitable context tree e.g. aAuthenticationContext.- Overrides:
buildProfileRequestContextin classAbstractAuthnXmlFlowExecutionTests- Parameters:
flowId- the flow identifierforceAuthn- force authenticationaddC14Context- add the c14 context, yes or no.- Returns:
- a profile request context.
-
populateBasicContextTreeFromAuthnResponse
protected ProfileRequestContext populateBasicContextTreeFromAuthnResponse(FlowExecutionImpl flowExecution) throws Exception
- Throws:
Exception
-
addACRAndAMRFunctions
protected void addACRAndAMRFunctions(@Nonnull ProfileRequestContext prc)
-
getRelyingPartyProfileConfig
protected net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfiguration getRelyingPartyProfileConfig(ProfileRequestContext prc)
Return the Profile configuration from the relying party context.- Parameters:
prc- the prc- Returns:
- the relying party configuration
-
assertStandardEndFlowSuccessConditions
protected ProfileRequestContext assertStandardEndFlowSuccessConditions(ProfileRequestContext rootPrc)
Assert the basic set of conditions expected at the end of the entire authentication flow.- Parameters:
rootPrc- the profile request context.- Returns:
- the nested profile request context to perform further checks over.
-
assertStandardAuthenticationRedirectFlowSuccessConditions
protected ProfileRequestContext assertStandardAuthenticationRedirectFlowSuccessConditions(ProfileRequestContext rootPrc)
Assert the basic set of conditions expected when the authentication flow is at the authentication redirect.- Parameters:
rootPrc- the root profile request context.- Returns:
- the nested profile request context to perform further checks over.
-
assertFlowEndedInErrorConditions
protected void assertFlowEndedInErrorConditions(@Nonnull ProfileRequestContext rootPrc, @Nonnull String error)Assert the conditions expected when the flow has ended in error. No authentication result is produced, and the previous event was an error event with the given value.- Parameters:
rootPrc- the root profile request contexterror- the error message to check.
-
assertFlowEndedInErrorConditions
protected void assertFlowEndedInErrorConditions(@Nonnull ProfileRequestContext rootPrc)Assert the conditions expected when the flow has ended in error. No authentication result is produced.- Parameters:
rootPrc- the root profile request context
-
assertStandardRequestObjectSuccessConditions
protected void assertStandardRequestObjectSuccessConditions(com.nimbusds.openid.connect.sdk.claims.ClaimsSet roClaims, String audience)Assert the claims (belonging to the request object) have the correct set of basic claims.- Parameters:
roClaims- the request object claimsaudience- the audience value to check
-
assertPreviousEventContextError
protected void assertPreviousEventContextError(@Nonnull ProfileRequestContext rootPrc, @Nonnull String error)Assert that a previous event context exists and that the event recorded is a string with the value given.- Parameters:
rootPrc- the root profile request contexterror- the error event value to test
-
assertStandardIdTokenClaimsSuccessCondition
protected void assertStandardIdTokenClaimsSuccessCondition(com.nimbusds.jwt.JWTClaimsSet claims)
Assert the standard set of claims exist in the id_token's claimsset.- Parameters:
claims- the claims to test.
-
assertStandardEndUserClaimsSuccessCondition
protected void assertStandardEndUserClaimsSuccessCondition(com.nimbusds.openid.connect.sdk.claims.ClaimsSet claims)
Assert the standard set of claims exist in the end-user context claimsset.- Parameters:
claims- the claims to test.
-
assertIdTokenSignatureAndClaimsVerified
protected void assertIdTokenSignatureAndClaimsVerified(ProfileRequestContext nestedPrc) throws ParseException
Assert the id_token exists, has had its signature verified, and the claims contained in the token are accurate.- Parameters:
nestedPrc- the nested profile request context- Throws:
ParseException- on error
-
assertUserInfoTokenSignatureVerified
protected void assertUserInfoTokenSignatureVerified(ProfileRequestContext nestedPrc) throws ParseException
Assert the user info response JWT exists, and has had its signature verified.- Parameters:
nestedPrc- the nested profile request context- Throws:
ParseException- on error
-
assertPlainJSONObjectUserInfoToken
protected void assertPlainJSONObjectUserInfoToken(ProfileRequestContext nestedPrc) throws ParseException
Assert a plain JSON object user info response.- Parameters:
nestedPrc- the nested profile request context- Throws:
ParseException- on error
-
assertEndUserClaimsVerified
protected void assertEndUserClaimsVerified(ProfileRequestContext nestedPrc) throws ParseException
Assert end-user claims exist, and the claims are accurate.- Parameters:
nestedPrc- the nested profile request context- Throws:
ParseException- on error
-
-