// be doable by looking for state transitions from UNKNOWN to other states.
// }
}
// set the session subject, so the fetch to load the configuration works
final Subject subject = new Subject();
subject.setId(subjectId);
subject.setSessionId(Integer.valueOf(sessionId));
// populate the username for the subject for isUserWithPrincipal check in ldap processing
subject.setName(user);
sessionSubject = subject;
if (subject.getId() == 0) {//either i)ldap new user registration ii)ldap case sensitive match
if ((subject.getName() == null) || (subject.getName().trim().isEmpty())) {
//we've lost crucial information, probably in a browser refresh. Send them back through login
Log.trace("Unable to locate information critical to ldap registration/account lookup. Log back in.");
sessionState = State.IS_LOGGED_OUT;
new LoginView().showLoginDialog(true);
return;
}
Log.error("Proceeding with case insensitive login of ldap user '" + user + "'.");
GWTServiceLookup.getSubjectService().processSubjectForLdap(subject, password,
new AsyncCallback<Subject>() {
public void onFailure(Throwable caught) {
// this means either: a) we mapped the username to a previously registered LDAP
// user but login via LDAP failed, or b) we were not able to map the username
// to any LDAP users, previously registered or not.
Log.debug("Failed to complete ldap processing for subject: "
+ caught.getMessage());
new LoginView().showLoginDialog(MSG.view_login_noUser());
return;
}
public void onSuccess(final Subject processedSubject) {
//Then found case insensitive and returned that logged in user
//Figure out of this is new user registration
boolean isNewUser = false;
if (processedSubject.getUserConfiguration() != null) {
isNewUser = Boolean.valueOf(processedSubject.getUserConfiguration()
.getSimpleValue("isNewUser", "false"));
}
if (!isNewUser) {
// otherwise, we successfully logged in as an existing LDAP user case insensitively.
Log.trace("Logged in case insensitively as ldap user '"
+ processedSubject.getName() + "'");
callback.onSuccess(processedSubject);
} else {// if account is still active assume new LDAP user registration.
Log.trace("Proceeding with registration for ldap user '" + user + "'.");
sessionState = State.IS_REGISTERING;
sessionSubject = processedSubject;
new LoginView().showRegistrationDialog(subject.getName(),
String.valueOf(processedSubject.getSessionId()), password, callback);
}
return;
}
});//end processSubjectForLdap call
} else {//else send through regular session check
SubjectCriteria criteria = new SubjectCriteria();
criteria.fetchConfiguration(true);
criteria.addFilterId(subjectId);
GWTServiceLookup.getSubjectService().findSubjectsByCriteria(criteria,
new AsyncCallback<PageList<Subject>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.util_userSession_loadFailSubject(),
caught);
Log.info("Failed to load user's subject");
//TODO: pass message to login ui.
new LoginView().showLoginDialog(true);
return;
}
public void onSuccess(PageList<Subject> results) {
final Subject validSessionSubject = results.get(0);
//update the returned subject with current session id
validSessionSubject.setSessionId(Integer.valueOf(sessionId));
Log.trace("Completed session check for subject '" + validSessionSubject + "'.");
//initiate ldap check for ldap authz update(wrt roles) of subject with silent update
//as the subject.id > 0 then only group authorization updates will occur if ldap configured.
GWTServiceLookup.getSubjectService().processSubjectForLdap(validSessionSubject,
"", new AsyncCallback<Subject>() {
public void onFailure(Throwable caught) {
Log.warn("Errors occurred processing subject for LDAP."
+ caught.getMessage());
//TODO: pass informative message to Login UI.
callback.onSuccess(validSessionSubject);
return;
}
public void onSuccess(Subject result) {
Log.trace("Successfully processed subject '"
+ validSessionSubject.getName() + "' for LDAP.");
callback.onSuccess(validSessionSubject);
return;
}
});
}