]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/security/jcr/NewUserDetails.java
Node registration
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / security / jcr / NewUserDetails.java
1 package org.argeo.security.jcr;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import javax.jcr.Node;
8 import javax.jcr.RepositoryException;
9
10 import org.springframework.security.core.GrantedAuthority;
11 import org.springframework.security.core.authority.SimpleGrantedAuthority;
12 import org.springframework.security.core.userdetails.User;
13
14 /** Used to create a new user */
15 public class NewUserDetails extends User {
16 private static final long serialVersionUID = -8331941336984083297L;
17
18 public NewUserDetails(String username, char[] password) {
19 this(username, password, null);
20 }
21
22 public NewUserDetails(String username, char[] password, String[] roles) {
23 super(username, new String(password), false, false, false, false,
24 rolesToAuthorities(roles));
25 }
26
27 /** To be overriden */
28 public void mapToProfileNode(Node userProfile) throws RepositoryException {
29 // does nothing by default
30 }
31
32 private static Collection<GrantedAuthority> rolesToAuthorities(
33 String[] roles) {
34 List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
35 if (roles != null)
36 for (String role : roles) {
37 authorities.add(new SimpleGrantedAuthority(role));
38 }
39 return authorities;
40 }
41 }