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 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);
|
private static final Logger logger = Logger.getLogger(KeycloakApplication.class);
|
||||||
|
|
||||||
protected boolean embedded = false;
|
protected boolean embedded = false;
|
||||||
|
@ -107,8 +109,6 @@ public class KeycloakApplication extends Application {
|
||||||
protected KeycloakSessionFactory sessionFactory;
|
protected KeycloakSessionFactory sessionFactory;
|
||||||
protected String contextPath;
|
protected String contextPath;
|
||||||
|
|
||||||
private AtomicBoolean bootstrapAdminUser = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
public KeycloakApplication() {
|
public KeycloakApplication() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -197,7 +197,7 @@ public class KeycloakApplication extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void run(KeycloakSession session) {
|
public void run(KeycloakSession session) {
|
||||||
boolean shouldBootstrapAdmin = new ApplianceBootstrap(session).isNoMasterUser();
|
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;
|
return singletons;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isBootstrap() {
|
|
||||||
return bootstrapAdminUser.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void importRealms() {
|
public void importRealms() {
|
||||||
String files = System.getProperty("keycloak.import");
|
String files = System.getProperty("keycloak.import");
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
|
|
|
@ -68,17 +68,12 @@ public class WelcomeResource {
|
||||||
|
|
||||||
private static final String KEYCLOAK_STATE_CHECKER = "WELCOME_STATE_CHECKER";
|
private static final String KEYCLOAK_STATE_CHECKER = "WELCOME_STATE_CHECKER";
|
||||||
|
|
||||||
private boolean bootstrap = true;
|
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
protected HttpHeaders headers;
|
protected HttpHeaders headers;
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
private KeycloakSession session;
|
private KeycloakSession session;
|
||||||
|
|
||||||
@Context
|
|
||||||
private KeycloakApplication application;
|
|
||||||
|
|
||||||
public WelcomeResource() {
|
public WelcomeResource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +102,7 @@ public class WelcomeResource {
|
||||||
public Response createUser(final MultivaluedMap<String, String> formData) {
|
public Response createUser(final MultivaluedMap<String, String> formData) {
|
||||||
checkBootstrap();
|
checkBootstrap();
|
||||||
|
|
||||||
if (!bootstrap) {
|
if (!shouldBootstrap()) {
|
||||||
return createWelcomePage(null, null);
|
return createWelcomePage(null, null);
|
||||||
} else {
|
} else {
|
||||||
if (!isLocal()) {
|
if (!isLocal()) {
|
||||||
|
@ -141,7 +136,7 @@ public class WelcomeResource {
|
||||||
|
|
||||||
ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session);
|
ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session);
|
||||||
if (applianceBootstrap.isNoMasterUser()) {
|
if (applianceBootstrap.isNoMasterUser()) {
|
||||||
bootstrap = false;
|
setBootstrap(false);
|
||||||
applianceBootstrap.createMasterRealmUser(username, password);
|
applianceBootstrap.createMasterRealmUser(username, password);
|
||||||
|
|
||||||
ServicesLogger.LOGGER.createdInitialAdminUser(username);
|
ServicesLogger.LOGGER.createdInitialAdminUser(username);
|
||||||
|
@ -179,20 +174,21 @@ public class WelcomeResource {
|
||||||
|
|
||||||
private Response createWelcomePage(String successMessage, String errorMessage) {
|
private Response createWelcomePage(String successMessage, String errorMessage) {
|
||||||
try {
|
try {
|
||||||
Theme theme = getTheme();
|
Theme theme = getTheme();
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
map.put("productName", Version.NAME);
|
map.put("productName", Version.NAME);
|
||||||
map.put("productNameFull", Version.NAME_FULL);
|
map.put("productNameFull", Version.NAME_FULL);
|
||||||
|
|
||||||
map.put("properties", theme.getProperties());
|
map.put("properties", theme.getProperties());
|
||||||
|
|
||||||
URI uri = Urls.themeRoot(session.getContext().getUri().getBaseUri());
|
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);
|
map.put("resourcesPath", resourcesPath);
|
||||||
|
|
||||||
map.put("bootstrap", bootstrap);
|
boolean bootstrap = shouldBootstrap();
|
||||||
|
map.put("bootstrap", bootstrap);
|
||||||
if (bootstrap) {
|
if (bootstrap) {
|
||||||
boolean isLocal = isLocal();
|
boolean isLocal = isLocal();
|
||||||
map.put("localUser", isLocal);
|
map.put("localUser", isLocal);
|
||||||
|
@ -230,9 +226,16 @@ public class WelcomeResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBootstrap() {
|
private void checkBootstrap() {
|
||||||
if (bootstrap && application.isBootstrap()) {
|
if (shouldBootstrap())
|
||||||
bootstrap = new ApplianceBootstrap(session).isNoMasterUser();
|
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() {
|
private boolean isLocal() {
|
||||||
|
|
Loading…
Reference in a new issue