X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2FAbstractCmsEntryPoint.java;h=2cd86ce08edc115300b1e9cda9d0309b4d8626bc;hb=92b77a90db637e71a7ccbc76fc12bad6ba4a289a;hp=43906fae73e7914aaa0797d06aa7746e76da93ad;hpb=c811008ac91053f068c26f48427617de9bb7b79c;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 43906fae7..2cd86ce08 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.io.IOException; import java.security.PrivilegedAction; import java.util.HashMap; @@ -14,9 +16,6 @@ import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.security.auth.Subject; import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; @@ -26,9 +25,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.cms.CmsException; import org.argeo.cms.auth.CurrentUser; +import org.argeo.cms.auth.HttpRequestCallback; 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; @@ -138,17 +140,17 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement * The node to return when no node was found (for authenticated users and * anonymous) */ - private Node getDefaultNode(Session session) throws RepositoryException { - if (!session.hasPermission(defaultPath, "read")) { - String userId = session.getUserID(); - if (userId.equals(NodeConstants.ROLE_ANONYMOUS)) - // TODO throw a special exception - throw new CmsException("Login required"); - else - throw new CmsException("Unauthorized"); - } - return session.getNode(defaultPath); - } +// private Node getDefaultNode(Session session) throws RepositoryException { +// if (!session.hasPermission(defaultPath, "read")) { +// String userId = session.getUserID(); +// if (userId.equals(NodeConstants.ROLE_ANONYMOUS)) +// // TODO throw a special exception +// throw new CmsException("Login required"); +// else +// throw new CmsException("Unauthorized"); +// } +// return session.getNode(defaultPath); +// } protected String getBaseTitle() { return factoryProperties.get(WebClient.PAGE_TITLE); @@ -274,24 +276,23 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement } // auth - int colonIndex = prefix.indexOf(':'); + 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() { + SharedSecret token = new SharedSecret(new AuthPassword(X_SHARED_SECRET + '$' + prefix)) { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + super.handle(callbacks); + // handle HTTP context for (Callback callback : callbacks) { - if (callback instanceof NameCallback) - ((NameCallback) callback).setName(user); - else if (callback instanceof PasswordCallback) - ((PasswordCallback) callback).setPassword(token.toCharArray()); + if (callback instanceof HttpRequestCallback) { + ((HttpRequestCallback) callback).setRequest(UiContext.getHttpRequest()); + ((HttpRequestCallback) callback).setResponse(UiContext.getHttpResponse()); + } } - } - }); + }; + LoginContext lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, token); lc.login(); authChange(lc);// sets the node as well // } else { @@ -301,8 +302,10 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement Node newNode = null; if (session.nodeExists(newNodePath)) newNode = session.getNode(newNodePath); - else - throw new CmsException("Data " + newNodePath + " does not exist"); + else { +// throw new CmsException("Data " + newNodePath + " does not exist"); + newNode = null; + } setNode(newNode); } String title = publishMetaData(getNode()); @@ -325,7 +328,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement private String publishMetaData(Node node) throws RepositoryException { // Title String title; - if (node.isNodeType(NodeType.MIX_TITLE) && node.hasProperty(Property.JCR_TITLE)) + if (node != null && node.isNodeType(NodeType.MIX_TITLE) && node.hasProperty(Property.JCR_TITLE)) title = node.getProperty(Property.JCR_TITLE).getString() + " - " + getBaseTitle(); else title = getBaseTitle(); @@ -335,6 +338,8 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement return null; StringBuilder js = new StringBuilder(); + if (title == null) + title = ""; title = title.replace("'", "\\'");// sanitize js.append("document.title = '" + title + "';"); jsExecutor.execute(js.toString());