我正在使用基于 Spring Java 配置的 HDIV 和 Spring MVC,我从他们的展示实现中派生出来。配置已加载,但当我尝试访问受保护的 URL 即“/messages/message”时,我总是收到未经授权的访问错误 HDIV_PARAMETER_DOES_NOT_EXIST。当我更改配置以从 HDIV 处理中排除 URL 时它可以工作,但这当然不是一个选项
有人知道我错过了什么吗?
日志文件错误声明
10:04:17.304 [http-nio-8080-exec-22] INFO org.hdiv.logs.Logger - HDIV_PARAMETER_DOES_NOT_EXIST;/spring-security-example/messages/message;_HDIV_STATE_;;;127.0.0.1;127.0.0.1;megloff;
Java 配置
@Configuration
@EnableHdivWebSecurity
public class HdivSecurityConfig extends HdivWebSecurityConfigurerAdapter {
@Override
public void configure(SecurityConfigBuilder builder) {
}
@Override
public void addExclusions(ExclusionRegistry registry) {
registry.addUrlExclusions("/").method("GET");
registry.addUrlExclusions("/login");
registry.addUrlExclusions("/logout");
registry.addUrlExclusions("/static/.*");
registry.addParamExclusions("_csrf");
// registry.addUrlExclusions("/messages/.*"); <-- would allow access, but not an option
}
@Override
public void configureEditableValidation(ValidationConfigurer validationConfigurer) {
validationConfigurer.addValidation("/messages/.*");
validationConfigurer.addValidation("/addUser");
}
}
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {
"ch.megloff.spring.security.example.mvc.controller",
"ch.megloff.spring.security.example.mvc.action",
"ch.megloff.spring.security.example.repository",
"ch.megloff.spring.security.example.listener",
"ch.megloff.spring.security.example.service"})
public class SpringMVCConfiguration extends WebMvcConfigurerAdapter {
@Autowired
@Qualifier("hdivEditableValidator")
private Validator hdivEditableValidator;
@Override
public Validator getValidator() {
return hdivEditableValidator;
}
...
}
public class SpringWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { SpringMVCConfiguration.class, SpringHibernateConfig.class, SpringSecurityConfiguration.class, SpringSecurityJDBCConfiguration.class, SpringWebFlowConfig.class, HdivSecurityConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { SpringMVCConfiguration.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
public void onStartup(ServletContext container) throws ServletException {
super.onStartup(container);
container.addFilter("ValidatorFilter", ValidatorFilter.class).addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST), false, "/*");
container.addListener(new InitListener());
}
}