Use global bootstrap flag
This commit is contained in:
parent
11f761ec1f
commit
203646627f
2 changed files with 25 additions and 26 deletions
|
@ -97,6 +97,8 @@ public class KeycloakApplication extends Application {
|
|||
|
||||
public static final String SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES = "keycloak.server.context.config.property-overrides";
|
||||
|
||||
public static final AtomicBoolean BOOTSTRAP_ADMIN_USER = new AtomicBoolean(false);
|
||||
|
||||
private static final Logger logger = Logger.getLogger(KeycloakApplication.class);
|
||||
|
||||
protected boolean embedded = false;
|
||||
|
@ -107,8 +109,6 @@ public class KeycloakApplication extends Application {
|
|||
protected KeycloakSessionFactory sessionFactory;
|
||||
protected String contextPath;
|
||||
|
||||
private AtomicBoolean bootstrapAdminUser = new AtomicBoolean(false);
|
||||
|
||||
public KeycloakApplication() {
|
||||
|
||||
try {
|
||||
|
@ -197,7 +197,7 @@ public class KeycloakApplication extends Application {
|
|||
@Override
|
||||
public void run(KeycloakSession session) {
|
||||
boolean shouldBootstrapAdmin = new ApplianceBootstrap(session).isNoMasterUser();
|
||||
bootstrapAdminUser.set(shouldBootstrapAdmin);
|
||||
BOOTSTRAP_ADMIN_USER.set(shouldBootstrapAdmin);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -385,10 +385,6 @@ public class KeycloakApplication extends Application {
|
|||
return singletons;
|
||||
}
|
||||
|
||||
boolean isBootstrap() {
|
||||
return bootstrapAdminUser.get();
|
||||
}
|
||||
|
||||
public void importRealms() {
|
||||
String files = System.getProperty("keycloak.import");
|
||||
if (files != null) {
|
||||
|
|
|
@ -68,17 +68,12 @@ public class WelcomeResource {
|
|||
|
||||
private static final String KEYCLOAK_STATE_CHECKER = "WELCOME_STATE_CHECKER";
|
||||
|
||||
private boolean bootstrap = true;
|
||||
|
||||
@Context
|
||||
protected HttpHeaders headers;
|
||||
|
||||
@Context
|
||||
private KeycloakSession session;
|
||||
|
||||
@Context
|
||||
private KeycloakApplication application;
|
||||
|
||||
public WelcomeResource() {
|
||||
}
|
||||
|
||||
|
@ -107,7 +102,7 @@ public class WelcomeResource {
|
|||
public Response createUser(final MultivaluedMap<String, String> formData) {
|
||||
checkBootstrap();
|
||||
|
||||
if (!bootstrap) {
|
||||
if (!shouldBootstrap()) {
|
||||
return createWelcomePage(null, null);
|
||||
} else {
|
||||
if (!isLocal()) {
|
||||
|
@ -141,7 +136,7 @@ public class WelcomeResource {
|
|||
|
||||
ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session);
|
||||
if (applianceBootstrap.isNoMasterUser()) {
|
||||
bootstrap = false;
|
||||
setBootstrap(false);
|
||||
applianceBootstrap.createMasterRealmUser(username, password);
|
||||
|
||||
ServicesLogger.LOGGER.createdInitialAdminUser(username);
|
||||
|
@ -189,9 +184,10 @@ public class WelcomeResource {
|
|||
map.put("properties", theme.getProperties());
|
||||
|
||||
URI uri = Urls.themeRoot(session.getContext().getUri().getBaseUri());
|
||||
String resourcesPath = uri.getPath() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName();
|
||||
String resourcesPath = uri.getPath() + "/" + theme.getType().toString().toLowerCase() + "/" + theme.getName();
|
||||
map.put("resourcesPath", resourcesPath);
|
||||
|
||||
boolean bootstrap = shouldBootstrap();
|
||||
map.put("bootstrap", bootstrap);
|
||||
if (bootstrap) {
|
||||
boolean isLocal = isLocal();
|
||||
|
@ -230,9 +226,16 @@ public class WelcomeResource {
|
|||
}
|
||||
|
||||
private void checkBootstrap() {
|
||||
if (bootstrap && application.isBootstrap()) {
|
||||
bootstrap = new ApplianceBootstrap(session).isNoMasterUser();
|
||||
if (shouldBootstrap())
|
||||
KeycloakApplication.BOOTSTRAP_ADMIN_USER.compareAndSet(true, new ApplianceBootstrap(session).isNoMasterUser());
|
||||
}
|
||||
|
||||
private boolean shouldBootstrap() {
|
||||
return KeycloakApplication.BOOTSTRAP_ADMIN_USER.get();
|
||||
}
|
||||
|
||||
private void setBootstrap(boolean value) {
|
||||
KeycloakApplication.BOOTSTRAP_ADMIN_USER.set(value);
|
||||
}
|
||||
|
||||
private boolean isLocal() {
|
||||
|
|
Loading…
Reference in a new issue