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 && (methodRA == null || methodRA.length == 0)) {
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(method);
// Determine pattern set
String[] urlPatterns = wrapper.findMappings();
Set<String> servletSecurityPatterns = new HashSet<String>();
for (String urlPattern : urlPatterns) {
if (!excludedPatterns.contains(urlPattern)) {
servletSecurityPatterns.add(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 && (classRA == null || classRA.length == 0)) {
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) {
if (!excludedPatterns.contains(urlPattern)) {
servletSecurityPatterns.add(urlPattern);
}
}
for (String urlPattern : servletSecurityPatterns) {
collection.addPattern(urlPattern);
}
for (String methodOmission : methodOmissions) {
collection.addMethodOmission(methodOmission);
}
constraint.addCollection(collection);
context.addConstraint(constraint);
}
}
}