Example usage for javax.servlet HttpMethodConstraintElement HttpMethodConstraintElement

List of usage examples for javax.servlet HttpMethodConstraintElement HttpMethodConstraintElement

Introduction

In this page you can find the example usage for javax.servlet HttpMethodConstraintElement HttpMethodConstraintElement.

Prototype

public HttpMethodConstraintElement(String methodName, HttpConstraintElement constraint) 

Source Link

Document

Constructs an instance with specified HttpConstraintElement value.

Usage

From source file:com.jsmartframework.web.manager.ContextControl.java

private ServletSecurityElement getServletSecurityElement(ServletContext servletContext) {
    SecureMethod[] secureMethods = CONFIG.getContent().getSecureMethods();

    if (secureMethods != null && secureMethods.length > 0) {

        HttpConstraintElement constraint = new HttpConstraintElement();

        SecureMethod allMethods = CONFIG.getContent().getSecureMethod("*");
        Set<HttpMethodConstraintElement> methodConstraints = new HashSet<HttpMethodConstraintElement>();

        if (allMethods != null) {
            for (String method : METHODS) {
                HttpConstraintElement constraintElement = getHttpConstraintElement(allMethods);
                if (constraintElement != null) {
                    methodConstraints.add(new HttpMethodConstraintElement(method, constraintElement));
                }//w  w  w. ja  v a 2 s .c  o m
            }

        } else {
            for (SecureMethod secureMethod : secureMethods) {
                HttpConstraintElement constraintElement = getHttpConstraintElement(secureMethod);
                if (constraintElement != null) {

                    if (secureMethod.getMethod() == null
                            || !METHODS.contains(secureMethod.getMethod().toUpperCase())) {
                        throw new RuntimeException(
                                "Method name declared in [secure-method] tag is unsupported! Supported values are HTTP methods.");
                    }
                    methodConstraints.add(new HttpMethodConstraintElement(
                            secureMethod.getMethod().toUpperCase(), constraintElement));
                }
            }
        }

        return new ServletSecurityElement(constraint, methodConstraints);
    }

    return null;
}