refactor(all): change sql to postgresql
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user