import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.cms.auth.ArgeoLoginContext;
+import org.argeo.cms.i18n.Msg;
import org.argeo.jcr.JcrUtils;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.rap.rwt.client.service.BrowserNavigationListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.springframework.security.context.SecurityContextHolder;
/** Manages history and navigation */
-public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint
- implements CmsSession {
+abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implements
+ CmsSession {
private final Log log = LogFactory.getLog(AbstractCmsEntryPoint.class);
+ private Subject subject = new Subject();
+
private Repository repository;
private String workspace;
private Session session;
private BrowserNavigation history;
public AbstractCmsEntryPoint(Repository repository, String workspace) {
- if (SecurityContextHolder.getContext().getAuthentication() == null)
- logAsAnonymous();
-
this.repository = repository;
this.workspace = workspace;
+
+ // Initial login
+ Subject subject = new Subject();
+ try {
+ new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_USER, subject)
+ .login();
+ } catch (LoginException e) {
+ if (log.isTraceEnabled())
+ log.trace("Cannot authenticate user", e);
+ try {
+ new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_ANONYMOUS,
+ subject).login();
+ } catch (LoginException eAnonymous) {
+ throw new ArgeoException("Cannot initialize subject",
+ eAnonymous);
+ }
+ }
authChange();
history = RWT.getClient().getService(BrowserNavigation.class);
/** Recreate body UI */
protected abstract void refreshBody();
- /** Log as anonymous */
- protected abstract void logAsAnonymous();
-
/**
* The node to return when no node was found (for authenticated users and
* anonymous)
history.pushState(state, state);
}
+ @Override
+ public Subject getSubject() {
+ return subject;
+ }
+
@Override
public void authChange() {
try {
currentPath = node.getPath();
JcrUtils.logoutQuietly(session);
- if (SecurityContextHolder.getContext().getAuthentication() == null)
- logAsAnonymous();
session = repository.login(workspace);
if (currentPath != null)
node = session.getNode(currentPath);
page = prefix;
} else {
node = getDefaultNode(session);
- if (state.equals("~"))
- page = "";
- else
- page = state;
+ page = state;
}
if (log.isTraceEnabled())
- log.trace("page=" + page + ", node=" + node + ", state="
- + state);
+ log.trace("node=" + node + ", state=" + state + " (page="
+ + page);
} catch (RepositoryException e) {
throw new CmsException("Cannot retrieve node", e);
return state;
}
- protected String getPage() {
- return page;
- }
+ // String getPage() {
+ // return page;
+ // }
protected Throwable getException() {
return exception;