1
2
3
4
5
6
7 package org.astrogrid.account;
8
9 import java.security.Principal;
10
11 /***
12 * Represents an individual user account within the International Virtual
13 * Observatory; ie one that is managed by VO Communities.
14 *
15 * An account consists of an individual within a community. The individual may be an
16 * automaton (eg a server) rather than human.
17 *
18 * AstroGrid references to users/accounts are of the form individual@community.
19 *
20 * While an individual can belong to one and only one community, he/she/it may
21 * belong to several 'groups'. A group may cross community boundaries.
22 *
23 * [MCH: I'm not sure if group should be specified here - it may be that the user
24 * has picked which is the relevent group that has the right credentials for the
25 * task. On the other hand it should probably be the community that looks to see if
26 * any of the groups the account belongs to have the right permissions]
27 *
28 * There are no setter methods. This is because the token goes along with the
29 * individual and community identifiers, and we shouldn't be able to change one
30 * without the other.
31 *
32 * The token is some kind of certification that is carried along with the account
33 * and community identifiers to prove that this individual really is this individual...
34
35 * @author M Hill
36 * @since iteration4
37 */
38
39
40 public class IvoAccount implements Principal {
41
42 private String individual = null;
43 private String community = null;
44 private String securityToken = null;
45
46 public static final String SCHEME = "account";
47
48 /*** Create an account for the individual with the given name who belongs
49 * to the given community, with some kind of security token */
50 public IvoAccount(String anIndividualName, String aCommunity, String aToken) {
51 this.individual = anIndividualName;
52 this.community = aCommunity;
53 this.securityToken = aToken;
54 }
55
56 /*** Create an account from the given uri of the form 'account:mch@roe.ac.uk' */
57 public IvoAccount(String uri) {
58 int atIdx = uri.indexOf("@");
59 if (!uri.startsWith(SCHEME+":") || (atIdx == -1)) {
60 throw new IllegalArgumentException("Account uri should be of the form 'account:{individual}@{community}'");
61 }
62 uri = uri.substring(SCHEME.length()+1);
63 this.individual = uri.substring(0, atIdx);
64 this.community = uri.substring(atIdx+1);
65 }
66
67 /*** Returns the canonical (fully descriptive) name of this account, implementing
68 * the Principal getName() method. */
69 public String getName() { return individual+"@"+community; }
70
71 /*** Returns the individual id within the community (eg mch) */
72 public String getIndividual() { return individual; }
73
74 /*** Returns the community id of the account (eg roe.ac.uk) */
75 public String getCommunity() { return community; }
76
77 /*** Property getter: Returns the security token */
78 public String getSecurityToken() { return securityToken; }
79
80 /*** Returns the URI used to represent this account 'on the wire'. This is
81 * of the form account:<community>/<individual> */
82 public String toUri() {
83 return "account:"+individual+"@"+community;
84 }
85
86 /*** Returns the IVORN that shouldn't be used to represent this account, but is
87 * in some places. @deprecated, use getUri */
88 public String toIvorn() {
89 return "ivo://"+community+"/"+individual;
90 }
91 }
92
93