OAuthAuthenticateCallbackHandler implements AuthenticateCallbackHandler { @Override public void configure(Map<String, ?> configs, String saslMechanism, List<AppConfigurationEntry> jaasConfigEntries) { log.debug("Starting to configure OAuth authentication callback handler."); log.debug("Validate method parameters."); Objects.requireNonNull(configs); Objects.requireNonNull(saslMechanism); Objects.requireNonNull(jaasConfigEntries); String errMsg; if (OAuthBearerLoginModule.OAUTHBEARER_MECHANISM.equals(saslMechanism)) { if (jaasConfigEntries.size() == 1 && jaasConfigEntries.get(0) != null) { this.moduleOptions = Collections.unmodifiableMap( (Map<String, String>) jaasConfigEntries.get(0).getOptions()); this.oauthService.setOAuthConfiguration(moduleOptions); configured = true; } else { errMsg = String.format( "Must supply exactly 1 non-null JAAS mechanism configuration (size was %d)", jaasConfigEntries.size()); log.error(errMsg); } } else { errMsg = String.format("Unexpected SASL mechanism: %s", saslMechanism); log.error(errMsg); } } OAuthAuthenticateCallbackHandler(OAuthService oauthService, Class callBackHandlerClass); @Override void configure(Map<String, ?> configs, String saslMechanism, List<AppConfigurationEntry> jaasConfigEntries); @Override void handle(Callback[] callbacks); @Override void close();  }
@Test(expected = NullPointerException.class) public void configure_NullConfigsParameter_ThrowsNullPointerException() { OAuthService oauthService = new OAuthServiceImpl(); TestOAuthAuthenticateCallbackHandler callbackHandler = new TestOAuthAuthenticateCallbackHandler( oauthService ); callbackHandler.configure(null, null, null); }
@Test(expected = NullPointerException.class) public void configure_NullSaslMechanismParameter_ThrowsNullPointerException() { OAuthService oauthService = new OAuthServiceImpl(); TestOAuthAuthenticateCallbackHandler callbackHandler = new TestOAuthAuthenticateCallbackHandler( oauthService ); Map<String, ?> configs = new HashMap<>(); callbackHandler.configure(configs, null, null); }
@Test(expected = NullPointerException.class) public void configure_NullJaasConfigEntriesParameter_ThrowsNullPointerException() { OAuthService oauthService = new OAuthServiceImpl(); TestOAuthAuthenticateCallbackHandler callbackHandler = new TestOAuthAuthenticateCallbackHandler( oauthService ); Map<String, ?> configs = new HashMap<>(); String saslMechanism = "Test"; callbackHandler.configure(configs, saslMechanism, null); }