From ed6428ff9bfce7349f9e9808ab030a07b4b6c6f7 Mon Sep 17 00:00:00 2001 From: Darran Lofthouse Date: Fri, 25 Nov 2011 10:53:47 +0000 Subject: [PATCH] [AS7-2778] The RealmAuthenticationProvider should be returning null instead of throwing an exception. Also some minor code cleanup. --- .../jboss/as/remoting/RealmAuthenticationProvider.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/remoting/src/main/java/org/jboss/as/remoting/RealmAuthenticationProvider.java b/remoting/src/main/java/org/jboss/as/remoting/RealmAuthenticationProvider.java index 97dd6afd2902..9a59fad60f2b 100644 --- a/remoting/src/main/java/org/jboss/as/remoting/RealmAuthenticationProvider.java +++ b/remoting/src/main/java/org/jboss/as/remoting/RealmAuthenticationProvider.java @@ -121,6 +121,9 @@ OptionMap getSaslOptionMap() { } public CallbackHandler getCallbackHandler(String mechanismName) { + // TODO - Once authorization is in place we may be able to relax the realm check to + // allow anonymous along side fully authenticated connections. + // If the mechanism is ANONYMOUS and we don't have a realm we return quickly. if (ANONYMOUS.equals(mechanismName) && realm == null) { return new CallbackHandler() { @@ -158,14 +161,14 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback }; } - CallbackHandler realmCallbackHandler = null; + final CallbackHandler realmCallbackHandler; // Referenced later by an inner-class so needs to be final. // We must have a match in this block or throw an IllegalStateException. if (DIGEST_MD5.equals(mechanismName) && digestMd5Supported() || PLAIN.equals(mechanismName) && plainSupported()) { realmCallbackHandler = realm.getCallbackHandler(); } else { - throw new IllegalStateException("Unsupported Callback '" + mechanismName + "'"); + return null; } // If there is not serverCallbackHandler then we don't need to wrap it so we can just return the realm @@ -174,12 +177,11 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback return realmCallbackHandler; } - final CallbackHandler wrappedHandler = realmCallbackHandler; // Just a copy so it can be made final for the inner class. return new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { serverCallbackHandler.handle(callbacks); if (handled(callbacks) == false) { - wrappedHandler.handle(callbacks); + realmCallbackHandler.handle(callbacks); } }