1 package org
.argeo
.security
.jackrabbit
.providers
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.Session
;
10 import org
.apache
.jackrabbit
.api
.JackrabbitSession
;
11 import org
.apache
.jackrabbit
.api
.security
.user
.Group
;
12 import org
.apache
.jackrabbit
.api
.security
.user
.User
;
13 import org
.apache
.jackrabbit
.api
.security
.user
.UserManager
;
14 import org
.argeo
.ArgeoException
;
15 import org
.argeo
.security
.jcr
.JcrAuthenticationProvider
;
16 import org
.springframework
.security
.GrantedAuthority
;
17 import org
.springframework
.security
.GrantedAuthorityImpl
;
19 public class JackrabbitAuthenticationProvider
extends JcrAuthenticationProvider
{
22 protected GrantedAuthority
[] getGrantedAuthorities(Session session
) {
24 JackrabbitSession jackrabbitSession
= (JackrabbitSession
) session
;
25 UserManager userManager
= jackrabbitSession
.getUserManager();
26 User user
= (User
) userManager
.getAuthorizable(session
.getUserID());
27 List
<GrantedAuthority
> authorities
= new ArrayList
<GrantedAuthority
>();
28 for (Iterator
<Group
> it
= user
.memberOf(); it
.hasNext();)
29 authorities
.add(new GrantedAuthorityImpl(it
.next().getID()));
31 .toArray(new GrantedAuthority
[authorities
.size()]);
32 } catch (RepositoryException e
) {
33 throw new ArgeoException("Cannot retrieve authorities for "
34 + session
.getUserID(), e
);