@Override
    public void execute(@Nonnull SessionData sessionData, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(sessionData.getOwner());

        Element note = command.addElement("note");
        // Check if users cannot be modified (backend is read-only)
        if (UserManager.getUserProvider().isReadOnly()) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.user.deleteuser.note.users-readonly", preferredLocale));
            return;
        }
        Map<String, List<String>> data = sessionData.getData();

        // Let's create the jids and check that they are a local user
        boolean requestError = false;
        final List<User> toDelete = new ArrayList<>();
        for ( final String accountjid : data.get( "accountjids" ))
        {
            JID account;
            try
            {
                account = new JID( accountjid );

                if ( !XMPPServer.getInstance().isLocal( account ) )
                {
                    note.addAttribute( "type", "error" );
                    note.setText( LocaleUtils.getLocalizedString("commands.admin.user.deleteuser.note.jid-not-local", List.of(accountjid), preferredLocale));
                    requestError = true;
                }
                else
                {
                    User user = UserManager.getInstance().getUser( account.getNode() );
                    toDelete.add( user );
                }
            }
            catch (IllegalArgumentException e) {
                note.addAttribute("type", "error");
                note.setText(LocaleUtils.getLocalizedString("commands.admin.user.deleteuser.note.jid-invalid", preferredLocale));
                return;
            }
            catch ( NullPointerException npe )
            {
                note.addAttribute( "type", "error" );
                note.setText(LocaleUtils.getLocalizedString("commands.admin.user.deleteuser.note.jid-required", preferredLocale));
                requestError = true;
            }
            catch ( UserNotFoundException e )
            {
                note.addAttribute( "type", "error" );
                note.setText( LocaleUtils.getLocalizedString("commands.admin.user.deleteuser.note.user-does-not-exist", List.of(accountjid), preferredLocale));
                requestError = true;
            }
        }

        if ( requestError )
        {
            // We've collected all errors. Return without deleting anything.
            return;
        }

        // No errors. Delete all users.
        for ( final User user : toDelete ) {
            UserManager.getInstance().deleteUser(user);
        }

        // Answer that the operation was successful
        note.addAttribute("type", "info");
        note.setText(LocaleUtils.getLocalizedString("commands.global.operation.finished.success", preferredLocale));
    }
Delete a user from Openfire if the provider is not read-only. See

@author John Georgiadis
@see <a href="https://xmpp.org/extensions/xep-0133.html#delete-user">XEP-0133 Service Administration: Delete User</a>
xmppserver/src/main/java/org/jivesoftware/openfire/commands/admin/user/DeleteUser.java