1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.ui.script;
12
13 import org.astrogrid.community.User;
14 import org.astrogrid.community.beans.v1.Account;
15 import org.astrogrid.community.beans.v1.Credentials;
16 import org.astrogrid.community.beans.v1.Group;
17 import org.astrogrid.community.common.exception.CommunityIdentifierException;
18 import org.astrogrid.community.common.exception.CommunitySecurityException;
19 import org.astrogrid.community.common.exception.CommunityServiceException;
20 import org.astrogrid.community.resolver.CommunityPasswordResolver;
21 import org.astrogrid.community.resolver.exception.CommunityResolverException;
22 import org.astrogrid.registry.RegistryException;
23 import org.astrogrid.scripting.Toolbox;
24 import org.astrogrid.store.Ivorn;
25
26 /*** Implementation of ScriptEnvironment that enforces login -- a bit crap, but will have to do until we have proper security.
27 * @author Noel Winstanley nw@jb.man.ac.uk 20-Dec-2004
28 *
29 */
30 final class LoginScriptEnvironment implements ScriptEnvironment {
31
32 /*** Construct a new LoginScriptEnvironment
33 * @throws RegistryException
34 * @throws CommunityIdentifierException
35 * @throws CommunitySecurityException
36 * @throws CommunityServiceException
37 * @throws CommunityResolverException
38 *
39 */
40 LoginScriptEnvironment(String name,String community,String password) throws CommunityResolverException, CommunityServiceException, CommunitySecurityException, CommunityIdentifierException, RegistryException {
41
42 ag = new Toolbox();
43
44 if (name == null) {
45 name = ag.getSystemConfig().getString("username");
46 }
47 if (community == null) {
48 community = ag.getSystemConfig().getString("org.astrogrid.community.ident");
49 }
50 if (password == null) {
51 password = ag.getSystemConfig().getString("password");
52 }
53 this.password = password;
54 CommunityPasswordResolver security = new CommunityPasswordResolver();
55 Account acc = new Account();
56 Group group = new Group();
57 group.setName("login-script-env-users");
58 acc.setName(name);
59 acc.setCommunity(community);
60 group.setCommunity(community);
61 creds = new Credentials();
62 creds.setAccount(acc);
63 creds.setGroup(group);
64 userIvorn = new Ivorn(community,name,"");
65 creds.setSecurityToken(security.checkPassword(userIvorn.toString(),password).getToken());
66
67 homeIvorn = new Ivorn(community,name,name + "/");
68 u = new User(name,community,creds.getGroup().getName(),creds.getSecurityToken());
69 }
70
71 private final Credentials creds;
72 private final Toolbox ag;
73 private final User u;
74 private final Ivorn userIvorn;
75 private final Ivorn homeIvorn;
76 private final String password;
77
78 /***
79 * @see org.astrogrid.ui.script.ScriptEnvironment#getAstrogrid()
80 */
81 public Toolbox getAstrogrid() {
82 return ag;
83 }
84
85 /***
86 * @see org.astrogrid.ui.script.ScriptEnvironment#getUser()
87 */
88 public User getUser() {
89 return u;
90 }
91
92 /***
93 * @see org.astrogrid.ui.script.ScriptEnvironment#getAccount()
94 */
95 public Account getAccount() {
96 return creds.getAccount();
97 }
98
99 /***
100 * @see org.astrogrid.ui.script.ScriptEnvironment#getUserIvorn()
101 */
102 public Ivorn getUserIvorn() {
103 return userIvorn;
104 }
105
106 /***
107 * @see org.astrogrid.ui.script.ScriptEnvironment#getHomeIvorn()
108 */
109 public Ivorn getHomeIvorn() {
110 return homeIvorn;
111 }
112
113 /***
114 * @see org.astrogrid.ui.script.ScriptEnvironment#getPassword()
115 */
116 public String getPassword() {
117 return password;
118 }
119
120 }
121
122
123
124
125
126
127
128
129
130
131