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;
|
||||
}
|
||||
|
||||
@Pointcut("execution(* run.halo.app.controller.*.*(..)) "
|
||||
+ "&& @annotation(run.halo.app.annotation.DisableOnCondition)")
|
||||
@Pointcut("within(run.halo.app.controller..*)")
|
||||
public void pointcut() {
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import run.halo.app.security.context.SecurityContextHolder;
|
|||
public class SensitiveConcealAspect {
|
||||
|
||||
|
||||
@Pointcut("execution(* run.halo.app.repository.*.*(..)) "
|
||||
@Pointcut("within(run.halo.app.repository..*) "
|
||||
+ "&& @annotation(run.halo.app.annotation.SensitiveConceal)")
|
||||
public void pointCut() {
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.security.KeyManagementException;
|
|||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
|
@ -38,17 +37,20 @@ import run.halo.app.utils.HttpClientUtils;
|
|||
BaseRepositoryImpl.class)
|
||||
public class HaloConfiguration {
|
||||
|
||||
@Autowired
|
||||
private HaloProperties haloProperties;
|
||||
private final HaloProperties haloProperties;
|
||||
|
||||
public HaloConfiguration(HaloProperties haloProperties) {
|
||||
this.haloProperties = haloProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||
ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||
builder.failOnEmptyBeans(false);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate httpsRestTemplate(RestTemplateBuilder builder)
|
||||
RestTemplate httpsRestTemplate(RestTemplateBuilder builder)
|
||||
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
RestTemplate httpsRestTemplate = builder.build();
|
||||
httpsRestTemplate.setRequestFactory(
|
||||
|
@ -59,7 +61,7 @@ public class HaloConfiguration {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public AbstractStringCacheStore stringCacheStore() {
|
||||
AbstractStringCacheStore stringCacheStore() {
|
||||
AbstractStringCacheStore stringCacheStore;
|
||||
switch (haloProperties.getCache()) {
|
||||
case "level":
|
||||
|
|
|
@ -25,15 +25,17 @@ public class HaloProperties {
|
|||
/**
|
||||
* Doc api disabled. (Default is true)
|
||||
*/
|
||||
@Deprecated
|
||||
private boolean docDisabled = true;
|
||||
|
||||
/**
|
||||
* Production env. (Default is true)
|
||||
*/
|
||||
@Deprecated
|
||||
private boolean productionEnv = true;
|
||||
|
||||
/**
|
||||
* Authentication enabled
|
||||
* Authentication enabled.
|
||||
*/
|
||||
private boolean authEnabled = true;
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
Path themePath = themeService.getBasePath();
|
||||
|
||||
// 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);
|
||||
log.debug("Copied theme folder from [{}] to [{}]", source, themePath);
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.model.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
@ -13,22 +14,22 @@ import org.springframework.lang.Nullable;
|
|||
public enum Mode {
|
||||
|
||||
/**
|
||||
* Production mode
|
||||
* Production mode.
|
||||
*/
|
||||
PRODUCTION,
|
||||
|
||||
/**
|
||||
* Develop mode
|
||||
* Develop mode.
|
||||
*/
|
||||
DEVELOPMENT,
|
||||
|
||||
/**
|
||||
* Demo mode
|
||||
* Demo mode.
|
||||
*/
|
||||
DEMO,
|
||||
|
||||
/**
|
||||
* Test mode
|
||||
* Test mode.
|
||||
*/
|
||||
TEST;
|
||||
|
||||
|
@ -57,4 +58,9 @@ public enum Mode {
|
|||
String getValue() {
|
||||
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
|
||||
DefaultAuthenticationFailureHandler failureHandler =
|
||||
new DefaultAuthenticationFailureHandler();
|
||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
||||
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||
|
||||
this.failureHandler = failureHandler;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class AdminAuthenticationFilter extends AbstractAuthenticationFilter {
|
|||
// set failure handler
|
||||
DefaultAuthenticationFailureHandler failureHandler =
|
||||
new DefaultAuthenticationFailureHandler();
|
||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
||||
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||
failureHandler.setObjectMapper(objectMapper);
|
||||
|
||||
setFailureHandler(failureHandler);
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {
|
|||
// set failure handler
|
||||
DefaultAuthenticationFailureHandler failureHandler =
|
||||
new DefaultAuthenticationFailureHandler();
|
||||
failureHandler.setProductionEnv(haloProperties.isProductionEnv());
|
||||
failureHandler.setProductionEnv(haloProperties.getMode().isProductionEnv());
|
||||
failureHandler.setObjectMapper(objectMapper);
|
||||
setFailureHandler(failureHandler);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {
|
|||
Optional<String> optionalAccessKey =
|
||||
optionService.getByProperty(ApiProperties.API_ACCESS_KEY, String.class);
|
||||
|
||||
if (!optionalAccessKey.isPresent()) {
|
||||
if (optionalAccessKey.isEmpty()) {
|
||||
// If the access key is not set
|
||||
throw new AuthenticationException("API access key hasn't been set by blogger");
|
||||
}
|
||||
|
|
|
@ -6,63 +6,9 @@ server:
|
|||
spring:
|
||||
jackson:
|
||||
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:
|
||||
download-timeout: 5m
|
||||
doc-disabled: false
|
||||
production-env: false
|
||||
auth-enabled: true
|
||||
mode: demo
|
||||
workDir: ${user.home}/halo-demo/
|
||||
|
|
|
@ -2,13 +2,16 @@ server:
|
|||
port: 8090
|
||||
forward-headers-strategy: native
|
||||
compression:
|
||||
enabled: false
|
||||
enabled: true
|
||||
spring:
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
output:
|
||||
ansi:
|
||||
enabled: always
|
||||
devtools:
|
||||
restart:
|
||||
eanbled: true
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
|
||||
|
@ -56,15 +59,9 @@ logging:
|
|||
org.hibernate.type.descriptor.sql.BasicBinder: INFO
|
||||
org.hibernate.type.descriptor.sql.BasicExtractor: INFO
|
||||
file:
|
||||
path: ${user.home}/halo-dev/logs
|
||||
|
||||
springfox:
|
||||
documentation:
|
||||
enabled: true
|
||||
path: ${halo.work-dir}/newLogs
|
||||
|
||||
halo:
|
||||
doc-disabled: false
|
||||
production-env: false
|
||||
auth-enabled: true
|
||||
mode: development
|
||||
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
|
||||
error:
|
||||
include-message: always
|
||||
compression:
|
||||
enabled: false
|
||||
spring:
|
||||
devtools:
|
||||
restart:
|
||||
eanbled: false
|
||||
mvc:
|
||||
pathmatch:
|
||||
use-suffix-pattern: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
devtools:
|
||||
add-properties: false
|
||||
output:
|
||||
ansi:
|
||||
enabled: always
|
||||
|
@ -21,20 +20,12 @@ spring:
|
|||
|
||||
# H2 database configuration.
|
||||
driver-class-name: org.h2.Driver
|
||||
url: jdbc:h2:file:~/.halo/db/halo
|
||||
url: jdbc:h2:file:${halo.work-dir}/db/halo
|
||||
username: admin
|
||||
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
|
||||
|
@ -48,20 +39,20 @@ spring:
|
|||
settings:
|
||||
auto_import: /common/macro/global_macro.ftl as global
|
||||
template-loader-path:
|
||||
- file:///${halo.work-dir}templates/
|
||||
- file:///${halo.work-dir}/templates/
|
||||
- classpath:/templates/
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
base-path: /api/admin/actuator
|
||||
exposure:
|
||||
include: [ 'httptrace', 'metrics','env','logfile','health' ]
|
||||
include: [ 'httptrace', 'metrics', 'env', 'logfile', 'health' ]
|
||||
logging:
|
||||
level:
|
||||
run.halo.app: INFO
|
||||
org.eclipse.jetty.server.HttpChannel: ERROR
|
||||
file:
|
||||
path: ${user.home}/.halo/logs
|
||||
path: ${halo.work-dir}/logs
|
||||
|
||||
springfox:
|
||||
documentation:
|
||||
|
|
Loading…
Reference in New Issue