FileDocCategorySizeDatePackage
AuthenticationHeader.javaAPI DocphoneME MR2 API (J2ME)17246Wed May 02 18:00:42 BST 2007gov.nist.siplite.header

AuthenticationHeader

public abstract class AuthenticationHeader extends ParametersHeader
The generic AuthenticationHeader This code is in the public domain.

Fields Summary
public static String
DOMAIN
Domain header label.
public static String
REALM
Realm header label.
public static String
OPAQUE
Opaque header.
public static String
ALGORITHM
Algorithm header label.
public static String
QOP
Qop header (RFC?).
public static String
STALE
Stale header (RFC?).
public static String
SIGNATURE
Signature header.
public static String
RESPONSE
Response header.
public static String
SIGNED_BY
Signed byte header.
public static String
NC
NC header (RFC?).
public static String
URI
URI header.
public static String
USERNAME
User name header.
public static String
CNONCE
C-nonce header.
public static String
NONCE
Nonce header.
public static String
DIGEST
Digest header.
public static String
NEXT_NONCE
Next nonce header.
protected String
scheme
Current protocol scheme.
Constructors Summary
public AuthenticationHeader(String name)
Constructor with header name.

param
name header to process


                  
       
        super(name);
        parameters.setSeparator(Separators.COMMA); // oddball
        this.scheme = DIGEST;
    
public AuthenticationHeader()
Default constructor.

        super();
        parameters.setSeparator(Separators.COMMA);
    
Methods Summary
public java.lang.Objectclone()
Clone - do a deep copy.

return
Object Authorization

        Exception ex = null;
        try {
            AuthenticationHeader retval = (AuthenticationHeader)
            this.getClass().newInstance();
            if (this.scheme != null) retval.scheme = new String(this.scheme);
            if (this.parameters != null)
                retval.parameters = (NameValueList)parameters.clone();
            return retval;
        } catch (InstantiationException ie) {
            ex = ie;
        } catch (IllegalAccessException iae) {
            ex = iae;
        }
        if (ex != null) {
            InternalErrorHandler.handleException(ex);
        }
        return null;
    
public java.lang.StringencodeBody()
Encodes in canonical form.

return
canonical string.

        return this.scheme + Separators.SP + parameters.encode();
    
public booleanequals(java.lang.Object that)
Compares for equivalence.

param
that object to compare
return
true if object matches

        if (! that.getClass().equals(this.getClass())) {
            return false;
        } else {
            AuthenticationHeader other = (AuthenticationHeader) that;
            return (equalsIgnoreCase(this.scheme, other.scheme) &&
                    this.parameters.equals(other.parameters));
        }
    
public java.lang.StringgetAlgorithm()
Returns the Algorithm value of this WWWAuthenicateHeader.

return
the String representing the Algorithm information, null if the value is not set.
since
v1.1

        return getParameter(ALGORITHM);
    
public java.lang.StringgetCNonce()
Get the CNonce.

return
the cnonce value.

        return getParameter(CNONCE);
    
public java.lang.StringgetDomain()
Returns the Domain value of this WWWAuthenicateHeader.

return
the String representing the Domain information, null if value is not set.
since
v1.1

        return getParameter(DOMAIN);
    
public java.lang.StringgetNonce()
Returns the Nonce value of this WWWAuthenicateHeader.

return
the String representing the nonce information, null if value is not set.
since
v1.1

        return getParameter(NONCE);
    
public intgetNonceCount()
Counts the nonce.

return
the count of nonces

        return this.getParameterAsHexInt(NC);

    
public java.lang.StringgetOpaque()
Returns the Opaque value of this WWWAuthenicateHeader.

return
the String representing the Opaque information, null if the value is not set.
since
v1.1

        return getParameter(OPAQUE);
    
public java.lang.StringgetParameter(java.lang.String name)
Returns the value of the named parameter, or null if it is not set. A zero-length String indicates flag parameter.

