parent
41b0b90746
commit
095ae0ef4c
@ -0,0 +1,31 @@
|
|||||||
|
package com.example.User.Config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
public class SecurityConfig {
|
||||||
|
|
||||||
|
//暂时配置成允许匿名访问
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
http
|
||||||
|
.csrf(csrf -> csrf.disable()) //禁用CSRF保护
|
||||||
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
.anyRequest().permitAll() //并允许所有请求
|
||||||
|
);
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
//密码加密器
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.example.User.Exceptions;
|
||||||
|
|
||||||
|
//处理输入异常
|
||||||
|
public class InvalidInputException extends Exception{
|
||||||
|
public InvalidInputException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.User.Exceptions;
|
||||||
|
|
||||||
|
//处理用户名相同异常
|
||||||
|
public class UserAlreadyExistException extends Exception{
|
||||||
|
public UserAlreadyExistException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
spring.application.name=User
|
spring.application.name=User
|
||||||
|
|
||||||
# ?????
|
#mysql
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/software
|
spring.datasource.url=jdbc:mysql://localhost:3306/software
|
||||||
|
#数据库用户名(请更改为自己设置的)
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
|
#数据库密码(同上)
|
||||||
spring.datasource.password=123456
|
spring.datasource.password=123456
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
# MyBatis ??
|
#MyBatis
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
mybatis.configuration.map-underscore-to-camel-case=true
|
mybatis.configuration.map-underscore-to-camel-case=true
|
Loading…
Reference in new issue