mirror of https://github.com/halo-dev/halo
Refactor system configuration (#1303)
* Refactor application*.yml * Remove application-user.yaml * Fix invalid config for aspectpull/1305/head
parent
c6a8757436
commit
caab2f3b93
|
@ -28,8 +28,7 @@ public class DisableOnConditionAspect {
|
||||||
this.haloProperties = haloProperties;
|
this.haloProperties = haloProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("execution(* run.halo.app.controller.*.*(..)) "
|
@Pointcut("within(run.halo.app.controller..*)")
|
||||||
+ "&& @annotation(run.halo.app.annotation.DisableOnCondition)")
|
|
||||||
public void pointcut() {
|
public void pointcut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import run.halo.app.security.context.SecurityContextHolder;
|
||||||
public class SensitiveConcealAspect {
|
public class SensitiveConcealAspect {
|
||||||
|
|
||||||
|
|
||||||
@Pointcut("execution(* run.halo.app.repository.*.*(..)) "
|
@Pointcut("within(run.halo.app.repository..*) "
|
||||||
+ "&& @annotation(run.halo.app.annotation.SensitiveConceal)")
|
+ "&& @annotation(run.halo.app.annotation.SensitiveConceal)")
|
||||||
public void pointCut() {
|
public void pointCut() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
|
@ -38,17 +37,20 @@ import run.halo.app.utils.HttpClientUtils;
|
||||||
BaseRepositoryImpl.class)
|
BaseRepositoryImpl.class)
|
||||||
public class HaloConfiguration {
|
public class HaloConfiguration {
|
||||||
|
|
||||||
@Autowired
|
private final HaloProperties haloProperties;
|
||||||
private HaloProperties haloProperties;
|
|
||||||
|
public HaloConfiguration(HaloProperties haloProperties) {
|
||||||
|
this.haloProperties = haloProperties;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||||
builder.failOnEmptyBeans(false);
|
builder.failOnEmptyBeans(false);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RestTemplate httpsRestTemplate(RestTemplateBuilder builder)
|
RestTemplate httpsRestTemplate(RestTemplateBuilder builder)
|
||||||
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||||
RestTemplate httpsRestTemplate = builder.build();
|
RestTemplate httpsRestTemplate = builder.build();
|
||||||
httpsRestTemplate.setRequestFactory(
|
httpsRestTemplate.setRequestFactory(
|
||||||
|
@ -59,7 +61,7 @@ public class HaloConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public AbstractStringCacheStore stringCacheStore() {
|
AbstractStringCacheStore stringCacheStore() {
|
||||||
AbstractStringCacheStore stringCacheStore;
|
AbstractStringCacheStore stringCacheStore;
|
||||||
switch (haloProperties.getCache()) {
|
switch (haloProperties.getCache()) {
|
||||||
case "level":
|
case "level":
|
||||||
|
|
|
@ -25,15 +25,17 @@ public class HaloProperties {
|
||||||
/**
|
/**
|
||||||
* Doc api disabled. (Default is true)
|
* Doc api disabled. (Default is true)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private boolean docDisabled = true;
|
private boolean docDisabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Production env. (Default is true)
|
* Production env. (Default is true)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private boolean productionEnv = true;
|
private boolean productionEnv = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authentication enabled
|
* Authentication enabled.
|
||||||
*/
|
*/
|
||||||
private boolean authEnabled = true;
|
private boolean authEnabled = true;
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
Path themePath = themeService.getBasePath();
|
Path themePath = themeService.getBasePath();
|
||||||
|
|
||||||
// Fix the problem that the project cannot start after moving to a new server
|
// Fix the problem that the project cannot start after moving to a new server
|
||||||
if (!haloProperties.isProductionEnv() || Files.notExists(themePath)) {
|
if (!haloProperties.getMode().isProductionEnv() || Files.notExists(themePath)) {
|
||||||
FileUtils.copyFolder(source, themePath);
|
FileUtils.copyFolder(source, themePath);
|
||||||
log.debug("Copied theme folder from [{}] to [{}]", source, themePath);
|
log.debug("Copied theme folder from [{}] to [{}]", source, themePath);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package run.halo.app.model.enums;
|
package run.halo.app.model.enums;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
@ -13,22 +14,22 @@ import org.springframework.lang.Nullable;
|
||||||
public enum Mode {
|
public enum Mode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Production mode
|
* Production mode.
|
||||||
*/
|
*/
|
||||||
PRODUCTION,
|
PRODUCTION,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Develop mode
|
* Develop mode.
|
||||||
*/
|
*/
|
||||||
DEVELOPMENT,
|
DEVELOPMENT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demo mode
|
* Demo mode.
|
||||||
*/
|
*/
|
||||||
DEMO,
|
DEMO,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test mode
|
* Test mode.
|
||||||
*/
|
*/
|
||||||
TEST;
|
TEST;
|
||||||
|
|
||||||
|
@ -57,4 +58,9 @@ public enum Mode {
|
||||||
String getValue() {
|
String getValue() {
|
||||||
return this.name().toLowerCase();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isProductionEnv() {
|
||||||
|
return PRODUCTION.equals(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
||||||
// Create default authentication failure handler
|
// Create default authentication failure handler
|
||||||
DefaultAuthenticationFailureHandler failureHandler =
|
DefaultAuthenticationFailureHandler failureHandler =
|
||||||
new DefaultAuthenticationFailureHandler();
|
new DefaultAuthenticationFailureHandler();
|
||||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||||
|
|
||||||
this.failureHandler = failureHandler;
|
this.failureHandler = failureHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class AdminAuthenticationFilter extends AbstractAuthenticationFilter {
|
||||||
// set failure handler
|
// set failure handler
|
||||||
DefaultAuthenticationFailureHandler failureHandler =
|
DefaultAuthenticationFailureHandler failureHandler =
|
||||||
new DefaultAuthenticationFailureHandler();
|
new DefaultAuthenticationFailureHandler();
|
||||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||||
failureHandler.setObjectMapper(objectMapper);
|
failureHandler.setObjectMapper(objectMapper);
|
||||||
|
|
||||||
setFailureHandler(failureHandler);
|
setFailureHandler(failureHandler);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {
|
||||||
// set failure handler
|
// set failure handler
|
||||||
DefaultAuthenticationFailureHandler failureHandler =
|
DefaultAuthenticationFailureHandler failureHandler =
|
||||||
new DefaultAuthenticationFailureHandler();
|
new DefaultAuthenticationFailureHandler();
|
||||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||||
failureHandler.setObjectMapper(objectMapper);
|
failureHandler.setObjectMapper(objectMapper);
|
||||||
setFailureHandler(failureHandler);
|
setFailureHandler(failureHandler);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {
|
||||||
Optional<String> optionalAccessKey =
|
Optional<String> optionalAccessKey =
|
||||||
optionService.getByProperty(ApiProperties.API_ACCESS_KEY, String.class);
|
optionService.getByProperty(ApiProperties.API_ACCESS_KEY, String.class);
|
||||||
|
|
||||||
if (!optionalAccessKey.isPresent()) {
|
if (optionalAccessKey.isEmpty()) {
|
||||||
// If the access key is not set
|
// If the access key is not set
|
||||||
throw new AuthenticationException("API access key hasn't been set by blogger");
|
throw new AuthenticationException("API access key hasn't been set by blogger");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,63 +6,9 @@ server:
|
||||||
spring:
|
spring:
|
||||||
jackson:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
devtools:
|
|
||||||
add-properties: false
|
|
||||||
output:
|
|
||||||
ansi:
|
|
||||||
enabled: always
|
|
||||||
datasource:
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
|
|
||||||
# H2 database configuration.
|
|
||||||
driver-class-name: org.h2.Driver
|
|
||||||
url: jdbc:h2:file:~/halo-demo/db/halo
|
|
||||||
username: admin
|
|
||||||
password: 123456
|
|
||||||
|
|
||||||
# MySQL database configuration.
|
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
|
||||||
# username: root
|
|
||||||
# password: 123456
|
|
||||||
|
|
||||||
h2:
|
|
||||||
console:
|
|
||||||
settings:
|
|
||||||
web-allow-others: false
|
|
||||||
path: /h2-console
|
|
||||||
enabled: false
|
|
||||||
jpa:
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: update
|
|
||||||
show-sql: false
|
|
||||||
open-in-view: false
|
|
||||||
flyway:
|
|
||||||
enabled: false
|
|
||||||
servlet:
|
|
||||||
multipart:
|
|
||||||
max-file-size: 10240MB
|
|
||||||
max-request-size: 10240MB
|
|
||||||
management:
|
|
||||||
endpoints:
|
|
||||||
web:
|
|
||||||
base-path: /api/admin/actuator
|
|
||||||
exposure:
|
|
||||||
include: [ 'httptrace', 'metrics','env','logfile','health' ]
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
run.halo.app: INFO
|
|
||||||
file:
|
|
||||||
path: ${user.home}/halo-demo/logs
|
|
||||||
|
|
||||||
springfox:
|
|
||||||
documentation:
|
|
||||||
enabled: true
|
|
||||||
|
|
||||||
halo:
|
halo:
|
||||||
download-timeout: 5m
|
download-timeout: 5m
|
||||||
doc-disabled: false
|
|
||||||
production-env: false
|
|
||||||
auth-enabled: true
|
auth-enabled: true
|
||||||
mode: demo
|
mode: demo
|
||||||
workDir: ${user.home}/halo-demo/
|
workDir: ${user.home}/halo-demo/
|
||||||
|
|
|
@ -2,13 +2,16 @@ server:
|
||||||
port: 8090
|
port: 8090
|
||||||
forward-headers-strategy: native
|
forward-headers-strategy: native
|
||||||
compression:
|
compression:
|
||||||
enabled: false
|
enabled: true
|
||||||
spring:
|
spring:
|
||||||
jackson:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
output:
|
output:
|
||||||
ansi:
|
ansi:
|
||||||
enabled: always
|
enabled: always
|
||||||
|
devtools:
|
||||||
|
restart:
|
||||||
|
eanbled: true
|
||||||
datasource:
|
datasource:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
|
|
||||||
|
@ -56,15 +59,9 @@ logging:
|
||||||
org.hibernate.type.descriptor.sql.BasicBinder: INFO
|
org.hibernate.type.descriptor.sql.BasicBinder: INFO
|
||||||
org.hibernate.type.descriptor.sql.BasicExtractor: INFO
|
org.hibernate.type.descriptor.sql.BasicExtractor: INFO
|
||||||
file:
|
file:
|
||||||
path: ${user.home}/halo-dev/logs
|
path: ${halo.work-dir}/newLogs
|
||||||
|
|
||||||
springfox:
|
|
||||||
documentation:
|
|
||||||
enabled: true
|
|
||||||
|
|
||||||
halo:
|
halo:
|
||||||
doc-disabled: false
|
|
||||||
production-env: false
|
|
||||||
auth-enabled: true
|
auth-enabled: true
|
||||||
mode: development
|
mode: development
|
||||||
workDir: ${user.home}/halo-dev/
|
workDir: ${user.home}/halo-dev/
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
server:
|
|
||||||
port: 8090
|
|
||||||
|
|
||||||
# Response data gzip.
|
|
||||||
compression:
|
|
||||||
enabled: false
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
|
|
||||||
# H2 database configuration.
|
|
||||||
driver-class-name: org.h2.Driver
|
|
||||||
url: jdbc:h2:file:~/.halo/db/halo
|
|
||||||
username: admin
|
|
||||||
password: 123456
|
|
||||||
|
|
||||||
# MySQL database configuration.
|
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
|
||||||
# username: root
|
|
||||||
# password: 123456
|
|
||||||
|
|
||||||
# H2 database console configuration.
|
|
||||||
h2:
|
|
||||||
console:
|
|
||||||
settings:
|
|
||||||
web-allow-others: false
|
|
||||||
path: /h2-console
|
|
||||||
enabled: false
|
|
||||||
|
|
||||||
halo:
|
|
||||||
|
|
||||||
# Your admin client path is https://your-domain/{admin-path}
|
|
||||||
admin-path: admin
|
|
||||||
|
|
||||||
# memory, level, redis
|
|
||||||
cache: memory
|
|
|
@ -3,16 +3,15 @@ server:
|
||||||
forward-headers-strategy: native
|
forward-headers-strategy: native
|
||||||
error:
|
error:
|
||||||
include-message: always
|
include-message: always
|
||||||
compression:
|
|
||||||
enabled: false
|
|
||||||
spring:
|
spring:
|
||||||
|
devtools:
|
||||||
|
restart:
|
||||||
|
eanbled: false
|
||||||
mvc:
|
mvc:
|
||||||
pathmatch:
|
pathmatch:
|
||||||
use-suffix-pattern: true
|
use-suffix-pattern: true
|
||||||
jackson:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
devtools:
|
|
||||||
add-properties: false
|
|
||||||
output:
|
output:
|
||||||
ansi:
|
ansi:
|
||||||
enabled: always
|
enabled: always
|
||||||
|
@ -21,20 +20,12 @@ spring:
|
||||||
|
|
||||||
# H2 database configuration.
|
# H2 database configuration.
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
url: jdbc:h2:file:~/.halo/db/halo
|
url: jdbc:h2:file:${halo.work-dir}/db/halo
|
||||||
username: admin
|
username: admin
|
||||||
password: 123456
|
password: 123456
|
||||||
|
|
||||||
h2:
|
|
||||||
console:
|
|
||||||
settings:
|
|
||||||
web-allow-others: false
|
|
||||||
path: /h2-console
|
|
||||||
enabled: false
|
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update
|
ddl-auto: update
|
||||||
show-sql: false
|
|
||||||
open-in-view: false
|
open-in-view: false
|
||||||
flyway:
|
flyway:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
@ -48,20 +39,20 @@ spring:
|
||||||
settings:
|
settings:
|
||||||
auto_import: /common/macro/global_macro.ftl as global
|
auto_import: /common/macro/global_macro.ftl as global
|
||||||
template-loader-path:
|
template-loader-path:
|
||||||
- file:///${halo.work-dir}templates/
|
- file:///${halo.work-dir}/templates/
|
||||||
- classpath:/templates/
|
- classpath:/templates/
|
||||||
management:
|
management:
|
||||||
endpoints:
|
endpoints:
|
||||||
web:
|
web:
|
||||||
base-path: /api/admin/actuator
|
base-path: /api/admin/actuator
|
||||||
exposure:
|
exposure:
|
||||||
include: [ 'httptrace', 'metrics','env','logfile','health' ]
|
include: [ 'httptrace', 'metrics', 'env', 'logfile', 'health' ]
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
run.halo.app: INFO
|
run.halo.app: INFO
|
||||||
org.eclipse.jetty.server.HttpChannel: ERROR
|
org.eclipse.jetty.server.HttpChannel: ERROR
|
||||||
file:
|
file:
|
||||||
path: ${user.home}/.halo/logs
|
path: ${halo.work-dir}/logs
|
||||||
|
|
||||||
springfox:
|
springfox:
|
||||||
documentation:
|
documentation:
|
||||||
|
|
Loading…
Reference in New Issue