/** * Create a user if none exists. * * @param name the short name, must be scrubbed of chars which XWiki doesn't like. * @param fullName name, prefixed with 'XWiki.'. * @param context the ball of mud. * @throws XWikiException if thrown by {@link XWiki#createEmptyUser()}. */ private void createUserIfNeeded( final String name, final String fullName, final XWikiContext context) throws XWikiException { final String database = context.getDatabase(); try { // Switch to main wiki to force users to be global users context.setDatabase(context.getMainXWiki()); final XWiki wiki = context.getWiki(); // test if user already exists if (!wiki.exists(fullName, context)) { LOGGER.info("Need to create user [{0}]", fullName); wiki.createEmptyUser(name, "edit", context); } } finally { context.setDatabase(database); } }