inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

안녕하세요. 현재 개발중인 spring security 설정 문의 드립니다.

미해결

안녕하세요 현재 java17 + spring boot 3.0 + gradle 7.7.6 + mybatis로 개발셋팅중인데.. spring security 설정에서 삽질중인데... http://localhost:8088/twinadm/login => 로그인,로그아웃 , 권한체크 잘됨. http://192.168.1.46:8088/twinadm/login => 로그인,로그아웃 안됨. 로그인 하면 org.springframework.security .web.csrf.MissingCsrfTokenException: Could not verify the provided CSRF token because no token was found to compare. 이런에러가 떨어짐. 위와 같이 로컬은 잘되는데 IP 접근시에는 저런에러가 떨어집니다 ㅠㅠ.. 소스 설정은 아래와 같습니다. public class AdminSecurityConfig { private final AdminAccessDeniedHandler adminAccessDeniedHandler; @Autowired public AdminSecurityConfig(AdminAccessDeniedHandler adminAccessDeniedHandler) { this.adminAccessDeniedHandler = adminAccessDeniedHandler; } @Bean public UserDetailsService adminDetailsService(){ return new AdminDetailService(); } @Bean public PasswordEncoder adminPasswordEncoder(){ return new BCryptPasswordEncoder(); } @Bean public DaoAuthenticationProvider adminAuthenticationProvider(){ DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setUserDetailsService(adminDetailsService()); provider.setPasswordEncoder(adminPasswordEncoder()); return provider; } @Bean public SecurityFilterChain adminFilterChain(HttpSecurity http) throws Exception { String[] AnyAuthority = {"ROLE_ADMIN","ROLE_ADMININ"}; http.headers().frameOptions().sameOrigin(); // security 설정 추가 [url x-frame-options : cro] http.headers(headers -> headers.cacheControl(cache -> cache.disable())); http.csrf() .ignoringAntMatchers() .ignoringRequestMatchers(); http // .antMatcher("/admin/**") .authenticationProvider(adminAuthenticationProvider()) // .authorizeHttpRequests().antMatchers("/admin/site/**").hasAnyAuthority("ROLE_ADMIN") // url 마다 권한 처리 .antMatcher("/admin/**") .authorizeRequests(authorize -> authorize .anyRequest() // .hasAuthority("ROLE_ADMIN")) // 단일 권한 .hasAnyAuthority(AnyAuthority)) // 여러권한 .formLogin(login -> login .loginPage("/admin/login") // GET 요청 (login form을 보여줌) .loginProcessingUrl("/admin/adminLoginProc") // POST 요청 (login 창에 입력한 데이터를 처리) .failureUrl("/admin/login?error=true") .usernameParameter("email") // login에 필요한 id 값을 email로 설정 (default는 username) .passwordParameter("password") // login에 필요한 password 값을 password(default)로 설정 .defaultSuccessUrl("/admin").permitAll()); http.exceptionHandling().accessDeniedHandler(adminAccessDeniedHandler); http .logout(logout -> logout .logoutUrl("/admin/adminLogout") .addLogoutHandler((request, response, authentication) -> { HttpSession session = request.getSession(); session.removeAttribute("SPRING_SECURITY_CONTEXT"); }) .invalidateHttpSession(false) .logoutSuccessUrl("/admin/login")); // logout에 성공하면 /로 redirect // 인증 거부 관련 처리 return http.build(); } // @Bean // public AdminSecurityCustomizer adminSecurityCustomizer() { // return (web) -> web.ignoring().antMatchers("/h2-console/**"); // } } 여기서 제가 잘못 설정한게 있을까요? 고수님들께 질문드립니다.. 조언 및 소스 수정의 키워드좀 알려주세요 ㅠㅠ

  • java17
  • springboot
  • securuty
  • 설정
  • csrf
  • 로그인보안설정
hghn0108 댓글 1 좋아요 0 조회수 1430

인기 태그

인프런 TOP Writers

주간 인기글