Example usage for javax.servlet ServletSecurityElement ServletSecurityElement

List of usage examples for javax.servlet ServletSecurityElement ServletSecurityElement

Introduction

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

Prototype

public ServletSecurityElement(HttpConstraintElement constraint,
        Collection<HttpMethodConstraintElement> methodConstraints) 

Source Link

Document

Constructs an instance with a default Constraint element and with a collection of HTTP Method specific constraint elements.

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));
                }/*from   ww w .  j  a va  2 s.c  om*/
            }

        } 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;
}