Better deal with authentication corner cases
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / AbstractCmsEntryPoint.java
index 9a7f6412e862a5b219df558932fe5b6952606f92..02e08f2af94c32d6561b94f0945a61513b1600ae 100644 (file)
@@ -160,7 +160,26 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint
 
                        session = repository.login(workspace);
                        if (currentPath != null)
-                               node = session.getNode(currentPath);
+                               try {
+                                       node = session.getNode(currentPath);
+                               } catch (Exception e) {
+                                       try {
+                                               // TODO find a less hacky way to log out
+                                               new ArgeoLoginContext(
+                                                               KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject)
+                                                               .logout();
+                                               new ArgeoLoginContext(
+                                                               KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject)
+                                                               .login();
+                                       } catch (LoginException eAnonymous) {
+                                               throw new ArgeoException("Cannot reset to anonymous",
+                                                               eAnonymous);
+                                       }
+                                       JcrUtils.logoutQuietly(session);
+                                       session = repository.login(workspace);
+                                       navigateTo("~");
+                                       throw e;
+                               }
 
                        // refresh UI
                        refresh();