OAuthAuthenticateCallbackHandler implements AuthenticateCallbackHandler { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { log.debug("Starting to handle OAuth bearer token login callbacks."); log.debug("Check to see of the handler has been configured."); if (!isConfigured()) { String errMsg = "Callback handler not configured"; log.error(errMsg); throw new IllegalStateException(errMsg); } log.debug("Loop through all of the callbacks looking for the OAuth bearer token callbacks."); for (Callback callback : callbacks) { log.debug("Check the type of the callback."); Class callBackType = callback.getClass(); if (callBackType.equals(this.callBackHandlerClass)) { log.debug("The callback is the correct type of this handler, process the callback."); try { T oauthBearerTokenCallback = (T) callback; handleCallback(oauthBearerTokenCallback); } catch (Exception e) { String errMsg = String.format( "Error handing OAuth bearer token login callback, Message: %s", e.getMessage()); log.error(errMsg); throw new IOException(errMsg, e); } } else { String errMsg = String.format( "Callback is not a OAuthBearerTokenCallback, Type: %s", callback); log.debug(errMsg); throw new UnsupportedCallbackException(callback); } } log.debug("Finished handling OAuth bearer token login callbacks."); } 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 = IllegalStateException.class) public void handle_NotConfigured_ThrowsIllegalStateException() throws IOException, UnsupportedCallbackException { OAuthService oauthService = new OAuthServiceImpl(); TestOAuthAuthenticateCallbackHandler callbackHandler = new TestOAuthAuthenticateCallbackHandler( oauthService, false, false ); Map<String, ?> configs = new HashMap<>(); String saslMechanism = "Test"; List<AppConfigurationEntry> jaasConfigEntries = new ArrayList<AppConfigurationEntry>(); Map<String, ?> options = new HashMap<>(); jaasConfigEntries.add(new AppConfigurationEntry( "Test", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options)); Callback[] callbacks = new Callback[1]; callbacks[0] = new OAuthBearerTokenCallback(); callbackHandler.handle(callbacks); }