@Test(expected = IllegalStateException.class) public void testExchangeCodeMultipleInvocation() throws Exception { final OidcService service = getServiceWithOidcSupport(); service.exchangeAuthorizationCode(TEST_REQUEST_IDENTIFIER, getAuthorizationCodeGrant()); service.exchangeAuthorizationCode(TEST_REQUEST_IDENTIFIER, getAuthorizationCodeGrant()); }
public RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant) throws IOException { if (!isOidcEnabled()) { throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED); } final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier); final OIDCTokens oidcTokens = exchangeOIDCToken(authorizationGrant); final RefreshToken oidcRefreshToken = oidcTokens.getRefreshToken(); final String nifiJwt = getJwtFromOIDCTokens(oidcTokens); try { synchronized (jwtLookupForCompletedRequests) { final String cachedJwt = jwtLookupForCompletedRequests.get(oidcRequestIdentifierKey, () -> nifiJwt); if (!timeConstantEqualityCheck(nifiJwt, cachedJwt)) { throw new IllegalStateException("An existing login request is already in progress."); } } return oidcRefreshToken; } catch (final ExecutionException e) { throw new IllegalStateException("Unable to store the login authentication token."); } }
OidcService { public RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant) throws IOException { if (!isOidcEnabled()) { throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED); } final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier); final OIDCTokens oidcTokens = exchangeOIDCToken(authorizationGrant); final RefreshToken oidcRefreshToken = oidcTokens.getRefreshToken(); final String nifiJwt = getJwtFromOIDCTokens(oidcTokens); try { synchronized (jwtLookupForCompletedRequests) { final String cachedJwt = jwtLookupForCompletedRequests.get(oidcRequestIdentifierKey, () -> nifiJwt); if (!timeConstantEqualityCheck(nifiJwt, cachedJwt)) { throw new IllegalStateException("An existing login request is already in progress."); } } return oidcRefreshToken; } catch (final ExecutionException e) { throw new IllegalStateException("Unable to store the login authentication token."); } } }
OidcService { public RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant) throws IOException { if (!isOidcEnabled()) { throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED); } final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier); final OIDCTokens oidcTokens = exchangeOIDCToken(authorizationGrant); final RefreshToken oidcRefreshToken = oidcTokens.getRefreshToken(); final String nifiJwt = getJwtFromOIDCTokens(oidcTokens); try { synchronized (jwtLookupForCompletedRequests) { final String cachedJwt = jwtLookupForCompletedRequests.get(oidcRequestIdentifierKey, () -> nifiJwt); if (!timeConstantEqualityCheck(nifiJwt, cachedJwt)) { throw new IllegalStateException("An existing login request is already in progress."); } } return oidcRefreshToken; } catch (final ExecutionException e) { throw new IllegalStateException("Unable to store the login authentication token."); } } OidcService(final OidcIdentityProvider identityProvider);  OidcService(final OidcIdentityProvider identityProvider, final int duration, final TimeUnit units); }
OidcService { public RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant) throws IOException { if (!isOidcEnabled()) { throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED); } final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier); final OIDCTokens oidcTokens = exchangeOIDCToken(authorizationGrant); final RefreshToken oidcRefreshToken = oidcTokens.getRefreshToken(); final String nifiJwt = getJwtFromOIDCTokens(oidcTokens); try { synchronized (jwtLookupForCompletedRequests) { final String cachedJwt = jwtLookupForCompletedRequests.get(oidcRequestIdentifierKey, () -> nifiJwt); if (!timeConstantEqualityCheck(nifiJwt, cachedJwt)) { throw new IllegalStateException("An existing login request is already in progress."); } } return oidcRefreshToken; } catch (final ExecutionException e) { throw new IllegalStateException("Unable to store the login authentication token."); } } OidcService(final OidcIdentityProvider identityProvider);  OidcService(final OidcIdentityProvider identityProvider, final int duration, final TimeUnit units); boolean isOidcEnabled(); URI getAuthorizationEndpoint(); URI getEndSessionEndpoint(); Scope getScope(); String getClientId(); State createState(final String oidcRequestIdentifier); boolean isStateValid(final String oidcRequestIdentifier, final State proposedState); RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant); String getJwtFromOIDCTokens(OIDCTokens oidcTokens); OIDCTokens exchangeOIDCToken(AuthorizationGrant authorizationGrant); OIDCTokenResponse exchangeOIDCToken(RefreshToken refreshToken); String getJwt(final String oidcRequestIdentifier); }
OidcService { public RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant) throws IOException { if (!isOidcEnabled()) { throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED); } final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier); final OIDCTokens oidcTokens = exchangeOIDCToken(authorizationGrant); final RefreshToken oidcRefreshToken = oidcTokens.getRefreshToken(); final String nifiJwt = getJwtFromOIDCTokens(oidcTokens); try { synchronized (jwtLookupForCompletedRequests) { final String cachedJwt = jwtLookupForCompletedRequests.get(oidcRequestIdentifierKey, () -> nifiJwt); if (!timeConstantEqualityCheck(nifiJwt, cachedJwt)) { throw new IllegalStateException("An existing login request is already in progress."); } } return oidcRefreshToken; } catch (final ExecutionException e) { throw new IllegalStateException("Unable to store the login authentication token."); } } OidcService(final OidcIdentityProvider identityProvider);  OidcService(final OidcIdentityProvider identityProvider, final int duration, final TimeUnit units); boolean isOidcEnabled(); URI getAuthorizationEndpoint(); URI getEndSessionEndpoint(); Scope getScope(); String getClientId(); State createState(final String oidcRequestIdentifier); boolean isStateValid(final String oidcRequestIdentifier, final State proposedState); RefreshToken exchangeAuthorizationCode(final String oidcRequestIdentifier, final AuthorizationGrant authorizationGrant); String getJwtFromOIDCTokens(OIDCTokens oidcTokens); OIDCTokens exchangeOIDCToken(AuthorizationGrant authorizationGrant); OIDCTokenResponse exchangeOIDCToken(RefreshToken refreshToken); String getJwt(final String oidcRequestIdentifier);  }