@Test public void retrieveAccessTokenViaPasswordGrant_twoDistinctRequests_onlyTwoRequestCalls() throws OAuth2ServiceException { retrieveAccessTokenViaPasswordGrant("user1"); retrieveAccessTokenViaPasswordGrant("user2"); retrieveAccessTokenViaPasswordGrant("user1"); assertThat(cut.tokenRequestCallCount).isEqualTo(2); }
@Override public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException { assertNotNull(tokenEndpoint, "tokenEndpoint is required"); assertNotNull(clientCredentials, "clientCredentials are required"); assertNotNull(username, "username is required"); assertNotNull(password, "password is required"); Map<String, String> parameters = new RequestParameterBuilder() .withGrantType(GRANT_TYPE_PASSWORD) .withUsername(username) .withPassword(password) .withClientCredentials(clientCredentials) .withOptionalParameters(optionalParameters) .buildAsMap(); HttpHeaders headers = HttpHeadersFactory.createWithoutAuthorizationHeader(); return getOAuth2TokenResponse(tokenEndpoint, headers, parameters, subdomain, disableCacheForRequest); }
AbstractOAuth2TokenService implements OAuth2TokenService, Cacheable { @Override public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException { assertNotNull(tokenEndpoint, "tokenEndpoint is required"); assertNotNull(clientCredentials, "clientCredentials are required"); assertNotNull(username, "username is required"); assertNotNull(password, "password is required"); Map<String, String> parameters = new RequestParameterBuilder() .withGrantType(GRANT_TYPE_PASSWORD) .withUsername(username) .withPassword(password) .withClientCredentials(clientCredentials) .withOptionalParameters(optionalParameters) .buildAsMap(); HttpHeaders headers = HttpHeadersFactory.createWithoutAuthorizationHeader(); return getOAuth2TokenResponse(tokenEndpoint, headers, parameters, subdomain, disableCacheForRequest); } }
AbstractOAuth2TokenService implements OAuth2TokenService, Cacheable { @Override public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException { assertNotNull(tokenEndpoint, "tokenEndpoint is required"); assertNotNull(clientCredentials, "clientCredentials are required"); assertNotNull(username, "username is required"); assertNotNull(password, "password is required"); Map<String, String> parameters = new RequestParameterBuilder() .withGrantType(GRANT_TYPE_PASSWORD) .withUsername(username) .withPassword(password) .withClientCredentials(clientCredentials) .withOptionalParameters(optionalParameters) .buildAsMap(); HttpHeaders headers = HttpHeadersFactory.createWithoutAuthorizationHeader(); return getOAuth2TokenResponse(tokenEndpoint, headers, parameters, subdomain, disableCacheForRequest); } AbstractOAuth2TokenService();  AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration);   AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration, Ticker cacheTicker,
			boolean sameThreadCache); }
AbstractOAuth2TokenService implements OAuth2TokenService, Cacheable { @Override public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException { assertNotNull(tokenEndpoint, "tokenEndpoint is required"); assertNotNull(clientCredentials, "clientCredentials are required"); assertNotNull(username, "username is required"); assertNotNull(password, "password is required"); Map<String, String> parameters = new RequestParameterBuilder() .withGrantType(GRANT_TYPE_PASSWORD) .withUsername(username) .withPassword(password) .withClientCredentials(clientCredentials) .withOptionalParameters(optionalParameters) .buildAsMap(); HttpHeaders headers = HttpHeadersFactory.createWithoutAuthorizationHeader(); return getOAuth2TokenResponse(tokenEndpoint, headers, parameters, subdomain, disableCacheForRequest); } AbstractOAuth2TokenService();  AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration);   AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration, Ticker cacheTicker,
			boolean sameThreadCache); @Override void clearCache(); @Override @Nonnull TokenCacheConfiguration getCacheConfiguration(); @Override OAuth2TokenResponse retrieveAccessTokenViaClientCredentialsGrant(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials,
			@Nullable String subdomain, @Nullable Map<String, String> optionalParameters,
			boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaUserTokenGrant(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials, @Nonnull String token, @Nullable String subdomain,
			@Nullable Map<String, String> optionalParameters); @Override OAuth2TokenResponse retrieveAccessTokenViaRefreshToken(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials,
			@Nonnull String refreshToken, String subdomain, boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint,
			@Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password,
			@Nullable String subdomain, @Nullable Map<String, String> optionalParameters,
			boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint,
			ClientCredentials clientCredentials, String token, @Nullable String subdomain,
			@Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest); @Override Object getCacheStatistics(); }
AbstractOAuth2TokenService implements OAuth2TokenService, Cacheable { @Override public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException { assertNotNull(tokenEndpoint, "tokenEndpoint is required"); assertNotNull(clientCredentials, "clientCredentials are required"); assertNotNull(username, "username is required"); assertNotNull(password, "password is required"); Map<String, String> parameters = new RequestParameterBuilder() .withGrantType(GRANT_TYPE_PASSWORD) .withUsername(username) .withPassword(password) .withClientCredentials(clientCredentials) .withOptionalParameters(optionalParameters) .buildAsMap(); HttpHeaders headers = HttpHeadersFactory.createWithoutAuthorizationHeader(); return getOAuth2TokenResponse(tokenEndpoint, headers, parameters, subdomain, disableCacheForRequest); } AbstractOAuth2TokenService();  AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration);   AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration, Ticker cacheTicker,
			boolean sameThreadCache); @Override void clearCache(); @Override @Nonnull TokenCacheConfiguration getCacheConfiguration(); @Override OAuth2TokenResponse retrieveAccessTokenViaClientCredentialsGrant(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials,
			@Nullable String subdomain, @Nullable Map<String, String> optionalParameters,
			boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaUserTokenGrant(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials, @Nonnull String token, @Nullable String subdomain,
			@Nullable Map<String, String> optionalParameters); @Override OAuth2TokenResponse retrieveAccessTokenViaRefreshToken(@Nonnull URI tokenEndpointUri,
			@Nonnull ClientCredentials clientCredentials,
			@Nonnull String refreshToken, String subdomain, boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint,
			@Nonnull ClientCredentials clientCredentials, @Nonnull String username, @Nonnull String password,
			@Nullable String subdomain, @Nullable Map<String, String> optionalParameters,
			boolean disableCacheForRequest); @Override OAuth2TokenResponse retrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint,
			ClientCredentials clientCredentials, String token, @Nullable String subdomain,
			@Nullable Map<String, String> optionalParameters, boolean disableCacheForRequest); @Override Object getCacheStatistics();  }