]> git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrArgeoUser.java
131d6ea5ebcdc5570a9094b560d8d21828dfd420
[lgpl/argeo-commons.git] / JcrArgeoUser.java
1 package org.argeo.security.jcr;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6 import java.util.Map;
7
8 import javax.jcr.Node;
9 import javax.jcr.RepositoryException;
10
11 import org.argeo.ArgeoException;
12 import org.argeo.security.ArgeoUser;
13 import org.argeo.security.UserNature;
14
15 public class JcrArgeoUser implements ArgeoUser {
16 /** Cached for performance reasons. */
17 private final String username;
18 private final Node home;
19 private final List<String> roles;
20 private final Boolean enabled;
21 private final String password;
22
23 public JcrArgeoUser(Node home, String password, List<String> roles,
24 Boolean enabled) {
25 this.home = home;
26 this.password = password;
27 this.roles = Collections.unmodifiableList(new ArrayList<String>(roles));
28 this.enabled = enabled;
29 try {
30 username = home.getSession().getUserID();
31 } catch (RepositoryException e) {
32 throw new ArgeoException("Cannot find JCR user id", e);
33 }
34
35 }
36
37 public String getUsername() {
38 return username;
39 }
40
41 public Map<String, UserNature> getUserNatures() {
42 throw new UnsupportedOperationException("deprecated");
43 }
44
45 public void updateUserNatures(Map<String, UserNature> userNatures) {
46 throw new UnsupportedOperationException("deprecated");
47 }
48
49 public List<String> getRoles() {
50 return roles;
51 }
52
53 public String getPassword() {
54 return password;
55 }
56
57 public Node getHome() {
58 return home;
59 }
60
61 public Boolean getEnabled() {
62 return enabled;
63 }
64
65 public boolean equals(Object obj) {
66 if (!(obj instanceof ArgeoUser))
67 return false;
68 return ((ArgeoUser) obj).getUsername().equals(username);
69 }
70
71 @Override
72 public int hashCode() {
73 return username.hashCode();
74 }
75
76 public String toString() {
77 return getUsername() + "@" + getHome();
78 }
79 }