if (checkServerId(request.getServerId())) {
// If this server is the target server, process the request.
Identity identity = request.getIdentity();
String name = identity.getUserName();
AgentId proxId = (AgentId) proxiesTable.get(name);
String info;
// The user has already been set.
if (proxId != null) {
Identity userIdentity = (Identity) usersTable.get(name);
if (logger.isLoggable(BasicLevel.INFO))
logger.log(BasicLevel.INFO, "User [" + name + "] already exists : " + userIdentity);
try {
if (! userIdentity.check(identity)) {
throw new RequestException("User [" + name + "] already exists"
+ " but with a different password.");
}
} catch (Exception e) {
throw new RequestException("User [" + name + "] already exists :: Exception :" + e.getMessage());
}
info = strbuf.append("Request [").append(request.getClass().getName())
.append("], processed by AdminTopic on server [").append(serverId)
.append("], successful [true]: proxy [").append(proxId.toString())
.append("] of user [").append(name)
.append("] has been retrieved").toString();
strbuf.setLength(0);
} else {
// try {
// if (! identity.validate()) {
// throw new RequestException("User [" + name + "] security validate failed.");
// }
// } catch (Exception e) {
// throw new RequestException(e.getMessage());
// }
UserAgent proxy = new UserAgent();
proxy.setName(name);
proxId = proxy.getId();
// set interceptors.
proxy.setInterceptors(request.getProperties());
try {
// deploy UserAgent
proxy.deploy();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "doProcess CreateUserRequest:: store (in usersTable) this identity = " + identity);
usersTable.put(name, identity);
proxiesTable.put(name, proxy.getId());
info = strbuf.append("Request [").append(request.getClass().getName())
.append("], processed by AdminTopic on server [").append(serverId)
.append("], successful [true]: proxy [")
.append(proxId.toString()).append("] for user [").append(name)
.append("] has been created and deployed").toString();
strbuf.setLength(0);
}
catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "EXCEPTION:: createUser [" + name + "]", exc);
throw new RequestException("User proxy not deployed: " + exc);
}
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, info);
distributeReply(replyTo,
msgId,
new CreateUserReply(proxId.toString(), info));
} else {
// Forward the request to the right AdminTopic agent.
forward(getDefault((short) request.getServerId()),
new FwdAdminRequestNot(request, replyTo, msgId));
}