KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > AuthorizationConstraintImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import com.sun.enterprise.deployment.web.SecurityRole;
26 import com.sun.enterprise.deployment.web.AuthorizationConstraint;
27
28 import java.util.Enumeration JavaDoc;
29 import java.util.Vector JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Set JavaDoc;
32
33 /**
34  * This descriptor represents an authorization contraint on a security
35  * constraint in a web application.
36  *
37  * @author Danny Coward
38  */

39
40 public class AuthorizationConstraintImpl extends Descriptor implements
41         AuthorizationConstraint {
42     private Set JavaDoc securityRoles;
43     
44     /**
45      * Default constructor that creates an AuthorizationConstraint
46      * with no roles.
47      */

48     public AuthorizationConstraintImpl() {
49     }
50     
51     /**
52      * Copy constructor.
53      */

54     public AuthorizationConstraintImpl(AuthorizationConstraintImpl other) {
55     this.securityRoles = new HashSet JavaDoc(other.getSecurityRoleSet());
56     }
57     
58     /**
59      * Return the set of roles.
60      */

61     private Set JavaDoc getSecurityRoleSet() {
62     if (this.securityRoles == null) {
63         this.securityRoles = new HashSet JavaDoc();
64     }
65     return this.securityRoles;
66     }
67
68     /**
69      * Return the security roles involved in this constraint. The
70      * enumeration is empty if there are none.
71      * @return the enumeration of security roles in this constraint.
72      */

73     public Enumeration JavaDoc getSecurityRoles() {
74     if (this.securityRoles == null) {
75         this.securityRoles = new HashSet JavaDoc();
76     }
77     return (new Vector JavaDoc(this.getSecurityRoleSet())).elements();
78     }
79     
80     /**
81      * Adds a role to the authorization constraint.
82      * @param the role to be added.
83      */

84     public void addSecurityRole(SecurityRole securityRole) {
85     this.getSecurityRoleSet().add(securityRole);
86     }
87     
88     /**
89      * Adds a role to the authorization constraint
90      * @param the role name to be added
91      */

92     public void addSecurityRole(String JavaDoc roleName) {
93         SecurityRoleDescriptor sr = new SecurityRoleDescriptor();
94         sr.setName(roleName);
95         addSecurityRole(sr);
96     }
97     
98     /**
99      * Removes the given role from the autrhorization constraint.
100      * @param the role to be removed.
101      */

102     public void removeSecurityRole(SecurityRole securityRole) {
103     this.getSecurityRoleSet().remove(securityRole);
104     }
105
106     /**
107      * Prints a formatted representation of this object.
108      */

109     public void print(StringBuffer JavaDoc toStringBuffer) {
110     toStringBuffer.append("AuthorizationConstraint ");
111     super.print(toStringBuffer);
112     toStringBuffer.append(" securityRoles ").append(this.securityRoles);
113     }
114     
115 }
116
Popular Tags