throw new LoginException("Only SimpleCredentials supported in this implementation");
}
final SimpleCredentials simpleCreds = (SimpleCredentials) credentials;
JahiaLoginModule m = new JahiaLoginModule();
Subject s = new Subject();
HashMap<String, ?> sharedState = new HashMap<String, Object>();
HashMap<String, ?> options = new HashMap<String, Object>();
m.initialize(s, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(simpleCreds.getUserID());
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(simpleCreds.getPassword());
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
}, sharedState, options);
try {
JahiaLoginModule.Token t = JahiaLoginModule.getToken(simpleCreds.getUserID(), new String(
simpleCreds.getPassword()));
m.login();
m.commit();
credentials = JahiaLoginModule.getCredentials(simpleCreds.getUserID(), t != null ? t.deniedPath : null);
} catch (javax.security.auth.login.LoginException e) {
throw new LoginException(e);
}