01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.identity;
23:
24: import java.security.*;
25: import java.util.*;
26:
27: /**
28: * user or a system.
29: */
30: public class User extends Entity implements Principal {
31:
32: private static final long serialVersionUID = 1L;
33:
34: protected String password = null;
35: protected String email = null;
36: protected Set memberships = null;
37:
38: public User() {
39: }
40:
41: public User(String name) {
42: super (name);
43: }
44:
45: public void addMembership(Membership membership) {
46: if (memberships == null)
47: memberships = new HashSet();
48: memberships.add(membership);
49: membership.setUser(this );
50: }
51:
52: public Set getGroupsForGroupType(String groupType) {
53: Set groups = new HashSet();
54: if (memberships != null) {
55: Iterator iter = memberships.iterator();
56: while (iter.hasNext()) {
57: Membership membership = (Membership) iter.next();
58: if (groupType.equals(membership.getGroup().getType())) {
59: groups.add(membership.getGroup());
60: }
61: }
62: }
63: return groups;
64: }
65:
66: public Set getGroupsForMembershipRole(String membershipRole) {
67: Set groups = new HashSet();
68: if (memberships != null) {
69: Iterator iter = memberships.iterator();
70: while (iter.hasNext()) {
71: Membership membership = (Membership) iter.next();
72: if (membershipRole.equals(membership.getRole())) {
73: groups.add(membership.getGroup());
74: }
75: }
76: }
77: return groups;
78: }
79:
80: public void setPassword(String password) {
81: this .password = password;
82: }
83:
84: public String getPassword() {
85: return password;
86: }
87:
88: public Set getMemberships() {
89: return memberships;
90: }
91:
92: public String getEmail() {
93: return email;
94: }
95:
96: public void setEmail(String email) {
97: this.email = email;
98: }
99: }
|