3131import javax .servlet .sip .SipServletResponse ;
3232import javax .servlet .sip .SipURI ;
3333
34+ import org .apache .log4j .Logger ;
3435import org .restcomm .connect .dao .ClientsDao ;
3536import org .restcomm .connect .dao .DaoManager ;
3637import org .restcomm .connect .dao .entities .Client ;
4748 *
4849 */
4950public class CallControlHelper {
51+ private static Logger logger = Logger .getLogger (CallControlHelper .class );
5052
5153 static boolean permitted (final String authorization , final String method , DaoManager daoManager , final Sid organizationSid ) {
5254 final Map <String , String > map = authHeaderToMap (authorization );
@@ -66,8 +68,16 @@ static boolean permitted(final String authorization, final String method, DaoMan
6668 final String password2 = client .getPassword ();
6769 final String result = DigestAuthentication .response (algorithm , user , realm , "" , password2 , nonce , nc , cnonce ,
6870 method , uri , null , qop );
71+ if (logger .isDebugEnabled ()) {
72+ String msg = String .format ("Provided response [%s], generated response [%s]" , response , result );
73+ logger .debug (msg );
74+ }
6975 return result .equals (response );
7076 } else {
77+ if (logger .isDebugEnabled ()) {
78+ String msg = String .format ("Authorization check failed, [if(client==null) evaluates %s] or [if(client.getStatus()==Client.ENABLED) evaluates %s]" , client !=null , Client .ENABLED == client .getStatus ());
79+ logger .debug (msg );
80+ }
7181 return false ;
7282 }
7383 }
@@ -85,6 +95,10 @@ public static boolean checkAuthentication(SipServletRequest request, DaoManager
8595 final String authorization = request .getHeader ("Proxy-Authorization" );
8696 final String method = request .getMethod ();
8797 if (authorization == null || !CallControlHelper .permitted (authorization , method , storage , organizationSid )) {
98+ if (logger .isDebugEnabled ()) {
99+ String msg = String .format ("Either authorization header is null [if(authorization==null) evaluates %s], or CallControlHelper.permitted() method failed, will send \" 407 Proxy Authentication required\" " , authorization ==null );
100+ logger .debug (msg );
101+ }
88102 authenticate (request , storage .getOrganizationsDao ().getOrganization (organizationSid ).getDomainName ());
89103 return false ;
90104 } else {
0 commit comments