@Test public void testAttemptToCreateBasicChallengeWithNoRegisteredFactories() throws Exception { final HttpRequestMessage request = new HttpRequestMessage(); final ResourceAddress address = context.mock(ResourceAddress.class); request.setLocalAddress(address); final HttpRealmInfo realm = new DefaultHttpRealmInfo("demo", "Basic", null, new String[]{"foo"}, new String[]{}, new String[]{}, null, null); try { factory.createChallenge(request, realm); fail("Expecting an Illegal State Exception because no factories are registered."); } catch (IllegalStateException e) { context.assertIsSatisfied(); } }
@Override public HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage, HttpRealmInfo realm, Object... params) { if ( httpRequestMessage == null || httpRequestMessage.getLocalAddress() == null) { throw new NullPointerException("Cannot issue challenge; httpRequestMessage not provided."); } String authScheme = realm.getChallengeScheme(); HttpChallengeFactory factory = lookup(authScheme); if (factory == null) { throw new IllegalStateException("Cannot issue a challenge for authentication scheme: " + authScheme); } return factory.createChallenge(httpRequestMessage, realm, params); }
DispatchHttpChallengeFactory implements HttpChallengeFactory { @Override public HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage, HttpRealmInfo realm, Object... params) { if ( httpRequestMessage == null || httpRequestMessage.getLocalAddress() == null) { throw new NullPointerException("Cannot issue challenge; httpRequestMessage not provided."); } String authScheme = realm.getChallengeScheme(); HttpChallengeFactory factory = lookup(authScheme); if (factory == null) { throw new IllegalStateException("Cannot issue a challenge for authentication scheme: " + authScheme); } return factory.createChallenge(httpRequestMessage, realm, params); } }
DispatchHttpChallengeFactory implements HttpChallengeFactory { @Override public HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage, HttpRealmInfo realm, Object... params) { if ( httpRequestMessage == null || httpRequestMessage.getLocalAddress() == null) { throw new NullPointerException("Cannot issue challenge; httpRequestMessage not provided."); } String authScheme = realm.getChallengeScheme(); HttpChallengeFactory factory = lookup(authScheme); if (factory == null) { throw new IllegalStateException("Cannot issue a challenge for authentication scheme: " + authScheme); } return factory.createChallenge(httpRequestMessage, realm, params); }  }
DispatchHttpChallengeFactory implements HttpChallengeFactory { @Override public HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage, HttpRealmInfo realm, Object... params) { if ( httpRequestMessage == null || httpRequestMessage.getLocalAddress() == null) { throw new NullPointerException("Cannot issue challenge; httpRequestMessage not provided."); } String authScheme = realm.getChallengeScheme(); HttpChallengeFactory factory = lookup(authScheme); if (factory == null) { throw new IllegalStateException("Cannot issue a challenge for authentication scheme: " + authScheme); } return factory.createChallenge(httpRequestMessage, realm, params); }  static void clear(); void register(String authScheme, HttpChallengeFactory factory); @Override HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage,
                                               HttpRealmInfo realm,
                                               Object... params); HttpChallengeFactory lookup(String authScheme); }
DispatchHttpChallengeFactory implements HttpChallengeFactory { @Override public HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage, HttpRealmInfo realm, Object... params) { if ( httpRequestMessage == null || httpRequestMessage.getLocalAddress() == null) { throw new NullPointerException("Cannot issue challenge; httpRequestMessage not provided."); } String authScheme = realm.getChallengeScheme(); HttpChallengeFactory factory = lookup(authScheme); if (factory == null) { throw new IllegalStateException("Cannot issue a challenge for authentication scheme: " + authScheme); } return factory.createChallenge(httpRequestMessage, realm, params); }  static void clear(); void register(String authScheme, HttpChallengeFactory factory); @Override HttpResponseMessage createChallenge(HttpRequestMessage httpRequestMessage,
                                               HttpRealmInfo realm,
                                               Object... params); HttpChallengeFactory lookup(String authScheme); static Map<String, HttpChallengeFactory> challengeFactoriesByAuthScheme; }