X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2FAbstractCmsEntryPoint.java;h=9d56e5eae4654072e0a1671ee4238896dd4ccaaa;hb=636529bb7df0774617693e452b04a4c61dda16cb;hp=2d83f8ded0ab2c60f80fcb9641c2f09e53b8edbc;hpb=d66d81530f1da58e2e2c5d25e0a5dc30ad32b848;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java index 2d83f8ded..9d56e5eae 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java @@ -1,5 +1,7 @@ package org.argeo.cms.ui; +import static org.argeo.naming.SharedSecret.X_SHARED_SECRET; + import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; @@ -23,6 +25,8 @@ import org.argeo.cms.auth.CurrentUser; import org.argeo.cms.auth.HttpRequestCallbackHandler; import org.argeo.eclipse.ui.specific.UiContext; import org.argeo.jcr.JcrUtils; +import org.argeo.naming.AuthPassword; +import org.argeo.naming.SharedSecret; import org.argeo.node.NodeConstants; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.AbstractEntryPoint; @@ -54,7 +58,6 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement private Node node; private String nodePath;// useful when changing auth private String state; - private String page; private Throwable exception; // Client services @@ -133,7 +136,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement * The node to return when no node was found (for authenticated users and * anonymous) */ - protected Node getDefaultNode(Session session) throws RepositoryException { + private Node getDefaultNode(Session session) throws RepositoryException { if (!session.hasPermission(defaultPath, "read")) { String userId = session.getUserID(); if (userId.equals(NodeConstants.ROLE_ANONYMOUS)) @@ -248,8 +251,8 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement protected synchronized String setState(String newState) { String previousState = this.state; - Node node = null; - page = null; + String newNodePath = null; + String prefix = null; this.state = newState; if (newState.equals("~")) this.state = ""; @@ -257,25 +260,57 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement try { int firstSlash = state.indexOf('/'); if (firstSlash == 0) { - node = session.getNode(state); - page = ""; + newNodePath = state; + prefix = ""; } else if (firstSlash > 0) { - String prefix = state.substring(0, firstSlash); - String path = state.substring(firstSlash); - if (session.nodeExists(path)) - node = session.getNode(path); - else - throw new CmsException("Data " + path + " does not exist"); - page = prefix; + prefix = state.substring(0, firstSlash); + newNodePath = state.substring(firstSlash); + } else { + newNodePath = defaultPath; + prefix = state; + + } + + // auth + int colonIndex = prefix.indexOf('$'); + if (colonIndex > 0) { + // String user = prefix.substring(0, colonIndex); + // // if (isAnonymous()) { + // String token = prefix.substring(colonIndex + 1); + // LoginContext lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, new + // CallbackHandler() { + // + // @Override + // public void handle(Callback[] callbacks) throws IOException, + // UnsupportedCallbackException { + // for (Callback callback : callbacks) { + // if (callback instanceof NameCallback) + // ((NameCallback) callback).setName(user); + // else if (callback instanceof PasswordCallback) + // ((PasswordCallback) callback).setPassword(token.toCharArray()); + // } + // + // } + // }); + SharedSecret token = new SharedSecret(new AuthPassword(X_SHARED_SECRET + '$' + prefix)); + LoginContext lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, token); + lc.login(); + authChange(lc);// sets the node as well + // } else { + // // TODO check consistency + // } } else { - node = getDefaultNode(session); - page = state; + Node newNode = null; + if (session.nodeExists(newNodePath)) + newNode = session.getNode(newNodePath); + else + throw new CmsException("Data " + newNodePath + " does not exist"); + setNode(newNode); } - setNode(node); - String title = publishMetaData(node); + String title = publishMetaData(getNode()); if (log.isTraceEnabled()) - log.trace("node=" + node + ", state=" + state + " (page=" + page + ")"); + log.trace("node=" + newNodePath + ", state=" + state + " (prefix=" + prefix + ")"); return title; } catch (Exception e) {