스프링 부트시 금지 된 403 문제를 처리하는 데 문제가 있습니다. WebSecurityConfigurerAdapter를 확장하여 클래스를 처리하여 커스 터 마이징했다. 금지 된 출력을 제공하고있다. 403 URL로 리디렉션되어야하지만 작동하지 않습니다. 나는 초보자이며 어디서 잘못인지 모른다. 스프링 부트 주석에 403 금지 된 오류를 처리하는 방법은 무엇입니까?
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(SecurityConfiguration.class);
ctx.setServletContext(servletContext);
//ctx.register(SecurityConfiguration.class);
DispatcherServlet dispatcherServlet = new DispatcherServlet(ctx);
dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
Dynamic dynamic = servletContext.addServlet("dispatcher", dispatcherServlet);
dynamic.addMapping("/data/*");
dynamic.setLoadOnStartup(1);
}
}
내 appconfig가 클래스
package com.portal.spring.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@ComponentScan("com.portal")
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
}
및 보안 설정
package com.portal.spring.config;
import java.util.logging.Logger;
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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final Logger log= Logger.getLogger(SecurityConfiguration.class.getName());
@Override
protected void configure(HttpSecurity http) throws Exception {
http.exceptionHandling().accessDeniedHandler(new AccessDenyHandler());
}
}
하고 여기에
package com.portal.spring.config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
public class AccessDenyHandler implements AccessDeniedHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException arg2) throws IOException, ServletException {
response.sendRedirect("//403");
}
}
더 자세히 설명해주십시오. 왜 그것이 작동하지 않는다고 생각하십니까 –
@SangramJadhav ... 나는 예외가 없다는 것을 알지 못합니다. 403 금지 된 문제를 처리하는 올바른 방법입니까 –