Better deal with authentication corner cases
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 14 May 2015 17:38:16 +0000 (17:38 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 14 May 2015 17:38:16 +0000 (17:38 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8107 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

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();