public void addAuthHeader(SipServletResponse challengeResponse,
			AuthInfo authInfo, boolean cacheCredentials) {
		checkReadOnly();
		AuthInfoImpl authInfoImpl = (AuthInfoImpl) authInfo;

		SipServletResponseImpl challengeResponseImpl =
			(SipServletResponseImpl) challengeResponse;

		Response response = (Response) challengeResponseImpl.getMessage();
		// First check for WWWAuthentication headers
		ListIterator authHeaderIterator =
			response.getHeaders(WWWAuthenticateHeader.NAME);
		while(authHeaderIterator.hasNext()) {
			WWWAuthenticateHeader wwwAuthHeader =
				(WWWAuthenticateHeader) authHeaderIterator.next();
			// Fix for Issue 1832 : http://code.google.com/p/mobicents/issues/detail?id=1832
			// Authorization header is growing when nonce become stale, don't take into account stale headers
			// in the challenge request
			removeStaleAuthHeaders(wwwAuthHeader);
//			String uri = wwwAuthHeader.getParameter("uri");
			AuthInfoEntry authInfoEntry = authInfoImpl.getAuthInfo(wwwAuthHeader.getRealm());

			if(authInfoEntry == null) throw new SecurityException(
					"Cannot add authorization header. No credentials for the following realm: " + wwwAuthHeader.getRealm());

			addChallengeResponse(wwwAuthHeader,
					authInfoEntry.getUserName(),
					authInfoEntry.getPassword(),
					this.getRequestURI().toString());

			if(cacheCredentials) {
				getSipSession().getSipSessionSecurity().addCachedAuthInfo(wwwAuthHeader.getRealm(), authInfoEntry);
			}
		}

		// Now check for Proxy-Authentication
		authHeaderIterator =
			response.getHeaders(ProxyAuthenticateHeader.NAME);
		while(authHeaderIterator.hasNext()) {
			ProxyAuthenticateHeader proxyAuthHeader =
				(ProxyAuthenticateHeader) authHeaderIterator.next();
			// Fix for Issue 1832 : http://code.google.com/p/mobicents/issues/detail?id=1832
			// Authorization header is growing when nonce become stale, don't take into account stale headers
			// in the challenge request
			removeStaleAuthHeaders(proxyAuthHeader);
//			String uri = wwwAuthHeader.getParameter("uri");
			AuthInfoEntry authInfoEntry = authInfoImpl.getAuthInfo(proxyAuthHeader.getRealm());

			if(authInfoEntry == null) throw new SecurityException(
					"No credentials for the following realm: " + proxyAuthHeader.getRealm());

			addChallengeResponse(proxyAuthHeader,
					authInfoEntry.getUserName(),
					authInfoEntry.getPassword(),
					this.getRequestURI().toString());

			if(cacheCredentials) {
				getSipSession().getSipSessionSecurity().addCachedAuthInfo(proxyAuthHeader.getRealm(), authInfoEntry);
			}
		}
	}
public void addAuthHeader ( SipServletResponse challengeResponse , AuthInfo authInfo , boolean cacheCredentials ) { checkReadOnly ( ) ; AuthInfoImpl authInfoImpl = ( AuthInfoImpl ) authInfo ; SipServletResponseImpl challengeResponseImpl = ( SipServletResponseImpl ) challengeResponse ; Response response = ( Response ) challengeResponseImpl . getMessage ( ) ; ListIterator authHeaderIterator = response . getHeaders ( WWWAuthenticateHeader . NAME ) ; while ( authHeaderIterator . hasNext ( ) ) { WWWAuthenticateHeader wwwAuthHeader = ( WWWAuthenticateHeader ) authHeaderIterator . next ( ) ; removeStaleAuthHeaders ( wwwAuthHeader ) ; AuthInfoEntry authInfoEntry = authInfoImpl . getAuthInfo ( wwwAuthHeader . getRealm ( ) ) ; if ( authInfoEntry == null ) throw new SecurityException ( "Cannot add authorization header. No credentials for the following realm: " + wwwAuthHeader . getRealm ( ) ) ; addChallengeResponse ( wwwAuthHeader , authInfoEntry . getUserName ( ) , authInfoEntry . getPassword ( ) , this . getRequestURI ( ) . toString ( ) ) ; if ( cacheCredentials ) { getSipSession ( ) . getSipSessionSecurity ( ) . addCachedAuthInfo ( wwwAuthHeader . getRealm ( ) , authInfoEntry ) ; } } authHeaderIterator = response . getHeaders ( ProxyAuthenticateHeader . NAME ) ; while ( authHeaderIterator . hasNext ( ) ) { ProxyAuthenticateHeader proxyAuthHeader = ( ProxyAuthenticateHeader ) authHeaderIterator . next ( ) ; removeStaleAuthHeaders ( proxyAuthHeader ) ; AuthInfoEntry authInfoEntry = authInfoImpl . getAuthInfo ( proxyAuthHeader . getRealm ( ) ) ; if ( authInfoEntry == null ) throw new SecurityException ( "No credentials for the following realm: " + proxyAuthHeader . getRealm ( ) ) ; addChallengeResponse ( proxyAuthHeader , authInfoEntry . getUserName ( ) , authInfoEntry . getPassword ( ) , this . getRequestURI ( ) . toString ( ) ) ; if ( cacheCredentials ) { getSipSession ( ) . getSipSessionSecurity ( ) . addCachedAuthInfo ( proxyAuthHeader . getRealm ( ) , authInfoEntry ) ; } } }
/*
(non-Javadoc)
@see org.mobicents.javax.servlet.sip.SipServletRequestExt#addAuthHeader(javax.servlet.sip.SipServletResponse, javax.servlet.sip.AuthInfo, boolean)