XMLElement passwordElm = query.getSingleInnerElementsNamed("password", NamespaceURIs.JABBER_IQ_REGISTER);
if(passwordElm == null || passwordElm.getInnerText() == null) throw new XMLSemanticError("Invalid or missing password");
String password = passwordElm.getInnerText().getText();
if(password.trim().length() == 0) throw new XMLSemanticError("Invalid password");
AccountManagement accountManagement = (AccountManagement) serverRuntimeContext.getStorageProvider(AccountManagement.class);
Entity user;
if(username.contains("@")) {
user = EntityImpl.parse(username);
if(!serverRuntimeContext.getServerEnitity().getDomain().equals(user.getDomain())) {
throw new XMLSemanticError("Username must be in the same domain as the server");
}
} else {
user = EntityImpl.parse(username + "@" + serverRuntimeContext.getServerEnitity());
}
if(sessionContext.getState().equals(SessionState.AUTHENTICATED)) {
if(accountManagement.verifyAccountExists(user)) {
// account exists
accountManagement.changePassword(user, password);
} else {
throw new AccountCreationException("Account does not exist");
}
} else {
if(accountManagement.verifyAccountExists(user)) {
// account exists
throw new AccountCreationException("Account already exists");
} else {
accountManagement.addUser(user, password);
}
}
return StanzaBuilder.createDirectReply(stanza, true, IQStanzaType.RESULT).build();
} catch (XMLSemanticError e) {