param
name name of parameter to retrieve
return
the value of specified parameter

        String returnValue = super.getParameter(name);
        if ((returnValue != null) && isQuoted(name)) { // remove quotes
            returnValue = returnValue.substring(1, returnValue.length() - 1);
        }
        return returnValue;
        
    
public java.lang.StringgetQop()
Returns the Qop value of this WWWAuthenicateHeader.

return
the string representing the Qop information, null if the value is not set.
since
v1.1

        return getParameter(QOP);
    
public java.lang.StringgetRealm()
Returns the Realm value of this WWWAuthenicateHeader. This convenience method returns only the realm of the complete Challenge.

return
the String representing the Realm information, null if value is not set.
since
v1.1

        return getParameter(REALM);
    
public java.lang.StringgetResponse()
Gets the RESPONSE value (or null if it does not exist).

return
String response parameter value.

        return (String) getParameterValue(RESPONSE);
    
public java.lang.StringgetScheme()
Returns the scheme of the challenge information for this AuthenticationHeaderHeader.

return
the string value of the challenge information.
since
v1.1

        return scheme;
    
public URIgetURI()
Returns the URI value of this WWWAuthenicateHeader, for example DigestURI.

return
the URI representing the URI information, null if value is not set.
since
v1.1

        return getParameterAsURI(URI);
    
public java.lang.StringgetUsername()
Returns the Username value of this AuthorizationHeader. This convenience method returns only the username of the complete Response.

return
the String representing the Username information, null if value is not set.
since
JAIN SIP v1.1

        return (String) getParameter
                (USERNAME);
    
public java.lang.ObjectgetValue()
Gets the value of the header (just returns the scheme).

return
the scheme object.

        return getScheme();

    
private booleanisQuoted(java.lang.String name)
Returns true if parameter must be quoted, else - false. zero-length String indicates flag parameter.

param
name name of parameter to retrieve
return
flag of parameter (quoted or not)

        if (equalsIgnoreCase(name, QOP) ||
                equalsIgnoreCase(name, REALM) ||
                equalsIgnoreCase(name, URI) ||
                equalsIgnoreCase(name, CNONCE) ||
                equalsIgnoreCase(name, NONCE) ||
                equalsIgnoreCase(name, USERNAME) ||
                equalsIgnoreCase(name, DOMAIN) ||
                equalsIgnoreCase(name, OPAQUE) ||
                equalsIgnoreCase(name, NEXT_NONCE) ||
                equalsIgnoreCase(name, RESPONSE)) {
            return true;
        }
        return false;
    
public booleanisStale()
Returns the boolean value of the state paramater of this WWWAuthenicateHeader.

return
the boolean representing if the challenge is stale.
since
v1.1

        return this.getParameterAsBoolean(STALE);
    
public voidsetAlgorithm(java.lang.String algorithm)
Sets the Algorithm of the WWWAuthenicateHeader to the new algorithm parameter value.

param
algorithm - the new algorithm String of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the algorithm value.
since
v1.1

        if (algorithm == null)
            throw new NullPointerException("null arg");
        setParameter(ALGORITHM, algorithm);
    
public voidsetCNonce(java.lang.String cnonce)
Set the CNonce.

param
cnonce -- a nonce string.

        this.setParameter(CNONCE, cnonce);
    
public voidsetDomain(java.lang.String domain)
Sets the Domain of the WWWAuthenicateHeader to the domain parameter value.

param
domain - the new Domain string of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the domain.
since
v1.1

        if (domain == null)
            throw new NullPointerException("null arg");
        setParameter(DOMAIN, domain);
    
public voidsetNonce(java.lang.String nonce)
Sets the Nonce of the WWWAuthenicateHeader to the nonce parameter value.

param
nonce - the new nonce String of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the nonce value.
since
v1.1

        if (nonce == null)
            throw new NullPointerException("null nonce");
        setParameter(NONCE, nonce);
    
public voidsetNonceCount(int nonceCount)
Set the nonce count parameter.

