• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Conditions Of Use
3 *
4 * This software was developed by employees of the National Institute of
5 * Standards and Technology (NIST), an agency of the Federal Government.
6 * Pursuant to title 15 Untied States Code Section 105, works of NIST
7 * employees are not subject to copyright protection in the United States
8 * and are considered to be in the public domain.  As a result, a formal
9 * license is not needed to use the software.
10 *
11 * This software is provided by NIST as a service and is expressly
12 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15 * AND DATA ACCURACY.  NIST does not warrant or make any representations
16 * regarding the use of the software or the results thereof, including but
17 * not limited to the correctness, accuracy, reliability or usefulness of
18 * the software.
19 *
20 * Permission to use this software is contingent upon your acceptance
21 * of the terms of this agreement
22 *
23 * .
24 *
25 */
26 /*******************************************************************************
27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        *
28 *******************************************************************************/
29 package gov.nist.javax.sip.header;
30 
31 import gov.nist.core.*;
32 
33 /**
34  * Challenge part of the Auth header. This is only used by the parser interface
35  *
36  * @author M. Ranganathan    <br/>
37  * @version 1.2 $Revision: 1.7 $ $Date: 2009/07/17 18:57:28 $
38  * @since 1.1
39  *
40 */
41 public class Challenge extends SIPObject {
42 
43     /**
44      * Comment for <code>serialVersionUID</code>
45      */
46     private static final long serialVersionUID = 5944455875924336L;
47 
48     private static String DOMAIN = ParameterNames.DOMAIN;
49     private static String REALM = ParameterNames.REALM;
50     private static String OPAQUE = ParameterNames.OPAQUE;
51     private static String ALGORITHM = ParameterNames.ALGORITHM;
52     private static String QOP = ParameterNames.QOP;
53     private static String STALE = ParameterNames.STALE;
54     private static String SIGNATURE = ParameterNames.SIGNATURE;
55     private static String RESPONSE = ParameterNames.RESPONSE;
56     private static String SIGNED_BY = ParameterNames.SIGNED_BY;
57     private static String URI = ParameterNames.URI;
58 
59     /**
60      * scheme field
61      */
62     protected String scheme;
63 
64     /**
65      * authParms list
66      */
67     protected NameValueList authParams;
68 
69     /**
70      * Default constructor
71      */
Challenge()72     public Challenge() {
73         authParams = new NameValueList();
74         authParams.setSeparator(COMMA);
75     }
76 
77     /**
78      * Encode the challenge in canonical form.
79      * @return String
80      */
encode()81     public String encode() {
82         return new StringBuffer(scheme)
83             .append(SP)
84             .append(authParams.encode())
85             .toString();
86     }
87 
88     /**
89      * get the scheme field
90      * @return String
91      */
getScheme()92     public String getScheme() {
93         return scheme;
94     }
95 
96     /**
97      * get AuthParms list.
98      * @return NameValueList
99      */
getAuthParams()100     public NameValueList getAuthParams() {
101         return authParams;
102     }
103 
104     /**
105      * get the domain
106      * @return String
107      */
getDomain()108     public String getDomain() {
109         return (String) authParams.getValue(DOMAIN);
110     }
111 
112     /**
113      * get the URI field
114      * @return String
115      */
getURI()116     public String getURI() {
117         return (String) authParams.getValue(URI);
118     }
119 
120     /**
121      * get the Opaque field
122      * @return String
123      */
getOpaque()124     public String getOpaque() {
125         return (String) authParams.getValue(OPAQUE);
126     }
127 
128     /**
129      * get QOP value
130      * @return String
131      */
getQOP()132     public String getQOP() {
133         return (String) authParams.getValue(QOP);
134     }
135 
136     /**
137      * get the Algorithm value.
138      * @return String
139      */
getAlgorithm()140     public String getAlgorithm() {
141         return (String) authParams.getValue(ALGORITHM);
142     }
143 
144     /**
145      * get the State value.
146      * @return String
147      */
getStale()148     public String getStale() {
149         return (String) authParams.getValue(STALE);
150     }
151 
152     /**
153      * get the Signature value.
154      * @return String
155      */
getSignature()156     public String getSignature() {
157         return (String) authParams.getValue(SIGNATURE);
158     }
159 
160     /**
161      * get the signedBy value.
162      * @return String
163      */
getSignedBy()164     public String getSignedBy() {
165         return (String) authParams.getValue(SIGNED_BY);
166     }
167 
168     /**
169      * get the Response value.
170      * @return String
171      */
getResponse()172     public String getResponse() {
173         return (String) authParams.getValue(RESPONSE);
174     }
175 
176     /**
177      * get the realm value.
178      * @return String.
179      */
getRealm()180     public String getRealm() {
181         return (String) authParams.getValue(REALM);
182     }
183 
184     /**
185      * get the specified parameter
186      * @param name String to set
187      * @return String to set
188      */
getParameter(String name)189     public String getParameter(String name) {
190         return (String) authParams.getValue(name);
191     }
192 
193     /**
194      * boolean function
195      * @param name String to set
196      * @return true if this header has the specified parameter, false otherwise.
197      */
hasParameter(String name)198     public boolean hasParameter(String name) {
199         return authParams.getNameValue(name) != null;
200     }
201 
202     /**
203      * Boolean function
204      * @return true if this header has some parameters.
205      */
hasParameters()206     public boolean hasParameters() {
207         return authParams.size() != 0;
208     }
209 
210     /**
211      * delete the specified parameter
212      * @param name String
213      * @return true if the specified parameter has been removed, false
214      * otherwise.
215      */
removeParameter(String name)216     public boolean removeParameter(String name) {
217         return authParams.delete(name);
218     }
219 
220     /**
221      * remove all parameters
222      */
removeParameters()223     public void removeParameters() {
224         authParams = new NameValueList();
225     }
226 
227     /**
228      * set the specified parameter
229      * @param nv NameValue to set
230      */
setParameter(NameValue nv)231     public void setParameter(NameValue nv) {
232         authParams.set(nv);
233     }
234 
235     /**
236      * Set the scheme member
237      * @param s String to set
238      */
setScheme(String s)239     public void setScheme(String s) {
240         scheme = s;
241     }
242 
243     /**
244      * Set the authParams member
245      * @param a NameValueList to set
246      */
setAuthParams(NameValueList a)247     public void setAuthParams(NameValueList a) {
248         authParams = a;
249     }
250 
clone()251     public Object clone() {
252         Challenge retval = (Challenge) super.clone();
253         if (this.authParams != null)
254             retval.authParams = (NameValueList) this.authParams.clone();
255         return retval;
256     }
257 }
258