Is it possible to show a custom error message in a custom login module with JAAS in EAP 6.4?
Issue
-
Is it possible show a different message error for each
throw
in a custom login module withJAAS
in EAP 6.4? -
With the follow LoginModule is it possible to show the
throw
message in the client.
public class CustomLoginModule implements LoginModule {
Subject subject = null;
CallbackHandler callbackHandler = null;
Map<String, ?> sharedState = null;
Map<String, ?> options = null;
private String username;
private char[] password;
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
this.subject = subject;
this.callbackHandler = callbackHandler;
this.sharedState = sharedState;
this.options = options;
}
public boolean login() throws LoginException {
if (callbackHandler == null) {
throw new LoginException("Error: no CallbackHandler available "
+ "to garner authentication information from the user");
}
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("username");
callbacks[1] = new PasswordCallback("password: ", false);
try {
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[0]).getName();
password = ((PasswordCallback) callbacks[1]).getPassword();
System.out.println("Username: " + username + " Password: " + password.toString());
} catch (java.io.IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException("Error: " + uce.getCallback().toString()
+ " not available to garner authentication information "
+ "from the user");
} catch (Exception e) {
throw new LoginException(e.getMessage());
}
return false;
}
// ...
}
Environment
Red Hat JBoss Enterprise Application Platform (EAP) 6.4.X
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.