feat: 添加UTF-8编码支持并优化DTO验证
refactor: 重构用户服务密码更新逻辑 fix: 删除不再使用的MarkdownDto类 style: 清理日志文件并优化日志配置 build: 更新pom.xml配置以支持UTF-8编码 docs: 更新application.properties配置文档
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
/**
|
||||
* Spring Security配置类
|
||||
@@ -61,8 +62,10 @@ public class SecurityConfig {
|
||||
.antMatchers(HttpMethod.GET,"/api/markdowns/**").permitAll()
|
||||
.antMatchers(HttpMethod.GET,"/api/articles/**").permitAll()
|
||||
.antMatchers(HttpMethod.GET,"/api/messages/**").permitAll()
|
||||
.antMatchers(HttpMethod.GET,"/api/categories/**").permitAll()
|
||||
// 公开post请求
|
||||
.antMatchers(HttpMethod.POST,"/api/messages/**").permitAll()
|
||||
.antMatchers(HttpMethod.POST,"/api/users/**").permitAll()
|
||||
// 管理员才能访问的路径
|
||||
.antMatchers("/api/admin/**").hasRole("ADMIN")
|
||||
// 其他所有请求都需要认证
|
||||
@@ -72,6 +75,15 @@ public class SecurityConfig {
|
||||
.sessionManagement()
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
|
||||
|
||||
// 确保Spring Security不会添加额外的CharacterEncodingFilter
|
||||
// 因为我们在CharacterEncodingConfig中已经配置了自定义的过滤器
|
||||
http.addFilterBefore((request, response, chain) -> {
|
||||
// 确保响应使用UTF-8编码
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
chain.doFilter(request, response);
|
||||
}, UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user