1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.astrogrid.community;
15
16 import org.astrogrid.community.common.util.CommunityMessage;
17
18 /***
19 * Represents an individual user account.
20 *
21 * An individual consists of an account and a community, where the account
22 * identifies the individual within a community. The individual may be an
23 * automaton (eg a server) rather than human.
24 *
25 * IVO references to users/accounts are of the form individual@community.
26 *
27 * While an individual can belong to one and only one community, he/she/it may
28 * belong to several 'groups'. A group may cross community boundaries.
29 *
30 * [MCH: I'm not sure if group should be specified here - it may be that the user
31 * has picked which is the relevent group that has the right credentials for the
32 * task. On the other hand it should probably be the community that looks to see if
33 * any of the groups the account belongs to have the right permissions]
34 *
35 * [MCH: There seems to have been some confusion between 'group' and 'community' in this
36 * object. The old 'group' term later came to represent a community, and now we
37 * have a different thing called group. In adding community to this, the way the datacenter
38 * calls myspace has changed... I've made the terms more explicit by adding
39 * a commnunity property; hopefully this won't break anything... 14/2/04]
40 *
41 * There are no setter methods. This is because the token goes along with the
42 * individual and community identifiers, and we shouldn't be able to change one
43 * without the other.
44 *
45 * The token is some kind of certification that is carried along with the account
46 * and community identifiers to prove that this individual really is this individual...
47
48 * @todo merge with @link org.astrogrid.community.common.util.CommunityMessage, which effectively does xml deserializtion
49 *
50 * @author Paul Harrison (pah@jb.man.ac.uk), mch
51 * @since iteration4
52 * @todo both User & Account are about to be replaced with Dave's Commnuity set.
53 */
54
55 public class Account {
56
57 private String individual = null;
58 private String community = null;
59 private String token = null;
60
61
62 public final static Account ANONYMOUS = new Account("Anonymous","Unknown",null);
63
64 /*** Default beanlike constructor - Don't really like this as it creates
65 * an invalid Account (ie one with no individual/community) or a duplicate
66 * ANONYMOUS one
67 * @deprecated sort of - only automatic code should use this
68 */
69 public Account(){
70 this("Anonymous","Unknown", null);
71 }
72
73 /***
74 * Creates a user from the given full account details. Account and
75 * community *must* be specified.
76 */
77 public Account(String anIndividual, String aCommunity, String aToken)
78 {
79 assert (anIndividual != null) && (anIndividual.length()>0) : "an Individual must be given";
80 assert (aCommunity != null) && (aCommunity.length()>0) : "a Community must be given";
81
82
83
84 this.individual = anIndividual;
85 this.community = aCommunity;
86 this.token = aToken;
87 }
88
89
90 /***
91 * Creates a user from the "community snippet" xml representation.
92 * @param snippet The community snippet - this is an xml fragment.
93 */
94 public Account(String snippet)
95 {
96 this(CommunityMessage.getAccount(snippet).substring(0,CommunityMessage.getAccount(snippet).indexOf("@")),
97 CommunityMessage.getAccount(snippet).substring(CommunityMessage.getAccount(snippet).indexOf("@")+1),
98 CommunityMessage.getToken(snippet));
99 }
100
101 /*** Returns the individual reference within the community */
102 public String getIndividual() {
103 return individual;
104 }
105
106 /*** Returns the Astrogrid format used to refer to an account - ie individual@community
107 */
108 public String getAstrogridId() {
109 return individual+"@"+community;
110 }
111
112 /*** Returns the IVO format used to refer to an account - ie ivo://community/individual
113 */
114 public String getIvorn() {
115 return "ivo://"+community+"/"+individual;
116 }
117
118 /*** Returns the commnunity this account belongs to */
119 public String getCommunity() {
120 return community;
121 }
122
123 /*** Returns the token that certifies this instance as really representing
124 * the individual given by account & community */
125 public String getToken() {
126 return token;
127 }
128
129 /***
130 * Checks to see if this user refers to the same party as the given user.
131 * Compares only individual and commnunity - the same individual might belong
132 * to several groups but is still the same individual.
133 */
134 public boolean equals(Account user)
135 {
136 return (user.getIvorn().equals(this.getIvorn()));
137 }
138
139 /***
140 * Returns a string with the 'normal' representation of account@community
141 */
142 public String toString()
143 {
144 return getAstrogridId();
145 }
146
147 /***
148 * Create a "community snippet" from this User.
149 * @return The XML string that is the community snippet.
150 */
151 public String toSnippet()
152 {
153 return CommunityMessage.getMessage(token, getAstrogridId(), "(NoGroup)");
154 }
155
156 /***
157 * Creates a User from this Account - User & Account are about to be
158 * replaced by Dave's new Community set
159 */
160 public User toUser()
161 {
162 return new User(getIndividual(), getCommunity(), "(NoGroup)", getToken());
163 }
164
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179