refactor(all): change sql to postgresql

This commit is contained in:
merlin
2025-10-31 10:21:36 +08:00
parent 4f84603d82
commit e4f032a7f0
35 changed files with 154 additions and 587 deletions

View File

@@ -13,17 +13,15 @@ public class CustomUserDetails implements UserDetails {
// Getter 和 Setter
@Setter
@Getter
private String u_id;
private Integer u_id;
@Getter
@Setter
private String role;
private Collection<? extends GrantedAuthority> authorities;
public CustomUserDetails(String username, String password, String u_id,String role, Collection<? extends GrantedAuthority> authorities) {
public CustomUserDetails(String username, String password, Integer u_id, Collection<? extends GrantedAuthority> authorities) {
this.username = username;
this.password = password;
this.u_id = u_id;
this.role = role;
this.authorities = authorities;
}

View File

@@ -1,12 +1,12 @@
package xin.merlin.myblog_server.config;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import xin.merlin.myblog_server.entity.Account;
import xin.merlin.myblog_server.service.impl.AccountServiceImpl;
import xin.merlin.myblog_server.entity.User;
import xin.merlin.myblog_server.service.impl.UserServiceImpl;
import java.util.ArrayList;
@@ -14,12 +14,15 @@ import java.util.ArrayList;
public class LoginDetails implements UserDetailsService {
@Autowired
private AccountServiceImpl accountServiceImpl;
private UserServiceImpl userServiceImpl;
@Override
public CustomUserDetails loadUserByUsername(String u_account) throws UsernameNotFoundException {
Account account = accountServiceImpl.getAccountInfo(u_account);
return new CustomUserDetails(account.getU_account(), account.getU_password(),account.getU_id(), account.getRole(),new ArrayList<>());
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("account", u_account);
User user = userServiceImpl.getOne(queryWrapper);
if(user == null) return null;
return new CustomUserDetails(user.getAccount(), user.getPassword(),user.getId(),new ArrayList<>());
}
}

View File

@@ -13,7 +13,6 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import xin.merlin.myblog_server.security.JWTAuthenticationFilter;
import static org.springframework.security.config.Customizer.withDefaults;
@Configuration
@EnableWebSecurity
@@ -25,7 +24,6 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors(withDefaults()) // <<<<<< 这里明确加上 withDefaults()
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authz -> authz
@@ -33,10 +31,8 @@ public class SecurityConfig {
"/login",
"/register",
"/test",
"/admin/login",
"/admin/register",
"/code/sendcode",
"/code/verifycode"
"/code/**",
"/blog/**"
).permitAll()
.anyRequest().authenticated()
)