]> WPIA git - gigi.git/blob - lib/servlet-api/javax/servlet/HttpConstraintElement.java
adding servlet api (from tomcat)
[gigi.git] / lib / servlet-api / javax / servlet / HttpConstraintElement.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package javax.servlet;
18
19 import java.util.ResourceBundle;
20
21 import javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic;
22 import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
23
24 /**
25  * @since Servlet 3.0
26  * TODO SERVLET3 - Add comments
27  */
28 public class HttpConstraintElement {
29
30     private static final String LSTRING_FILE = "javax.servlet.LocalStrings";
31     private static final ResourceBundle lStrings =
32         ResourceBundle.getBundle(LSTRING_FILE);
33
34     private final EmptyRoleSemantic emptyRoleSemantic;// = EmptyRoleSemantic.PERMIT;
35     private final TransportGuarantee transportGuarantee;// = TransportGuarantee.NONE;
36     private final String[] rolesAllowed;// = new String[0];
37
38     /**
39      * Default constraint is permit with no transport guarantee.
40      */
41     public HttpConstraintElement() {
42         // Default constructor
43         this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
44         this.transportGuarantee = TransportGuarantee.NONE;
45         this.rolesAllowed = new String[0];
46     }
47
48     /**
49      * Convenience constructor for {@link EmptyRoleSemantic#DENY}.
50      *
51      */
52     public HttpConstraintElement(EmptyRoleSemantic emptyRoleSemantic) {
53         this.emptyRoleSemantic = emptyRoleSemantic;
54         this.transportGuarantee = TransportGuarantee.NONE;
55         this.rolesAllowed = new String[0];
56     }
57
58     /**
59      * Convenience constructor to specify transport guarantee and/or roles.
60      */
61     public HttpConstraintElement(TransportGuarantee transportGuarantee,
62             String... rolesAllowed) {
63         this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
64         this.transportGuarantee = transportGuarantee;
65         this.rolesAllowed = rolesAllowed;
66     }
67
68     /**
69      *
70      * @param emptyRoleSemantic
71      * @param transportGuarantee
72      * @param rolesAllowed
73      * @throws IllegalArgumentException if roles are specified when DENY is used
74      */
75     public HttpConstraintElement(EmptyRoleSemantic emptyRoleSemantic,
76             TransportGuarantee transportGuarantee, String... rolesAllowed) {
77         if (rolesAllowed != null && rolesAllowed.length > 0 &&
78                 EmptyRoleSemantic.DENY.equals(emptyRoleSemantic)) {
79             throw new IllegalArgumentException(lStrings.getString(
80                     "httpConstraintElement.invalidRolesDeny"));
81         }
82         this.emptyRoleSemantic = emptyRoleSemantic;
83         this.transportGuarantee = transportGuarantee;
84         this.rolesAllowed = rolesAllowed;
85     }
86
87     public EmptyRoleSemantic getEmptyRoleSemantic() {
88         return emptyRoleSemantic;
89     }
90
91     public TransportGuarantee getTransportGuarantee() {
92         return transportGuarantee;
93     }
94
95     public String[] getRolesAllowed() {
96         return rolesAllowed;
97     }
98 }