Skip to content

Commit

Permalink
Student Scheduling Assistant: User Authentication
Browse files Browse the repository at this point in the history
- better handling of the authentication, especially the guest account (when authentication is not required)
  - e.g., the guest user does not get the “You are not eligible to register” warning
- an issue fixed in the redirection to the login / logout page (when the login dialog is not allowed)
  - not authenticated (no guest) case went to the logout page instead of the login page
  • Loading branch information
tomas-muller committed Apr 16, 2015
1 parent cc56657 commit b275d8b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,27 @@ public StudentSectioningPage(final Mode mode) {
if (Window.Location.getParameter("student") == null)
iSectioningService.whoAmI(new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
userAuthentication.authenticate();
if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired() || CONSTANTS.tryAuthenticationWhenGuest()) {
if (CONSTANTS.allowUserLogin())
userAuthentication.authenticate();
else if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired())
ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref()));
else
userAuthentication.authenticated(null);
}
}
public void onSuccess(String result) {
if (MESSAGES.userGuest().equals(result)) { // user is guest (i.e., not truly authenticated)
if (result == null) { // not authenticated
if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired() || CONSTANTS.tryAuthenticationWhenGuest()) {
if (CONSTANTS.allowUserLogin())
userAuthentication.authenticate();
else if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired())
ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref()));
else
userAuthentication.authenticated(result);
} else
} else {
userAuthentication.authenticated(result);
}
} else {
userAuthentication.authenticated(result);
}
Expand Down Expand Up @@ -134,10 +142,10 @@ public void onClick(ClickEvent event) {
userAuthentication.authenticate();
} else if (userAuthentication.isAllowLookup()) {
userAuthentication.doLookup();
} else if (userAuthentication.isGuest()) {
ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref()));
} else {
} else if (userAuthentication.isLoggedIn()) {
ToolBox.open(GWT.getHostPageBaseURL() + "logOut.do");
} else {
ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref()));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ public void lastRequest(Long sessionId, Long studentId, final boolean saved) {
AsyncCallback<CourseRequestInterface> callback = new AsyncCallback<CourseRequestInterface>() {
public void onFailure(Throwable caught) {
LoadingWidget.getInstance().hide();
clear();
}
public void onSuccess(final CourseRequestInterface request) {
if (request.isSaved() && request.getCourses().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,7 @@ public void onSuccess(String result) {
iSkip.setEnabled(true);
iError.setVisible(false);
iDialog.hide();
iPanel.setText(MESSAGES.userLabel(result));
iLastUser = result;
if (isAllowLookup() && !CONSTANTS.allowUserLogin()) {
iPanel.setHint(MESSAGES.userHintLookup());
iPanel.setAriaLabel(ARIA.userAuthenticatedLookup(getUser()));
} else {
iPanel.setHint(MESSAGES.userHintLogout());
iPanel.setAriaLabel(ARIA.userAuthenticated(result));
}
iLoggedIn = true;
iGuest = false;
authenticated(result);
UserAuthenticatedEvent e = new UserAuthenticatedEvent(iGuest);
for (UserAuthenticatedHandler h: iUserAuthenticatedHandlers)
h.onLogIn(e);
Expand Down Expand Up @@ -346,12 +336,31 @@ public void execute() {

public void authenticated(String user) {
if (iDialog.isShowing()) iDialog.hide();
iLoggedIn = true;
iGuest = MESSAGES.userGuest().equals(user);
iPanel.setText(MESSAGES.userLabel(user));
if (user == null) {
if (iAllowGuest) {
iGuest = true;
iPanel.setText(MESSAGES.userLabel(MESSAGES.userGuest()));
iPanel.setAriaLabel(ARIA.userGuest());
} else {
iGuest = false;
iPanel.setText(MESSAGES.userNotAuthenticated());
iPanel.setAriaLabel(ARIA.userNotAuthenticated());
}
iLoggedIn = false;
iPanel.setHint(MESSAGES.userHintLogin());
} else {
iLoggedIn = true;
iGuest = false;
iPanel.setText(MESSAGES.userLabel(user));
if (isAllowLookup() && !CONSTANTS.allowUserLogin()) {
iPanel.setHint(MESSAGES.userHintLookup());
iPanel.setAriaLabel(ARIA.userAuthenticatedLookup(getUser()));
} else {
iPanel.setHint(MESSAGES.userHintLogout());
iPanel.setAriaLabel(ARIA.userAuthenticated(user));
}
}
iLastUser = user;
iPanel.setHint(iGuest ? MESSAGES.userHintLogin() : MESSAGES.userHintLogout());
iPanel.setAriaLabel(iGuest ? ARIA.userGuest() : ARIA.userAuthenticated(user));
}

private void logIn(boolean guest) {
Expand All @@ -360,12 +369,8 @@ private void logIn(boolean guest) {
sSectioningService.logOut(new AsyncCallback<Boolean>() {
public void onFailure(Throwable caught) { }
public void onSuccess(Boolean result) {
iLoggedIn = true; iGuest = true;
iDialog.hide();
iPanel.setText(MESSAGES.userLabel(MESSAGES.userGuest()));
iPanel.setHint(MESSAGES.userHintLogin());
iPanel.setAriaLabel(ARIA.userGuest());
iLastUser = MESSAGES.userGuest();
authenticated(null);
UserAuthenticatedEvent e = new UserAuthenticatedEvent(iGuest);
for (UserAuthenticatedHandler h: iUserAuthenticatedHandlers)
h.onLogIn(e);
Expand All @@ -389,27 +394,19 @@ public void logOut() {
public void onFailure(Throwable caught) { }
public void onSuccess(Boolean result) {
if (result) {
authenticated(null);
UserAuthenticatedEvent e = new UserAuthenticatedEvent(iGuest);
iPanel.setHint(MESSAGES.userHintClose());
iPanel.setText(MESSAGES.userNotAuthenticated());
iPanel.setAriaLabel(ARIA.userNotAuthenticated());
iLastUser = null;
for (UserAuthenticatedHandler h: iUserAuthenticatedHandlers)
h.onLogOut(e);
iLoggedIn = false;
Client.reloadMenu();
} else {
sSectioningService.whoAmI(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
authenticated(null);
UserAuthenticatedEvent e = new UserAuthenticatedEvent(iGuest);
iPanel.setHint(MESSAGES.userHintClose());
iPanel.setText(MESSAGES.userNotAuthenticated());
iPanel.setAriaLabel(ARIA.userNotAuthenticated());
iLastUser = null;
for (UserAuthenticatedHandler h: iUserAuthenticatedHandlers)
h.onLogOut(e);
iLoggedIn = false;
Client.reloadMenu();
}

Expand All @@ -434,13 +431,17 @@ public String getUser() {
public void setUser(final String user, final AsyncCallback<Boolean> callback) {
iOnLoginCommand = null;
if (user == null) {
callback.onSuccess(false);
authenticate();
if (iLastUser == null) {
callback.onSuccess(true);
} else if (iAllowGuest) {
logIn(true);
callback.onSuccess(true);
} else {
callback.onSuccess(false);
authenticate();
}
} else if (user.equals(iLastUser)) {
callback.onSuccess(true);
} else if (user.equals(MESSAGES.userGuest())) {
logIn(true);
callback.onSuccess(true);
} else {
iOnLoginCommand = new Command() {
public void execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import org.unitime.timetable.security.SessionContext;
import org.unitime.timetable.security.UserAuthority;
import org.unitime.timetable.security.UserContext;
import org.unitime.timetable.security.context.AnonymousUserContext;
import org.unitime.timetable.security.qualifiers.SimpleQualifier;
import org.unitime.timetable.security.rights.Right;
import org.unitime.timetable.solver.service.SolverServerService;
Expand Down Expand Up @@ -676,8 +677,8 @@ public String whoAmI() throws SectioningException, PageAccessException {
UniTimePrincipal principal = (UniTimePrincipal)getSessionContext().getAttribute("user");
if (principal != null) return principal.getName();
UserContext user = getSessionContext().getUser();
if (user != null) return (user.getName() == null ? user.getUsername() : user.getName());
return "Guest";
if (user == null || user instanceof AnonymousUserContext) return null;
return (user.getName() == null ? user.getUsername() : user.getName());
}

public Long getStudentId(Long sessionId) {
Expand Down Expand Up @@ -1975,6 +1976,7 @@ public EligibilityCheck checkEligibility(boolean online, Long sessionId, Long st
EligibilityCheck check = new EligibilityCheck();
check.setFlag(EligibilityFlag.IS_ADMIN, getSessionContext().hasPermission(Right.StudentSchedulingAdmin));
check.setFlag(EligibilityFlag.IS_ADVISOR, getSessionContext().hasPermission(Right.StudentSchedulingAdvisor));
check.setFlag(EligibilityFlag.IS_GUEST, user instanceof AnonymousUserContext);
check.setSessionId(sessionId);
check.setStudentId(studentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class EligibilityCheck implements IsSerializable, Serializable {
private Long iSessionId = null, iStudentId = null;

public static enum EligibilityFlag implements IsSerializable {
IS_ADMIN, IS_ADVISOR,
IS_ADMIN, IS_ADVISOR, IS_GUEST,
CAN_USE_ASSISTANT,
CAN_ENROLL,
PIN_REQUIRED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public EligibilityCheck execute(OnlineSectioningServer server, OnlineSectioningH

Student student = (iStudentId == null ? null : StudentDAO.getInstance().get(iStudentId, helper.getHibSession()));
if (student == null) {
if (!iCheck.hasFlag(EligibilityFlag.IS_ADMIN) && !iCheck.hasFlag(EligibilityFlag.IS_ADVISOR)
if (!iCheck.hasFlag(EligibilityFlag.IS_ADMIN) && !iCheck.hasFlag(EligibilityFlag.IS_ADVISOR) && !iCheck.hasFlag(EligibilityFlag.IS_GUEST)
&& server.getAcademicSession().isSectioningEnabled())
iCheck.setMessage(MSG.exceptionEnrollNotStudent(server.getAcademicSession().toString()));
logCheck(action, iCheck);
Expand Down

0 comments on commit b275d8b

Please sign in to comment.