summaryrefslogtreecommitdiffstats
path: root/java/gov/nist/javax/sip/clientauthutils/AuthenticationHelper.java
blob: a8266916a8bdaec5ea04fbf9afa3b2062cec4bdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gov.nist.javax.sip.clientauthutils;

import java.text.ParseException;
import java.util.Collection;

import javax.sip.ClientTransaction;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import javax.sip.SipProvider;
import javax.sip.header.AuthorizationHeader;
import javax.sip.message.Request;
import javax.sip.message.Response;

/**
 * A helper interface that provides useful functionality for clients that need to authenticate
 * with servers.
 *
 * @author Emil Ivov
 * @author Jeroen van Bemmel
 * @author M. Ranganathan
 *
 * @since 2.0
 *
 *
 */
public interface AuthenticationHelper {

    /**
     * Uses securityAuthority to determinie a set of valid user credentials for
     * the specified Response (Challenge) and appends it to the challenged
     * request so that it could be retransmitted.
     *
     *
     *
     * @param challenge
     *            the 401/407 challenge response
     * @param challengedTransaction
     *            the transaction established by the challenged request
     * @param transactionCreator
     *            the JAIN SipProvider that we should use to create the new
     *            transaction.
     * @param cacheTime The amount of time (seconds ) for which the authentication helper
     *      will keep a reference to the generated credentials in a cache.
     *      If you specify -1, then the authentication credentials are cached
     *      until you remove them from the cache. If you choose this option, make sure
     *      you remove the cached headers or you will have a memory leak.
     *
     * @return a transaction containing a re-originated request with the
     *         necessary authorization header.
     * @throws SipException
     *             if we get an exception white creating the new transaction
     * @throws NullPointerException
     *             if an argument or a header is null.
     */
    public abstract ClientTransaction handleChallenge(Response challenge,
            ClientTransaction challengedTransaction,
            SipProvider transactionCreator, int cacheTime ) throws SipException,
             NullPointerException;

    /**
     * Attach authentication headers to the given request. This looks up
     * the credential cache and picks up any stored authentication headers
     * for the given call ID and attaches it to the request.
     * @param request - the request for which we attach the authentication headers.
     */
    public abstract void setAuthenticationHeaders(Request request) ;

    /**
     * Remove cached entry.
     *
     * @param callId -- the call Id for which we want to remove the cached headers.
     *
     */
    public abstract void removeCachedAuthenticationHeaders(String callId);
}