feature(all): 服务增加配置文件信息加密
This commit is contained in:
@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.service.configuration;
|
||||
|
||||
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -14,11 +16,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
public class JacksonConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JacksonConfiguration.class);
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||
return builder -> {
|
||||
builder.modules(new EclipseCollectionsModule());
|
||||
builder.modules(new JavaTimeModule());
|
||||
builder.modules(
|
||||
new EclipseCollectionsModule(),
|
||||
new JavaTimeModule()
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,13 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
|
||||
|
||||
private final SecurityProperties securityProperties;
|
||||
|
||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||
public SecurityConfig(SecurityProperties securityProperties) {
|
||||
this.securityProperties = securityProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests()
|
||||
@@ -37,8 +44,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder builder) throws Exception {
|
||||
builder.inMemoryAuthentication()
|
||||
.withUser(Constants.SPRING_SECURITY_USERNAME)
|
||||
.password(Constants.SPRING_SECURITY_PASSWORD)
|
||||
.authorities(Constants.SPRING_SECURITY_AUTHORITY);
|
||||
.withUser(securityProperties.getUsername())
|
||||
.password("{noop}" + securityProperties.getDarkcode())
|
||||
.authorities(securityProperties.getAuthority());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.lanyuanxiaoyao.service.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-07-03
|
||||
*/
|
||||
@ConfigurationProperties("spring.security.meta")
|
||||
@Component
|
||||
public class SecurityProperties {
|
||||
private String authority;
|
||||
private String username;
|
||||
private String darkcode;
|
||||
|
||||
public String getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
||||
public void setAuthority(String authority) {
|
||||
this.authority = authority;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getDarkcode() {
|
||||
return darkcode;
|
||||
}
|
||||
|
||||
public void setDarkcode(String darkcode) {
|
||||
this.darkcode = darkcode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SecurityProperties{" +
|
||||
"authority='" + authority + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", darkcode='" + darkcode + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user