001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: * AuthenticationProcess.java
027: *
028: * Created on January 7, 2003, 5:30 PM
029: */
030:
031: package gov.nist.siplite.stack.authentication;
032:
033: /**
034: * Authentication process.
035: */
036: public class AuthenticationProcess {
037:
038: /** Creates a new instance of AuthenticationProcess */
039: public AuthenticationProcess() {
040:
041: }
042: /*
043: * need revisit
044: public Header getHeader(Response response) {
045: try {
046:
047: // Proxy-Authorization header:
048: ProxyAuthenticateHeader authenticateHeader =
049: (ProxyAuthenticateHeader)
050: response.getHeader(ProxyAuthenticateHeader.NAME);
051:
052: WWWAuthenticateHeader wwwAuthenticateHeader = null;
053: CSeqHeader cseqHeader =
054: (CSeqHeader)response.getHeader(CSeqHeader.NAME);
055:
056: String cnonce = null;
057: String uri = "sip:"+imUA.getRegistrarAddress()+":"
058: + imUA.getRegistrarPort();
059: String method = cseqHeader.getMethod();
060: String userName = null;
061: String password = null;
062: String nonce = null;
063: String realm = null;
064: String qop = null;
065:
066: if (authenticateHeader == null) {
067: wwwAuthenticateHeader = (WWWAuthenticateHeader)
068: response.getHeader(WWWAuthenticateHeader.NAME);
069:
070: nonce = wwwAuthenticateHeader.getNonce();
071: realm = wwwAuthenticateHeader.getRealm();
072: if (realm == null) {
073: DebugIM.println("AuthenticationProcess,"
074: + " getProxyAuthorizationHeader(), "+
075: " ERROR: the realm is not part "
076: + "of the 401 response!");
077: return null;
078: }
079: cnonce = wwwAuthenticateHeader.getParameter("cnonce");
080: qop = wwwAuthenticateHeader.getParameter("qop");
081: } else {
082:
083: nonce = authenticateHeader.getNonce();
084: realm = authenticateHeader.getRealm();
085: if (realm == null) {
086: DebugIM.println("AuthenticationProcess,"
087: + " getProxyAuthorizationHeader(), "+
088: " ERROR: the realm is not part"
089: + " of the 407 response!");
090: return null;
091: }
092: cnonce = authenticateHeader.getParameter("cnonce");
093: qop = authenticateHeader.getParameter("qop");
094: }
095:
096: HeaderFactory headerFactory = imUA.getHeaderFactory();
097:
098: DigestClientAuthenticationMethod digest =
099: new DigestClientAuthenticationMethod();
100: digest.initialize(realm, userName, uri, nonce,
101: password, method, cnonce, "MD5");
102:
103: if (authenticateHeader == null) {
104: AuthorizationHeader header =
105: headerFactory.createAuthorizationHeader("Digest");
106: header.setParameter("username", userName);
107: header.setParameter("realm", realm);
108: header.setParameter("uri", uri);
109: header.setParameter("algorithm", "MD5");
110: header.setParameter("opaque", "");
111: header.setParameter("nonce", nonce);
112: header.setParameter("response", digest.generateResponse());
113: if (qop != null)
114: header.setParameter("qop", qop);
115:
116: return header;
117: } else {
118: ProxyAuthorizationHeader header =
119: headerFactory.createProxyAuthorizationHeader("Digest");
120: header.setParameter("username", userName);
121: header.setParameter("realm", realm);
122: header.setParameter("uri", uri);
123: header.setParameter("algorithm", "MD5");
124: header.setParameter("opaque", "");
125: header.setParameter("nonce", nonce);
126: header.setParameter("response", digest.generateResponse());
127: if (qop != null)
128: header.setParameter("qop", qop);
129:
130: return header;
131: }
132: }
133: catch (Exception ex) {
134: ex.printStackTrace();
135: return null;
136: }
137: }
138: */
139: }
|