X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fjcr%2FJcrAuthenticationToken.java;h=27b7ee85b174a222300c79c36d9f260dffe9369d;hb=8b8ee149b20e2578a55e17413fa5f7399ff7ba14;hp=865508317e9a12d68b9476a30783a64904bb8db5;hpb=10c220cf49f5b146bac50ed7fe2578135cd466f1;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrAuthenticationToken.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrAuthenticationToken.java index 865508317..27b7ee85b 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrAuthenticationToken.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrAuthenticationToken.java @@ -2,33 +2,63 @@ package org.argeo.security.jcr; import javax.jcr.Node; import javax.jcr.RepositoryException; +import javax.jcr.Session; import org.argeo.ArgeoException; import org.argeo.security.SiteAuthenticationToken; import org.springframework.security.GrantedAuthority; +/** An authenticated authentication based on a JCR session. */ public class JcrAuthenticationToken extends SiteAuthenticationToken { private static final long serialVersionUID = -2736830165315486169L; - private final transient Node userHome; + + private final transient Session session; + private final String userHomePath; public JcrAuthenticationToken(Object principal, Object credentials, GrantedAuthority[] authorities, String url, Node userHome) { super(principal, credentials, authorities, url, extractWorkspace(userHome)); - this.userHome = userHome; + try { + this.session = userHome.getSession(); + this.userHomePath = userHome.getPath(); + } catch (RepositoryException e) { + throw new ArgeoException("Cannot extract path from " + userHome, e); + } } private static String extractWorkspace(Node userHome) { try { return userHome.getSession().getWorkspace().getName(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot extract workspace of " + userHome, - e); + throw new ArgeoException("Cannot extract workspace from " + + userHome, e); } } - public Node getUserHome() { - return userHome; + /** The path to the authenticated user home node. */ + public String getUserHomePath() { + return userHomePath; + } + + /** The session used to create this authentication. */ + public Session getSession() { + return session; + } + + @Override + public boolean isAuthenticated() { + if (session == null || !session.isLive()) + setAuthenticated(false); + return super.isAuthenticated(); + } + + @Override + public void setAuthenticated(boolean isAuthenticated) + throws IllegalArgumentException { + super.setAuthenticated(isAuthenticated); + if (!isAuthenticated && session != null) + session.logout(); } }