boolean methodTP = httpMethodConstraint.getTransportGuarantee().equals(TransportGuarantee.CONFIDENTIAL);
String[] methodRA = httpMethodConstraint.getRolesAllowed();
if (methodDA || methodTP || (methodRA != null && methodRA.length > 0))
{
// Define a constraint specific for the method
SecurityConstraint constraint = new SecurityConstraint();
if (methodDA) {
constraint.setAuthConstraint(true);
}
if (methodPA) {
constraint.addAuthRole("*");
}
if (methodRA != null) {
for (String role : methodRA) {
constraint.addAuthRole(role);
}
}
if (methodTP) {
constraint.setUserConstraint(org.apache.catalina.realm.Constants.CONFIDENTIAL_TRANSPORT);
}
SecurityCollection collection = new SecurityCollection();
collection.addMethod(httpMethodConstraint.getMethodName());
// Determine pattern set
String[] urlPatterns = wrapper.findMappings();
Set<String> servletSecurityPatterns = new HashSet<String>();
for (String urlPattern : urlPatterns) {
servletSecurityPatterns.add(urlPattern);
}
SecurityConstraint[] constraints = context.findConstraints();
for (SecurityConstraint constraint2 : constraints) {
for (SecurityCollection collection2 : constraint2.findCollections()) {
for (String urlPattern : collection2.findPatterns()) {
if (servletSecurityPatterns.contains(urlPattern)) {
servletSecurityPatterns.remove(urlPattern);
}
}
}
}
for (String urlPattern : servletSecurityPatterns) {
collection.addPattern(urlPattern);
}
constraint.addCollection(collection);
context.addConstraint(constraint);
}
}
}
if (classDA || classTP || (classRA != null && classRA.length > 0))
{
// Define a constraint for the class
SecurityConstraint constraint = new SecurityConstraint();
if (classPA) {
constraint.addAuthRole("*");
}
if (classDA) {
constraint.setAuthConstraint(true);
}
if (classRA != null) {
for (String role : classRA) {
constraint.addAuthRole(role);
}
}
if (classTP) {
constraint.setUserConstraint(org.apache.catalina.realm.Constants.CONFIDENTIAL_TRANSPORT);
}
SecurityCollection collection = new SecurityCollection();
// Determine pattern set
String[] urlPatterns = wrapper.findMappings();
Set<String> servletSecurityPatterns = new HashSet<String>();
for (String urlPattern : urlPatterns) {
servletSecurityPatterns.add(urlPattern);
}
SecurityConstraint[] constraints = context.findConstraints();
for (SecurityConstraint constraint2 : constraints) {
for (SecurityCollection collection2 : constraint2.findCollections()) {
for (String urlPattern : collection2.findPatterns()) {
if (servletSecurityPatterns.contains(urlPattern)) {
servletSecurityPatterns.remove(urlPattern);
}
}
}
}
for (String urlPattern : servletSecurityPatterns) {
collection.addPattern(urlPattern);
}
for (String methodOmission : methodOmissions) {
collection.addMethodOmission(methodOmission);
}
constraint.addCollection(collection);
context.addConstraint(constraint);
}
}
}