KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > security > Communication


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31
32 package org.objectweb.proactive.ext.security;
33
34 import java.io.Serializable JavaDoc;
35
36
37 /**
38  * @author acontes
39  *
40  * To change the template for this generated type comment go to
41  * Window>Preferences>Java>Code Generation>Code and Comments
42  */

43 public class Communication implements Serializable JavaDoc {
44     public static int REQUIRED = 1;
45     public static int DENIED = -1;
46     public static int OPTIONAL = 0;
47     public static int ALLOWED = 1;
48
49     /* indicates if authentication is required,optional or denied */
50     private int authentication;
51
52     /* indicates if confidentiality is required,optional or denied */
53     private int confidentiality;
54
55     /* indicates if integrity is required,optional or denied */
56     private int integrity;
57
58     /* indicates if communication between active objects is allowed or not */
59     private int communication;
60     private int migration;
61     private int aoCreation;
62
63     /**
64      * Default constructor, initialize a policy with communication attribute sets to allowed and
65      * authentication,confidentiality and integrity set to optional
66      */

67     public Communication() {
68         authentication = 0;
69         confidentiality = 0;
70         integrity = 0;
71         communication = 1;
72         migration = 1;
73         aoCreation = 1;
74     }
75
76     /**
77      * Method Communication.
78      * @param communication specifies if communication is allowed
79      * @param authentication specifies if authentication is required, optional, or denied
80      * @param confidentiality specifies if confidentiality is required, optional, or denied
81      * @param integrity specifies if integrity is required, optional, or denied
82      */

83     public Communication(int authentication, int confidentiality, int integrity) {
84         this.authentication = authentication;
85         this.confidentiality = confidentiality;
86         this.integrity = integrity;
87     }
88
89     /**
90      * Method isAuthenticationEnabled.
91      * @return boolean true if authentication is required
92      */

93     public boolean isAuthenticationEnabled() {
94         return authentication == 1;
95     }
96
97     /**
98      * Method isConfidentialityEnabled.
99      * @return boolean true if confidentiality is required
100      */

101     public boolean isConfidentialityEnabled() {
102         return confidentiality == 1;
103     }
104
105     /**
106      * Method isIntegrityEnabled.
107      * @return boolean true if integrity is required
108      */

109     public boolean isIntegrityEnabled() {
110         return integrity == 1;
111     }
112
113     /**
114      * Method isAuthenticationForbidden.
115      * @return boolean true if confidentiality is forbidden
116      */

117     public boolean isAuthenticationForbidden() {
118         return authentication == -1;
119     }
120
121     /**
122      * Method isConfidentialityForbidden.
123      * @return boolean true if confidentiality is forbidden
124      */

125     public boolean isConfidentialityForbidden() {
126         return confidentiality == -1;
127     }
128
129     /**
130      * Method isIntegrityForbidden.
131      * @return boolean true if integrity is forbidden
132      */

133     public boolean isIntegrityForbidden() {
134         return integrity == -1;
135     }
136
137     /**
138      * Method isCommunicationAllowed.
139      * @return boolean true if confidentiality is allowed
140      */

141     public boolean isCommunicationAllowed() {
142         return communication == 1;
143     }
144
145     public String JavaDoc toString() {
146         return "Com : " + communication + " Auth : " + authentication +
147         " Conf : " + confidentiality + " Integrity : " + integrity + "\n";
148     }
149
150     /**
151      * @param i
152      */

153     public void setMigration(int i) {
154         migration = i;
155     }
156
157     /**
158      * @return migration
159      */

160     public int getMigration() {
161         return migration;
162     }
163
164     /**
165      * Method computePolicy.
166      * @param from the client policy
167      * @param to the server policy
168      * @return Policy returns a computation of the from and server policies
169      * @throws IncompatiblePolicyException policies are incomptables, conflicting communication attributes
170      */

171     public static Communication computeCommunication(Communication from,
172         Communication to) throws IncompatiblePolicyException {
173         if (from.isCommunicationAllowed() && to.isCommunicationAllowed()) {
174             if (((from.authentication == REQUIRED) &&
175                     (to.authentication == DENIED)) ||
176                     ((from.confidentiality == REQUIRED) &&
177                     (to.confidentiality == DENIED)) ||
178                     ((from.integrity == REQUIRED) && (to.integrity == DENIED)) ||
179                     ((from.authentication == DENIED) &&
180                     (to.authentication == REQUIRED)) ||
181                     ((from.confidentiality == DENIED) &&
182                     (to.confidentiality == REQUIRED)) ||
183                     ((from.integrity == DENIED) && (to.integrity == REQUIRED))) {
184                 throw new IncompatiblePolicyException("incompatible policies");
185             }
186         }
187
188         return new Communication(from.authentication + to.authentication,
189             from.confidentiality + to.confidentiality,
190             from.integrity + to.integrity);
191     }
192
193     /**
194      * @param aocreation
195      */

196     public void setAOCreation(int aocreation) {
197         this.aoCreation = aocreation;
198     }
199
200     /**
201      * @param aocreation
202      */

203     public int getAOCreation() {
204         return this.aoCreation;
205     }
206
207     /**
208      * @return communication
209      */

210     public int getCommunication() {
211         return communication;
212     }
213
214     /**
215      * @param i
216      */

217     public void setCommunication(int i) {
218         communication = i;
219     }
220 }
221
Popular Tags