|| sessionContext.getState().equals(SessionState.AUTHENTICATED)) {
try {
XMLElement query = stanza.getSingleInnerElementsNamed("query", NamespaceURIs.JABBER_IQ_REGISTER);
XMLElement usernameElm = query.getSingleInnerElementsNamed("username", NamespaceURIs.JABBER_IQ_REGISTER);
if(usernameElm == null || usernameElm.getInnerText() == null) throw new XMLSemanticError("Invalid or missing username");
String username = usernameElm.getInnerText().getText();
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());
}