@Override
    @Nonnull
    public MUCRoom getChatRoom(@Nonnull final String roomName, @Nonnull final JID userjid) throws NotAllowedException {
        MUCRoom room;
        boolean loaded = false;
        boolean created = false;
        final Lock lock = localMUCRoomManager.getLock(roomName);
        lock.lock();
        try {
            room = localMUCRoomManager.get(roomName);
            if (room == null) {

                // Has the room been deleted and retired?
                if (MUCPersistenceManager.isRoomRetired(roomName, this)) {
                    throw new NotAllowedException(ROOM_RETIRED);
                }

                room = new MUCRoom(this, roomName);
                // If the room is persistent load the configuration values from the DB
                try {
                    // Try to load the room's configuration from the database (if the room is
                    // persistent but was added to the DB after the server was started up or the
                    // room may be an old room that was not present in memory)
                    MUCPersistenceManager.loadFromDB(room);
                    loaded = true;
                }
                catch (final IllegalArgumentException e) {
                    // Check if room needs to be recreated in case it failed to be created previously
                    // (or was deleted somehow and is expected to exist by a delegate).
                    if (mucEventDelegate != null && mucEventDelegate.shouldRecreate(roomName, userjid)) {
                        if (mucEventDelegate.loadConfig(room)) {
                            loaded = true;
                            if (room.isPersistent()) {
                                MUCPersistenceManager.saveToDB(room);
                            }
                        }
                        else {
                            // Room does not exist and delegate does not recognize it and does
                            // not allow room creation
                            throw new NotAllowedException();

                        }
                    }
                    else {
                        // The room does not exist so check for creation permissions
                        if (!isAllowedToCreate(userjid)) {
                            throw new NotAllowedException();
                        }
                        room.addFirstOwner(userjid);
                        created = true;
                    }
                }
                localMUCRoomManager.add(room);
            }
        } finally {
            lock.unlock();
        }
        if (created) {
            // Fire event that a new room has been created
            MUCEventDispatcher.roomCreated(room.getID(), room.getSelfRepresentation().getOccupantJID());
        }
        if (loaded || created) {
            // Initiate FMUC, when enabled.
            room.getFmucHandler().applyConfigurationChanges();
        }
        return room;
    }
Checks if a particular JID is allowed to create rooms.

@param jid The jid for which to check (cannot be null).
@return true if the JID is allowed to create a room, otherwise false.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/MultiUserChatServiceImpl.java