/*
* (non-Javadoc)
* @see org.apache.james.protocols.api.CommandHandler#onCommand(org.apache.james.protocols.api.ProtocolSession, org.apache.james.protocols.api.Request)
*/
public Response onCommand(RemoteManagerSession session, Request request) {
RemoteManagerResponse response = null;
String parameters = request.getArgument();
int breakIndex = -1;
if ((parameters == null) ||
(parameters.equals("")) ||
((breakIndex = parameters.indexOf(" ")) < 0)) {
response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
return response;
}
String username = parameters.substring(0,breakIndex);
String passwd = parameters.substring(breakIndex + 1);
if (username.equals("") || passwd.equals("")) {
response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
return response;
}
UsersRepository users = uStore.getRepository((String)session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
User user = users.getUserByName(username);
if (user == null) {
response = new RemoteManagerResponse("No such user " + username);
return response;
}
boolean success = user.setPassword(passwd);
if (success) {
users.updateUser(user);
StringBuilder responseBuffer =
new StringBuilder(64)
.append("Password for ")
.append(username)
.append(" reset");
String responseString = responseBuffer.toString();
response = new RemoteManagerResponse(responseString);
session.getLogger().info(responseString);
} else {
response = new RemoteManagerResponse("Error resetting password");
session.getLogger().error("Error resetting password");
}
return response;
}