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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package javax.servlet;
19 import java.util.ResourceBundle;
21 import javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic;
22 import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
26 * TODO SERVLET3 - Add comments
28 public class HttpConstraintElement {
30 private static final String LSTRING_FILE = "javax.servlet.LocalStrings";
31 private static final ResourceBundle lStrings =
32 ResourceBundle.getBundle(LSTRING_FILE);
34 private final EmptyRoleSemantic emptyRoleSemantic;// = EmptyRoleSemantic.PERMIT;
35 private final TransportGuarantee transportGuarantee;// = TransportGuarantee.NONE;
36 private final String[] rolesAllowed;// = new String[0];
39 * Default constraint is permit with no transport guarantee.
41 public HttpConstraintElement() {
42 // Default constructor
43 this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
44 this.transportGuarantee = TransportGuarantee.NONE;
45 this.rolesAllowed = new String[0];
49 * Convenience constructor for {@link EmptyRoleSemantic#DENY}.
52 public HttpConstraintElement(EmptyRoleSemantic emptyRoleSemantic) {
53 this.emptyRoleSemantic = emptyRoleSemantic;
54 this.transportGuarantee = TransportGuarantee.NONE;
55 this.rolesAllowed = new String[0];
59 * Convenience constructor to specify transport guarantee and/or roles.
61 public HttpConstraintElement(TransportGuarantee transportGuarantee,
62 String... rolesAllowed) {
63 this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
64 this.transportGuarantee = transportGuarantee;
65 this.rolesAllowed = rolesAllowed;
70 * @param emptyRoleSemantic
71 * @param transportGuarantee
73 * @throws IllegalArgumentException if roles are specified when DENY is used
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"));
82 this.emptyRoleSemantic = emptyRoleSemantic;
83 this.transportGuarantee = transportGuarantee;
84 this.rolesAllowed = rolesAllowed;
87 public EmptyRoleSemantic getEmptyRoleSemantic() {
88 return emptyRoleSemantic;
91 public TransportGuarantee getTransportGuarantee() {
92 return transportGuarantee;
95 public String[] getRolesAllowed() {