if (ANONYMOUS.equals(mechanismName) && realm == null) {
return new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback current : callbacks) {
throw new UnsupportedCallbackException(current, "ANONYMOUS mechanism so not expecting a callback");
}
}
};
}
// For now for the JBOSS_LOCAL_USER we are only supporting the $local user and not allowing for
// an alternative authorizationID.
if (JBOSS_LOCAL_USER.equals(mechanismName)) {
return new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback current : callbacks) {
if (current instanceof NameCallback) {
NameCallback ncb = (NameCallback) current;
if (DOLLAR_LOCAL.equals(ncb.getDefaultName()) == false) {
throw new SaslException("Only " + DOLLAR_LOCAL + " user is acceptable.");
}
} else if (current instanceof AuthorizeCallback) {
AuthorizeCallback acb = (AuthorizeCallback) current;
acb.setAuthorized(acb.getAuthenticationID().equals(acb.getAuthorizationID()));
} else {
throw new UnsupportedCallbackException(current);
}
}
}
};
}
// In this calls only the AuthorizeCallback is needed, we are not making use if an authorization ID just yet
// so don't need to be linked back to the realms.
if (EXTERNAL.equals(mechanismName)) {
return new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback current : callbacks) {
if (current instanceof AuthorizeCallback) {
AuthorizeCallback acb = (AuthorizeCallback) current;
acb.setAuthorized(acb.getAuthenticationID().equals(acb.getAuthorizationID()));
} else {
throw new UnsupportedCallbackException(current);
}
}
}
};