KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ietf > jgss > MessageProp


1 /*
2  * @(#)MessageProp.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package org.ietf.jgss;
9
10 /**
11  * This is a utility class used within the per-message GSSContext
12  * methods to convey per-message properties.<p>
13  *
14  * When used with the GSSContext interface's wrap and getMIC methods, an
15  * instance of this class is used to indicate the desired
16  * Quality-of-Protection (QOP) and to request if confidentiality services
17  * are to be applied to caller supplied data (wrap only). To request
18  * default QOP, the value of 0 should be used for QOP.<p>
19  *
20  * When used with the unwrap and verifyMIC methods of the GSSContext
21  * interface, an instance of this class will be used to indicate the
22  * applied QOP and confidentiality services over the supplied message.
23  * In the case of verifyMIC, the confidentiality state will always be
24  * <code>false</code>. Upon return from these methods, this object will also
25  * contain any supplementary status values applicable to the processed
26  * token. The supplementary status values can indicate old tokens, out
27  * of sequence tokens, gap tokens or duplicate tokens.<p>
28  *
29  * @see GSSContext#wrap
30  * @see GSSContext#unwrap
31  * @see GSSContext#getMIC
32  * @see GSSContext#verifyMIC
33  *
34  * @author Mayank Upadhyay
35  * @version 1.9, 12/19/03
36  * @since 1.4
37  */

38 public class MessageProp {
39
40     private boolean privacyState;
41     private int qop;
42     private boolean dupToken;
43     private boolean oldToken;
44     private boolean unseqToken;
45     private boolean gapToken;
46     private int minorStatus;
47     private String JavaDoc minorString;
48
49    /**
50     * Constructor which sets the desired privacy state. The QOP value used
51     * is 0.
52     *
53     * @param privState the privacy (i.e. confidentiality) state
54     */

55     public MessageProp(boolean privState) {
56         this(0, privState);
57     }
58
59     /**
60      * Constructor which sets the values for the qop and privacy state.
61      *
62      * @param qop the QOP value
63      * @param privState the privacy (i.e. confidentiality) state
64      */

65     public MessageProp(int qop, boolean privState) {
66         this.qop = qop;
67         this.privacyState = privState;
68         resetStatusValues();
69     }
70
71     /**
72      * Retrieves the QOP value.
73      *
74      * @return an int representing the QOP value
75      * @see #setQOP
76      */

77     public int getQOP() {
78         return qop;
79     }
80
81     /**
82      * Retrieves the privacy state.
83      *
84      * @return true if the privacy (i.e., confidentiality) state is true,
85      * false otherwise.
86      * @see #setPrivacy
87      */

88     public boolean getPrivacy() {
89     
90         return (privacyState);
91     }
92
93     /**
94      * Sets the QOP value.
95      *
96      * @param qop the int value to set the QOP to
97      * @see #getQOP
98      */

99     public void setQOP(int qop) {
100         this.qop = qop;
101     }
102
103
104     /**
105      * Sets the privacy state.
106      *
107      * @param privState true is the privacy (i.e., confidentiality) state
108      * is true, false otherwise.
109      * @see #getPrivacy
110      */

111     public void setPrivacy(boolean privState) {
112     
113         this.privacyState = privState;
114     }
115
116
117     /**
118      * Tests if this is a duplicate of an earlier token.
119      *
120      * @return true if this is a duplicate, false otherwise.
121      */

122     public boolean isDuplicateToken() {
123         return dupToken;
124     }
125
126     /**
127      * Tests if this token's validity period has expired, i.e., the token
128      * is too old to be checked for duplication.
129      *
130      * @return true if the token's validity period has expired, false
131      * otherwise.
132      */

133     public boolean isOldToken() {
134         return oldToken;
135     }
136
137     /**
138      * Tests if a later token had already been processed.
139      *
140      * @return true if a later token had already been processed, false otherwise.
141      */

142     public boolean isUnseqToken() {
143         return unseqToken;
144     }
145
146     /**
147      * Tests if an expected token was not received, i.e., one or more
148      * predecessor tokens have not yet been successfully processed.
149      *
150      * @return true if an expected per-message token was not received,
151      * false otherwise.
152      */

153     public boolean isGapToken() {
154         return gapToken;
155     }
156
157     /**
158      * Retrieves the minor status code that the underlying mechanism might
159      * have set for this per-message operation.
160      *
161      * @return the int minor status
162      */

163     public int getMinorStatus(){
164         return minorStatus;
165     }
166     
167     /**
168      * Retrieves a string explaining the minor status code.
169      *
170      * @return a String corresponding to the minor status
171      * code. <code>null</code> will be returned when no minor status code
172      * has been set.
173      */

174     public String JavaDoc getMinorString(){
175         return minorString;
176     }
177     
178     /**
179      * This method sets the state for the supplementary information flags
180      * and the minor status in MessageProp. It is not used by the
181      * application but by the GSS implementation to return this information
182      * to the caller of a per-message context method.
183      *
184      * @param duplicate true if the token was a duplicate of an earlier
185      * token, false otherwise
186      * @param old true if the token's validity period has expired, false
187      * otherwise
188      * @param unseq true if a later token has already been processed, false
189      * otherwise
190      * @param gap true if one or more predecessor tokens have not yet been
191      * successfully processed, false otherwise
192      * @param minorStatus the int minor status code for the per-message
193      * operation
194      * @param minorString the textual representation of the minorStatus value
195      */

196    public void setSupplementaryStates(boolean duplicate,
197                   boolean old, boolean unseq, boolean gap,
198                   int minorStatus, String JavaDoc minorString) {
199        this.dupToken = duplicate;
200        this.oldToken = old;
201        this.unseqToken = unseq;
202        this.gapToken = gap;
203        this.minorStatus = minorStatus;
204        this.minorString = minorString;
205     }
206
207     /**
208      * Resets the supplementary status values to false.
209      */

210     private void resetStatusValues() {
211         dupToken = false;
212         oldToken = false;
213         unseqToken = false;
214         gapToken = false;
215         minorStatus = 0;
216         minorString = null;
217     }
218 }
219
Popular Tags