param
nonceCount -- nonce count to set.

        if (nonceCount < 0)
            throw new IllegalArgumentException("bad value");

        String nc = Integer.toHexString(nonceCount);

        String base = "00000000";
        nc = base.substring(0, 8 - nc.length()) + nc;
        this.setParameter(NC, nc);

    
public voidsetOpaque(java.lang.String opaque)
Sets the Opaque value of the WWWAuthenicateHeader to the new opaque parameter value.

param
opaque - the new Opaque string of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the opaque value.
since
v1.1

        if (opaque == null)
            throw new NullPointerException("null arg");
        setParameter(OPAQUE, opaque);
    
public voidsetParameter(NameValue nv)
Sets the specified parameter.

param
nv parameter's name/value pair

        Object val = nv.getValue();
        setParameter(nv.getName(), (val == null) ? null : val.toString());
    
public voidsetParameter(java.lang.String name, java.lang.String value)
Sets the specified parameter.

param
name name of the parameter
param
value value of the parameter.

        NameValue nv =
                super.parameters.getNameValue(name.toLowerCase());

        boolean quotedParam = false;
        
        if (isQuoted(name)) {
            
            if (value == null) {
                throw new NullPointerException("null value");
            }
            
            quotedParam = true;
            boolean quoteStart = value.startsWith(Separators.DOUBLE_QUOTE);
            boolean quoteEnd = value.endsWith(Separators.DOUBLE_QUOTE);
            
            if ((quoteStart && !quoteEnd) || (!quoteStart && quoteEnd)) {
                throw new IllegalArgumentException
                    (value + " : Unexpected DOUBLE_QUOTE");
            }
            
            if (quoteStart) { // quoteEnd is true in this case
                value = value.substring(1, value.length() - 1);
            }
        }
        
        if (nv == null) {
            nv = new NameValue(name.toLowerCase(), value);

            if (quotedParam) {
                nv.setQuotedValue();
            }

            super.setParameter(nv);
        } else {
            nv.setValue(value);
        }

    
public voidsetQop(java.lang.String qop)
Sets the Qop value of the WWWAuthenicateHeader to the new qop parameter value.

param
qop - the new Qop string of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the Qop value.
since
v1.1

        if (qop == null)
            throw new NullPointerException("null arg");
        setParameter(QOP, qop);
    
public voidsetRealm(java.lang.String realm)
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.

param
realm the new Realm String of this WWWAuthenicateHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the realm.
since
v1.1

        if (realm == null)
            throw new NullPointerException("null realm");
        setParameter(REALM, realm);
    
public voidsetResponse(java.lang.String response)
Sets the Response.

param
response to set.

        if (response == null)
            throw new NullPointerException("Null parameter");
        this.setParameter(RESPONSE, response);
    
public voidsetScheme(java.lang.String scheme)
Sets the scheme of the challenge information for this AuthenticationHeaderHeader. For example, Digest.

param
scheme - the new string value that identifies the challenge information scheme.
since
v1.1

        this.scheme = scheme;
    
public voidsetStale(boolean stale)
Sets the value of the stale parameter of the WWWAuthenicateHeader to the stale parameter value.

param
stale - the new boolean value of the stale parameter.
since
v1.1

        setParameter(new NameValue(STALE, new Boolean(stale)));
    
public voidsetURI(URI uri)
Sets the URI of the WWWAuthenicateHeader to the uri parameter value.

param
uri - the new URI of this WWWAuthenicateHeader.
since
v1.1

        if (uri != null) {
            NameValue nv = new NameValue(URI, uri);
            nv.setQuotedValue();
            super.parameters.set(nv);
        } else {
            throw new NullPointerException("Null URI");
        }
    
public voidsetUsername(java.lang.String username)
Sets the Username of the AuthorizationHeader to the username parameter value.

param
username the new Username String of this AuthorizationHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the username.
since
JAIN SIP v1.1

        this.setParameter(USERNAME, username);