]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrAuthenticationToken.java
27b7ee85b174a222300c79c36d9f260dffe9369d
1 package org
.argeo
.security
.jcr
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.ArgeoException
;
8 import org
.argeo
.security
.SiteAuthenticationToken
;
9 import org
.springframework
.security
.GrantedAuthority
;
11 /** An authenticated authentication based on a JCR session. */
12 public class JcrAuthenticationToken
extends SiteAuthenticationToken
{
13 private static final long serialVersionUID
= -2736830165315486169L;
15 private final transient Session session
;
16 private final String userHomePath
;
18 public JcrAuthenticationToken(Object principal
, Object credentials
,
19 GrantedAuthority
[] authorities
, String url
, Node userHome
) {
20 super(principal
, credentials
, authorities
, url
,
21 extractWorkspace(userHome
));
23 this.session
= userHome
.getSession();
24 this.userHomePath
= userHome
.getPath();
25 } catch (RepositoryException e
) {
26 throw new ArgeoException("Cannot extract path from " + userHome
, e
);
30 private static String
extractWorkspace(Node userHome
) {
32 return userHome
.getSession().getWorkspace().getName();
33 } catch (RepositoryException e
) {
34 throw new ArgeoException("Cannot extract workspace from "
39 /** The path to the authenticated user home node. */
40 public String
getUserHomePath() {
44 /** The session used to create this authentication. */
45 public Session
getSession() {
50 public boolean isAuthenticated() {
51 if (session
== null || !session
.isLive())
52 setAuthenticated(false);
53 return super.isAuthenticated();
57 public void setAuthenticated(boolean isAuthenticated
)
58 throws IllegalArgumentException
{
59 super.setAuthenticated(isAuthenticated
);
60 if (!isAuthenticated
&& session
!= null)