Skip to content

Commit

Permalink
[AS7-2778] The RealmAuthenticationProvider should be returning null i…
Browse files Browse the repository at this point in the history
…nstead of throwing an exception.

Also some minor code cleanup.
  • Loading branch information
darranl authored and bstansberry committed Nov 28, 2011
1 parent 33c72ef commit ed6428f
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down

0 comments on commit ed6428f

Please sign in to comment.