Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
smthing committed Feb 8, 2025
1 parent 55c88da commit 51f6735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,33 +242,32 @@ private void initContainer(DeploymentInfo deploymentInfo) throws ServletExceptio
servletContext.addListener0(clazz.newInstance(), false);
}
deploymentInfo.getHandlesTypesLoader().getServlets().forEach(servletInfo -> {
//当 在便携式部署描述符中的一个 security-constraint 包含一个 url-pattern ,其精确匹配 一个使用
//@ServletSecurity 注解的模式映射到的类,该注解必须不影响 Servlet 容器在该模式上实施的强制约束。
List<String> patterns = deploymentInfo.getHandlesTypesLoader().getServletMappings().get(servletInfo.getServletName());
if (patterns == null) {
patterns = Collections.emptyList();
}
ServletInfo webXmlInfo = deploymentInfo.getServlets().get(servletInfo.getServletName());
if (webXmlInfo != null) {

servletInfo.getInitParams().forEach(webXmlInfo::addInitParam);
webXmlInfo.getSecurityConstraints().addAll(servletInfo.getSecurityConstraints());
webXmlInfo.getSecurityRoles().putAll(servletInfo.getSecurityRoles());
servletInfo = webXmlInfo;

} else {
webXmlInfo = servletInfo;
deploymentInfo.addServlet(servletInfo);
}
//当 在便携式部署描述符中的一个 security-constraint 包含一个 url-pattern ,其精确匹配 一个使用
//@ServletSecurity 注解的模式映射到的类,该注解必须不影响 Servlet 容器在该模式上实施的强制约束。
List<String> patterns = deploymentInfo.getHandlesTypesLoader().getServletMappings().get(servletInfo.getServletName());
if (patterns == null) {
patterns = Collections.emptyList();
}
for (String pattern : patterns) {
servletInfo.addServletMapping(pattern, this);
webXmlInfo.addServletMapping(pattern, this);
boolean exists = deploymentInfo.getSecurityConstraints().stream().anyMatch(securityConstraint -> securityConstraint.getUrlPatterns().stream().map(UrlPattern::getUrlPattern).toList().contains(pattern));
if (!exists) {
servletInfo.getSecurityConstraints().forEach(securityConstraint -> {
securityConstraint.getUrlPatterns().add(new UrlPattern(pattern));
deploymentInfo.getSecurityConstraints().add(securityConstraint);
});
}

}

});
deploymentInfo.getHandlesTypesLoader().getFilters().forEach(deploymentInfo::addFilter);
deploymentInfo.getHandlesTypesLoader().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ public List<ServletMappingInfo> getServletMappings() {
}

public void addServletMapping(String urlPattern, ServletContextRuntime runtime) {
if (servletMappings.stream().anyMatch(servletMapping -> servletMapping.getUrlPattern().equals(urlPattern))) {
return;
}
ServletMappingInfo servletMappingInfo = new ServletMappingInfo(this, urlPattern);
if (servletMappingInfo.getMappingMatch() != null) {
servletMappings.add(servletMappingInfo);
Expand Down

0 comments on commit 51f6735

Please sign in to comment.