Commit 8f2f7ea9 by Tuomas Riihimäki

Fix logging in with invalid password, and other ui error handlings

1 parent 14334dff
Pipeline #72 passed
in 0 seconds
......@@ -127,6 +127,8 @@ public class MenuBean implements MenuBeanLocal {
usermenu.addPage(menuitemfacade.findOrCreate("/auth/resetmailSent"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/auth/passwordChanged"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/auth/notauthorized"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/viewExpired"), null).setVisible(false);
MenuNavigation userEvent = usermenu.addPage(null, null);
userEvent.setKey("topnavi.userevent");
......
......@@ -108,7 +108,7 @@ public abstract class AbstractView implements Serializable {
viewidbuilder.toString());
// navihandler.navigateTo("/permissionDenied");
fcont.getApplication().getNavigationHandler()
.handleNavigation(fcont, null, "/permissionDenied");
.handleNavigation(fcont, null, "/permissionDenied?faces-redirect=true");
}
return ret;
......
......@@ -23,6 +23,7 @@ import java.util.Map;
import javax.ejb.AccessLocalException;
import javax.ejb.EJBAccessException;
import javax.enterprise.context.NonexistentConversationException;
import javax.faces.FacesException;
import javax.faces.application.NavigationHandler;
import javax.faces.application.ViewExpiredException;
......@@ -50,43 +51,53 @@ public class BortalExceptionHandler extends ExceptionHandlerWrapper {
return wrapped;
}
@Override
public void handle() throws FacesException {
Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
while (i.hasNext()) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
logger.debug("Found exception! handing it: {}", t.getClass().toString());
if (t instanceof ViewExpiredException) {
logger.debug("ViewExpiredException details", t);
errorpage(i, t, "/viewExpired");
if(checkException(i, t)){
return;
}
Throwable cause = t.getCause();
for (int loop = 0; loop < 20 && cause != null; ++loop) {
logger.debug("Cause not null, but {}: {}, checking" + cause.getClass(), cause.getMessage());
if (cause instanceof EJBAccessException ||
cause instanceof AccessLocalException) {
logger.debug("Found Permission Denied cause: {}, {}", cause.getClass(), cause.getMessage());
// errorpage(i, t, "permissionDenied");
logger.debug("Cause not null, but {}: {}, checking " + cause.getClass(), cause.getMessage());
if(checkException(i, cause)){
return;
}
cause = cause.getCause();
}
}
// At this point, the queue will not contain any ViewExpiredEvents.
// Therefore, let the parent handle them.
getWrapped().handle();
}
private void errorpage(Iterator<ExceptionQueuedEvent> i, Throwable t, String navigateTo) {
private boolean checkException(Iterator<ExceptionQueuedEvent> i, Throwable t) {
if (t instanceof ViewExpiredException) {
logger.debug("ViewExpiredException details", t);
errorpage(i, t, "/viewExpired?faces-redirect=true");
} else if (t instanceof NonexistentConversationException) {
logger.debug("Server restart? Got nonexistent converstation", t);
errorpage(i, t, "/viewExpired?faces-redirect=true");
} else if (t instanceof EJBAccessException || t instanceof AccessLocalException) {
logger.debug("Found Permission Denied cause: {}, {}", t.getClass(), t.getMessage());
// We should handler permission checking elsewhere. Lets just pass the error through
//errorpage(i, t, "/permissionDenied?faces-redirect=true");
} else {
return false;
}
return true;
}
private void errorpage(Iterator<ExceptionQueuedEvent> iter, Throwable t, String navigateTo) {
logger.info("navigating to {} because root exception: {}", navigateTo, t.getClass());
ViewExpiredException vee = null;
if (t instanceof ViewExpiredException) {
......@@ -106,7 +117,9 @@ public class BortalExceptionHandler extends ExceptionHandlerWrapper {
nav.handleNavigation(fc, null, navigateTo);
fc.renderResponse();
} finally {
i.remove();
if(iter != null) {
iter.remove();
}
}
}
}
......@@ -121,8 +121,8 @@ public class AuthView extends GenericCDIView {
}
public void executeLogin(String onError) {
if (onError == null) {
onError = "/auth/loginError";
if (onError == null || onError.isEmpty()) {
onError = "/auth/loginError?faces-redirect=true";
}
doLogin(onError);
}
......@@ -188,9 +188,10 @@ public class AuthView extends GenericCDIView {
try {
request.logout();
request.getSession().invalidate();
request.getSession(true);
//navihandler.forward("/frontpage?faces-redirect=true");
if (onError != null) {
logger.warn("Redirecting to error", onError);
logger.warn("Redirecting to error: '{}'", onError);
navihandler.forward(onError);
}
} catch (ServletException e) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!