1. 基于xml的配置方式
Example Security Constraint
Protected Area
/*
DELETE
HEAD
PUT
2. springboot项目,容器是jetty,版本 springboot 2.X
@Bean
public JettyServletWebServerFactory createJettyServletWebServerFactory() {
return new JettyServletWebServerFactory(){
@Override
protected void postProcessWebAppContext(WebAppContext webAppContext) {
HttpConstraintElement disable = new HttpConstraintElement(ServletSecurity.EmptyRoleSemantic.DENY);
HttpMethodConstraintElement put = new HttpMethodConstraintElement("PUT", disable);
HttpMethodConstraintElement delete = new HttpMethodConstraintElement("DELETE", disable);
HttpMethodConstraintElement head = new HttpMethodConstraintElement("HEAD", disable);
ServletSecurityElement sse = new ServletSecurityElement(Arrays.asList(put, delete, head));
List mappings = ConstraintSecurityHandler.createConstraintsWithMappingsForPath("disable", "/*", sse);
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setConstraintMappings(mappings);
webAppContext.setSecurityHandler(csh);
}
};
}
————————————————
原文链接:https://blog.csdn.net/shuipinglp/article/details/102812710