OW2 Consortium joram

Rev

Rev 902 | Rev 1254 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
861 fmaistre 1
/*
2
 * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3
 * Copyright (C) 2004 - Bull SA
4
 * Copyright (C) 2004 - ScalAgent Distributed Technologies
5
 * Copyright (C) 1996 - Dyade
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or any later version.
11
 *
12
 * This library 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 library; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20
 * USA.
21
 *
22
 * Initial developer(s): Frederic Maistre (INRIA)
23
 * Contributor(s): Nicolas Tachker (ScalAgent DT)
24
 */
25
package org.objectweb.joram.client.jms.admin;
26
 
27
import java.util.Vector;
28
import java.util.Hashtable;
29
import java.net.ConnectException;
30
 
31
import javax.naming.*;
32
 
33
import org.objectweb.joram.shared.admin.*;
34
 
35
/**
36
 * The <code>User</code> class is a utility class needed for administering
37
 * JORAM users.
38
 */
39
public class User extends AdministeredObject
40
{
41
  /** The name of the user. */
904 fmaistre 42
  String name;
861 fmaistre 43
  /** Identifier of the user's proxy agent. */
904 fmaistre 44
  String proxyId;
861 fmaistre 45
 
46
 
47
  /**
48
   * Constructs an <code>User</code> instance.
49
   *
50
   * @param name  The name of the user.
51
   * @param proxyId  Identifier of the user's proxy agent.
52
   */
53
  public User(String name, String proxyId)
54
  {
55
    super(proxyId);
56
    this.name = name;
57
    this.proxyId = proxyId;
58
  }
59
 
60
 
61
  /** Returns a string view of this <code>User</code> instance. */
62
  public String toString()
63
  {
64
    return "User[" + name + "]:" + proxyId;
65
  }
66
 
883 fmaistre 67
 
68
  /** Returns the user name. */
69
  public String getName()
70
  {
71
    return name;
72
  }
73
 
74
  /** Provides a reliable way to compare <code>User</code> instances. */
75
  public boolean equals(Object o)
76
  {
77
    if (! (o instanceof User))
78
      return false;
79
 
80
    User other = (User) o;
81
 
82
    return other.proxyId ==proxyId;
83
  }
861 fmaistre 84
 
85
  /**
86
   * Admin method creating a user for a given server and instanciating the
87
   * corresponding <code>User</code> object.
88
   * <p>
89
   * If the user has already been set on this server, the method simply
90
   * returns the corresponding <code>User</code> object. Its fails if the
91
   * target server does not belong to the platform, or if a proxy could not
92
   * be deployed server side for a new user.
93
   *
94
   * @param name  Name of the user.
95
   * @param password  Password of the user.
96
   * @param serverId  The identifier of the user's server.
97
   *
98
   * @exception ConnectException  If the connection fails.
99
   * @exception AdminException  If the request fails.
100
   */
101
  public static User create(String name, String password, int serverId)
102
         throws ConnectException, AdminException
103
  {
104
    AdminReply reply = AdminModule.doRequest(
105
      new CreateUserRequest(name, password, serverId));
106
    return new User(name, ((CreateUserReply) reply).getProxId());
107
  }
108
 
109
  /**
110
   * Admin method creating a user on the local server and instanciating the
111
   * corresponding <code>User</code> object.
112
   * <p>
113
   * If the user has already been set on this server, the method simply
114
   * returns the corresponding <code>User</code> object. It fails if a
115
   * proxy could not be deployed server side for a new user.
116
   *
117
   * @param name  Name of the user.
118
   * @param password  Password of the user.
119
   *
120
   * @exception ConnectException  If the connection fails.
121
   * @exception AdminException  If the request fails.
122
   */
123
  public static User create(String name, String password)
124
         throws ConnectException, AdminException
125
  {
126
    return create(name, password, AdminModule.getLocalServer());
127
  }
128
 
129
  /**
130
   * Admin method updating this user identification.
131
   * <p>
132
   * The request fails if the user does not exist server side, or if the new
133
   * identification is already taken by a user on the same server.
134
   *
135
   * @param newName  The new name of the user.
136
   * @param newPassword  The new password of the user.
137
   *
138
   * @exception ConnectException  If the connection fails.
139
   * @exception AdminException  If the request fails.
140
   */
141
  public void update(String newName, String newPassword)
142
         throws ConnectException, AdminException
143
  {
144
    AdminModule.doRequest(new UpdateUser(name, proxyId, newName, newPassword));
145
    name = newName;
146
  }
147
 
148
  /**
149
   * Removes this user.
150
   *
151
   * @exception ConnectException  If the connection fails.
152
   * @exception AdminException  Never thrown.
153
   */
154
  public void delete() throws ConnectException, AdminException
155
  {
156
    AdminModule.doRequest(new DeleteUser(name, proxyId));
157
  }
158
 
159
  /**
160
   * Admin method setting a given dead message queue for this user.
161
   * <p>
162
   * The request fails if the user is deleted server side.
163
   *
164
   * @param dmq  The dead message queue to be set.
165
   *
166
   * @exception ConnectException  If the connection fails.
167
   * @exception AdminException  If the request fails.
168
   */
169
  public void setDMQ(DeadMQueue dmq) throws ConnectException, AdminException
170
  {
171
    AdminModule.doRequest(new SetUserDMQ(proxyId, dmq.getName()));
172
  }
173
 
174
  /**
175
   * Admin method setting a given value as the threshold for this user.
176
   * <p>
177
   * The request fails if the user is deleted server side.
178
   *
179
   * @param threshold  The threshold value to be set.
180
   *
181
   * @exception ConnectException  If the connection fails.
182
   * @exception AdminException  If the request fails.
183
   */
184
  public void setThreshold(int thresh) throws ConnectException, AdminException
185
  {
186
    AdminModule.doRequest(new SetUserThreshold(proxyId, thresh));
187
  }
188
 
189
  /**
190
   * Returns the dead message queue for this user, null if not set.
191
   * <p>
192
   * The request fails if the user is deleted server side.
193
   *
194
   * @exception ConnectException  If the connection fails.
195
   * @exception AdminException  If the request fails.
196
   */
197
  public DeadMQueue getDMQ() throws ConnectException, AdminException
198
  {
199
    Monitor_GetDMQSettings request;
200
    request = new Monitor_GetDMQSettings(proxyId);
201
    Monitor_GetDMQSettingsRep reply;
202
    reply = (Monitor_GetDMQSettingsRep) AdminModule.doRequest(request);
203
 
204
    if (reply.getDMQName() == null)
205
      return null;
206
    else
207
      return new DeadMQueue(reply.getDMQName());
208
  }
209
 
210
  /**
211
   * Returns the threshold for this user, -1 if not set.
212
   * <p>
213
   * The request fails if the user is deleted server side.
214
   *
215
   * @exception ConnectException  If the connection fails.
216
   * @exception AdminException  If the request fails.
217
   */
218
  public int getThreshold() throws ConnectException, AdminException
219
  {
220
    Monitor_GetDMQSettings request;
221
    request = new Monitor_GetDMQSettings(proxyId);
222
    Monitor_GetDMQSettingsRep reply;
223
    reply = (Monitor_GetDMQSettingsRep) AdminModule.doRequest(request);
224
 
225
    if (reply.getThreshold() == null)
226
      return -1;
227
    else
228
      return reply.getThreshold().intValue();
229
  }
230
 
231
 
232
  /** Returns the identifier of the user's proxy. */
233
  public String getProxyId()
234
  {
235
    return proxyId;
236
  }
237
 
238
  /** Sets the naming reference of this user. */
239
  public Reference getReference() throws NamingException
240
  {
241
    Reference ref = super.getReference();
242
    ref.add(new StringRefAddr("user.name", name));
243
    ref.add(new StringRefAddr("user.id", proxyId));
244
    return ref;
245
  }
246
 
247
  /**
248
   * Codes an <code>User</code> instance as a Hashtable for travelling
249
   * through the SOAP protocol.
250
   */
251
  public Hashtable code() {
252
    Hashtable h = super.code();
253
    h.put("name",name);
254
    h.put("proxyId",proxyId);
255
    return h;
256
  }
257
 
258
  /**
259
   * Decodes an <code>User</code> which travelled through the SOAP protocol.
260
   */
261
  public Object decode(Hashtable h) {
262
    return new User((String) h.get("name"), (String) h.get("proxyId"));
263
  }
264
}