Polish "Add support for webAdminPassword property of H2 Console"
See gh-21533
This commit is contained in:
parent
1d40234737
commit
bf96b0c57b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||||
|
import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties.Settings;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
|
|
@ -62,7 +63,7 @@ public class H2ConsoleAutoConfiguration {
|
||||||
String path = properties.getPath();
|
String path = properties.getPath();
|
||||||
String urlMapping = path + (path.endsWith("/") ? "*" : "/*");
|
String urlMapping = path + (path.endsWith("/") ? "*" : "/*");
|
||||||
ServletRegistrationBean<WebServlet> registration = new ServletRegistrationBean<>(new WebServlet(), urlMapping);
|
ServletRegistrationBean<WebServlet> registration = new ServletRegistrationBean<>(new WebServlet(), urlMapping);
|
||||||
configureSettings(properties.getSettings(), registration);
|
configureH2ConsoleSettings(registration, properties.getSettings());
|
||||||
dataSource.ifAvailable((available) -> {
|
dataSource.ifAvailable((available) -> {
|
||||||
try (Connection connection = available.getConnection()) {
|
try (Connection connection = available.getConnection()) {
|
||||||
logger.info("H2 console available at '" + path + "'. Database available at '"
|
logger.info("H2 console available at '" + path + "'. Database available at '"
|
||||||
|
|
@ -75,15 +76,13 @@ public class H2ConsoleAutoConfiguration {
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureSettings(H2ConsoleProperties.Settings settings,
|
private void configureH2ConsoleSettings(ServletRegistrationBean<WebServlet> registration, Settings settings) {
|
||||||
ServletRegistrationBean<WebServlet> registration) {
|
|
||||||
if (settings.isTrace()) {
|
if (settings.isTrace()) {
|
||||||
registration.addInitParameter("trace", "");
|
registration.addInitParameter("trace", "");
|
||||||
}
|
}
|
||||||
if (settings.isWebAllowOthers()) {
|
if (settings.isWebAllowOthers()) {
|
||||||
registration.addInitParameter("webAllowOthers", "");
|
registration.addInitParameter("webAllowOthers", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getWebAdminPassword() != null) {
|
if (settings.getWebAdminPassword() != null) {
|
||||||
registration.addInitParameter("webAdminPassword", settings.getWebAdminPassword());
|
registration.addInitParameter("webAdminPassword", settings.getWebAdminPassword());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -77,6 +77,9 @@ public class H2ConsoleProperties {
|
||||||
*/
|
*/
|
||||||
private boolean webAllowOthers = false;
|
private boolean webAllowOthers = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password to access preferences and tools of H2 Console.
|
||||||
|
*/
|
||||||
private String webAdminPassword;
|
private String webAdminPassword;
|
||||||
|
|
||||||
public boolean isTrace() {
|
public boolean isTrace() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue