use of com.sun.enterprise.deployment.web.WebResourceCollection in project Payara by payara.
the class DynamicWebServletRegistrationImpl method processServletSecurityElement.
void processServletSecurityElement(ServletSecurityElement servletSecurityElement, WebBundleDescriptor wbd, WebComponentDescriptor wcd) {
Set<String> urlPatterns = ServletSecurityHandler.getUrlPatternsWithoutSecurityConstraint(wcd);
if (urlPatterns.size() > 0) {
SecurityConstraint securityConstraint = ServletSecurityHandler.createSecurityConstraint(wbd, urlPatterns, servletSecurityElement.getRolesAllowed(), servletSecurityElement.getEmptyRoleSemantic(), servletSecurityElement.getTransportGuarantee(), null);
// we know there is one WebResourceCollection there
WebResourceCollection webResColl = securityConstraint.getWebResourceCollections().iterator().next();
for (HttpMethodConstraintElement httpMethodConstraintElement : servletSecurityElement.getHttpMethodConstraints()) {
String httpMethod = httpMethodConstraintElement.getMethodName();
ServletSecurityHandler.createSecurityConstraint(wbd, urlPatterns, httpMethodConstraintElement.getRolesAllowed(), httpMethodConstraintElement.getEmptyRoleSemantic(), httpMethodConstraintElement.getTransportGuarantee(), httpMethod);
// exclude this from the top level constraint
webResColl.addHttpMethodOmission(httpMethod);
}
}
}
use of com.sun.enterprise.deployment.web.WebResourceCollection in project Payara by payara.
the class ServletSecurityHandler method getUrlPatternsWithoutSecurityConstraint.
/**
* Given a WebComponentDescriptor, find the set of urlPattern which does not have
* any existing url pattern in SecurityConstraint
* @param webCompDesc
* @return a list of url String
*/
public static Set<String> getUrlPatternsWithoutSecurityConstraint(WebComponentDescriptor webCompDesc) {
Set<String> urlPatternsWithoutSC = new HashSet<String>(webCompDesc.getUrlPatternsSet());
WebBundleDescriptor webBundleDesc = webCompDesc.getWebBundleDescriptor();
Enumeration<SecurityConstraint> eSecConstr = webBundleDesc.getSecurityConstraints();
while (eSecConstr.hasMoreElements()) {
SecurityConstraint sc = eSecConstr.nextElement();
for (WebResourceCollection wrc : sc.getWebResourceCollections()) {
urlPatternsWithoutSC.removeAll(wrc.getUrlPatterns());
}
}
return urlPatternsWithoutSC;
}
use of com.sun.enterprise.deployment.web.WebResourceCollection in project Payara by payara.
the class WebBundleDescriptorImpl method combineSecurityConstraints.
@Override
protected void combineSecurityConstraints(Set<SecurityConstraint> firstScSet, Set<SecurityConstraint> secondScSet) {
Set<String> allUrlPatterns = new HashSet<String>();
for (SecurityConstraint sc : firstScSet) {
for (WebResourceCollection wrc : sc.getWebResourceCollections()) {
allUrlPatterns.addAll(wrc.getUrlPatterns());
}
}
for (SecurityConstraint sc : secondScSet) {
SecurityConstraint newSc = new SecurityConstraintImpl((SecurityConstraintImpl) sc);
boolean addSc = false;
Iterator<WebResourceCollection> iter = newSc.getWebResourceCollections().iterator();
while (iter.hasNext()) {
WebResourceCollection wrc = iter.next();
Set<String> urlPatterns = wrc.getUrlPatterns();
urlPatterns.removeAll(allUrlPatterns);
boolean isEmpty = (urlPatterns.isEmpty());
addSc = (addSc || (!isEmpty));
if (isEmpty) {
iter.remove();
}
}
if (addSc) {
firstScSet.add(newSc);
}
}
}
Aggregations