1 package org
.argeo
.security
.jcr
;
4 import javax
.jcr
.Repository
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
8 import org
.argeo
.ArgeoException
;
9 import org
.argeo
.jcr
.JcrUtils
;
10 import org
.argeo
.security
.OsAuthenticationToken
;
11 import org
.argeo
.security
.core
.OsAuthenticationProvider
;
12 import org
.springframework
.security
.Authentication
;
13 import org
.springframework
.security
.AuthenticationException
;
15 /** Relies on OS to authenticate and additionaly setup JCR */
16 public class OsJcrAuthenticationProvider
extends OsAuthenticationProvider
{
17 private Repository repository
;
18 private String securityWorkspace
= "security";
19 private Session securitySession
;
23 securitySession
= repository
.login(securityWorkspace
);
24 } catch (RepositoryException e
) {
25 throw new ArgeoException("Cannot initialize", e
);
29 public void destroy() {
30 JcrUtils
.logoutQuietly(securitySession
);
33 public Authentication
authenticate(Authentication authentication
)
34 throws AuthenticationException
{
35 final OsAuthenticationToken authen
= (OsAuthenticationToken
) super
36 .authenticate(authentication
);
38 // WARNING: at this stage we assume that the java properties
39 // will have the same value
40 String username
= System
.getProperty("user.name");
41 Node userProfile
= JcrUtils
.createUserProfileIfNeeded(
42 securitySession
, username
);
44 JcrUserDetails
.checkAccountStatus(userProfile
);
46 JcrUserDetails userDetails
= new JcrUserDetails(userProfile
, authen
47 .getCredentials().toString(), getBaseAuthorities());
48 authen
.setDetails(userDetails
);
49 } catch (RepositoryException e
) {
50 JcrUtils
.discardQuietly(securitySession
);
51 throw new ArgeoException(
52 "Unexpected exception when synchronizing OS and JCR security ",
55 JcrUtils
.logoutQuietly(securitySession
);
60 public void setSecurityWorkspace(String securityWorkspace
) {
61 this.securityWorkspace
= securityWorkspace
;
64 public void setRepository(Repository repository
) {
65 this.repository
= repository
;