swagger가 403이 뜬다면...
security config에 httpSecurity.authorizeHttpRequests가 잘못되어있는지 확인해보자.
"/swagger-ui/**" 만 있다고 스웨거에서 원래처럼 기능을 테스트해볼 수 없다.
뒤에 쟤네들도 세트이니 같이 허락을 해주자.
.authorizeHttpRequests((auth)->auth
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/webjars/**").permitAll()
.csrf().disable()이 spring security 6.1 이후로 deprecated 되었다.
.csrf(AbstractHttpConfigurer::disable) 이렇게 바꿔주자.
at com.ssafy.gumibom.global.config.JwtAuthenticationFilter.doFilter(JwtAuthenticationFilter.java:31) ~[main/:na]
지겨워
500 에러 그만 떠
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MyUserDetailsService implements UserDetailsService {
@Autowired
private UserRepository userRepository; // 사용자 정보를 조회하기 위한 Repository
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("User not found with username: " + username);
}
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.getAuthorities());
}
}
백팀장님이 해냈다!