Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement.
 *
 */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.javax.sip.header;
 
 
  /*
  * 2005/06/12: geir.hedemark@telio.no: Changed behaviour of qop parameter in
  *           Authorization header - removed quoting of string according to
  *          RFC3261, BNF element "message-qop" (as opposed to "qop-options",
  *           which is quoted.
  */

The generic AuthenticationHeader

Author(s):
Olivier Deruelle
M. Ranganathan
Version:
1.2 $Revision: 1.14 $ $Date: 2010-05-06 14:07:47 $
Since:
1.1
 
 public abstract class AuthenticationHeader extends ParametersHeader {
 
     public static final String DOMAIN = .;
 
     public static final String REALM = .;
 
     public static final String OPAQUE = .;
 
     public static final String ALGORITHM = .;
 
     public static final String QOP = .;
 
     public static final String STALE = .;
 
     public static final String SIGNATURE = .;
 
     public static final String RESPONSE = .;
 
     public static final String SIGNED_BY = .;
 
     public static final String NC = .;
 
     public static final String URI = .;
 
     public static final String USERNAME = .;
 
     public static final String CNONCE = .;
 
     public static final String NONCE = .;
 
     public static final String IK = .;
     public static final String CK = .;
     public static final String INTEGRITY_PROTECTED = .;
 
     protected String scheme;
 
     public AuthenticationHeader(String name) {
         super(name);
         .setSeparator(.); // oddball
         this. = .;
     }
 
     public AuthenticationHeader() {
         super();
     }

    
set the specified parameter. Bug reported by Dominic Sparks.

Parameters:
name -- name of the parameter
value -- value of the parameter.
    public void setParameter(String nameString valuethrows ParseException {
        NameValue nv = super..getNameValue(name.toLowerCase());
        if (nv == null) {
            nv = new NameValue(namevalue);
            if (name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(. )
                    ||name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)
                    || name.equalsIgnoreCase(.)) {
                if (((this instanceof Authorization) || (this instanceof ProxyAuthorization))
                        && name.equalsIgnoreCase(.)) {
                    // NOP, QOP not quoted in authorization headers
                } else {
                    nv.setQuotedValue();
                }
                if (value == null)
                    throw new NullPointerException("null value");
                if (value.startsWith(.))
                    throw new ParseException(value
                            + " : Unexpected DOUBLE_QUOTE", 0);
            }
            super.setParameter(nv);
        } else
            nv.setValueAsObject(value);
    }

    
This is only used for the parser interface.

Parameters:
challenge -- the challenge from which the parameters are extracted.
    public void setChallenge(Challenge challenge) {
        this. = challenge.scheme;
        super. = challenge.authParams;
    }

    
Encode in canonical form.

Returns:
canonical string.
    public StringBuilder encodeBody(StringBuilder buffer) {
        buffer = buffer.append(this.).append();
        return .encode(buffer);
    }

    
Sets the scheme of the challenge information for this AuthenticationHeaderHeader. For example, Digest.

Parameters:
scheme - the new string value that identifies the challenge information scheme.
    public void setScheme(String scheme) {
        this. = scheme;
    }

    
Returns the scheme of the challenge information for this AuthenticationHeaderHeader.

Returns:
the string value of the challenge information.
    public String getScheme() {
        return ;
    }

    
Sets the Realm of the WWWAuthenicateHeader to the realm parameter value. Realm strings MUST be globally unique. It is RECOMMENDED that a realm string contain a hostname or domain name. Realm strings SHOULD present a human-readable identifier that can be rendered to a user.

Parameters:
realm the new Realm String of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the realm.
    public void setRealm(String realmthrows ParseException {
        if (realm == null)
            throw new NullPointerException(
                    "JAIN-SIP Exception, "
                            + " AuthenticationHeader, setRealm(), The realm parameter is null");
        setParameter(.realm);
    }

    
Returns the Realm value of this WWWAuthenicateHeader. This convenience method returns only the realm of the complete Challenge.

Returns:
the String representing the Realm information, null if value is not set.
Since:
v1.1
    public String getRealm() {
        return getParameter(.);
    }

    
Sets the Nonce of the WWWAuthenicateHeader to the nonce parameter value.

Parameters:
nonce - the new nonce String of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the nonce value.
Since:
v1.1
    public void setNonce(String noncethrows ParseException {
        if (nonce == null)
            throw new NullPointerException(
                    "JAIN-SIP Exception, "
                            + " AuthenticationHeader, setNonce(), The nonce parameter is null");
        setParameter(nonce);
    }

    
Returns the Nonce value of this WWWAuthenicateHeader.

Returns:
the String representing the nonce information, null if value is not set.
Since:
v1.1
    public String getNonce() {
        return getParameter(.);
    }

    
Sets the URI of the WWWAuthenicateHeader to the uri parameter value.

Parameters:
uri - the new URI of this AuthenicationHeader.
Since:
v1.1 Note that since 1.2 this is no longer applicable to the WWW-Authenticate and Proxy-Authenticate headers
    public void setURI(javax.sip.address.URI uri) {
        if (uri != null) {
            NameValue nv = new NameValue(.uri);
            nv.setQuotedValue();
            super..set(nv);
        } else {
            throw new NullPointerException("Null URI");
        }
    }

    
Returns the URI value of this WWWAuthenicateHeader, for example DigestURI.

Returns:
the URI representing the URI information, null if value is not set.
Since:
v1.1 Note that since 1.2 this is no longer applicable to the WWW-Authenticate and Proxy-Authenticate headers
    public javax.sip.address.URI getURI() {
        return getParameterAsURI(.);
    }

    
Sets the Algorithm of the WWWAuthenicateHeader to the new algorithm parameter value.

Parameters:
algorithm - the new algorithm String of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the algorithm value.
Since:
v1.1
    public void setAlgorithm(String algorithmthrows ParseException {
        if (algorithm == null)
            throw new NullPointerException("null arg");
        setParameter(.algorithm);
    }

    
Returns the Algorithm value of this WWWAuthenicateHeader.

Returns:
the String representing the Algorithm information, null if the value is not set.
Since:
v1.1
    public String getAlgorithm() {
        return getParameter(.);
    }

    
Sets the Qop value of the WWWAuthenicateHeader to the new qop parameter value.

Parameters:
qop - the new Qop string of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the Qop value.
Since:
v1.1
    public void setQop(String qopthrows ParseException {
        if (qop == null)
            throw new NullPointerException("null arg");
        setParameter(.qop);
    }

    
Returns the Qop value of this WWWAuthenicateHeader.

Returns:
the string representing the Qop information, null if the value is not set.
Since:
v1.1
    public String getQop() {
        return getParameter(.);
    }

    
Sets the Opaque value of the WWWAuthenicateHeader to the new opaque parameter value.

Parameters:
opaque - the new Opaque string of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the opaque value.
Since:
v1.1
    public void setOpaque(String opaquethrows ParseException {
        if (opaque == null)
            throw new NullPointerException("null arg");
        setParameter(.opaque);
    }

    
Returns the Opaque value of this WWWAuthenicateHeader.

Returns:
the String representing the Opaque information, null if the value is not set.
Since:
v1.1
    public String getOpaque() {
        return getParameter(.);
    }

    
Sets the Domain of the WWWAuthenicateHeader to the domain parameter value.

Parameters:
domain - the new Domain string of this WWWAuthenicateHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the domain.
Since:
v1.1
    public void setDomain(String domainthrows ParseException {
        if (domain == null)
            throw new NullPointerException("null arg");
        setParameter(.domain);
    }

    
Returns the Domain value of this WWWAuthenicateHeader.

Returns:
the String representing the Domain information, null if value is not set.
Since:
v1.1
    public String getDomain() {
        return getParameter(.);
    }

    
Sets the value of the stale parameter of the WWWAuthenicateHeader to the stale parameter value.

Parameters:
stale - the Boolean.valueOf value of the stale parameter.
Since:
v1.1
    public void setStale(boolean stale) {
        setParameter(new NameValue(., Boolean.valueOf(stale)));
    }

    
Returns the boolean value of the state paramater of this WWWAuthenicateHeader.

Returns:
the boolean representing if the challenge is stale.
Since:
v1.1
    public boolean isStale() {
        return this.getParameterAsBoolean(.);
    }

    
Set the CNonce.

Parameters:
cnonce -- a nonce string.
    public void setCNonce(String cnoncethrows ParseException {
        this.setParameter(.cnonce);
    }

    
Get the CNonce.

Returns:
the cnonce value.
    public String getCNonce() {
        return getParameter(.);
    }
    public int getNonceCount() {
        return this.getParameterAsHexInt(.);
    }

    
Set the nonce count pakrameter. Bug fix sent in by Andreas Bystr�m
    public void setNonceCount(int paramthrows java.text.ParseException {
        if (param < 0)
            throw new ParseException("bad value", 0);
        String nc = Integer.toHexString(param);
        String base = "00000000";
        nc = base.substring(0, 8 - nc.length()) + nc;
        this.setParameter(.nc);
    }

    
Get the RESPONSE value (or null if it does not exist).

Returns:
String response parameter value.
    public String getResponse() {
        return (StringgetParameterValue(.);
    }

    
Set the Response.

Parameters:
response to set.
    public void setResponse(String responsethrows ParseException {
        if (response == null)
            throw new NullPointerException("Null parameter");
        // Bug fix from Andreas Bystr�m
        this.setParameter(response);
    }

    
Returns the Username value of this AuthorizationHeader. This convenience method returns only the username of the complete Response.

Returns:
the String representing the Username information, null if value is not set.
    public String getUsername() {
        return (StringgetParameter(.);
    }

    
Sets the Username of the AuthorizationHeader to the username parameter value.

Parameters:
username the new Username String of this AuthorizationHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the username.
    public void setUsername(String usernamethrows ParseException {
        this.setParameter(.username);
    }
    public void setIK(String ikthrows ParseException {
        if (ik == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + " AuthenticationHeader, setIk(), The auth-param IK parameter is null");
        setParameter(ik);
    }
    public String getIK() {
        return getParameter(.);
    }
    public void setCK(String ckthrows ParseException {
        if (ck == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + " AuthenticationHeader, setCk(), The auth-param CK parameter is null");
        setParameter(ck);
    }
    public String getCK() {
        return getParameter(.);
    }
    public void setIntegrityProtected(String integrityProtectedthrows ParseException
    {
        if (integrityProtected == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + " AuthenticationHeader, setIntegrityProtected(), The integrity-protected parameter is null");
        setParameter(integrityProtected);
    }
    public String getIntegrityProtected() {
    }
New to GrepCode? Check out our FAQ X