public static boolean checkDomainMatchToUrl ( String cookieDomain , String urlHostName ) { try { if ( cookieDomain . startsWith ( "." ) ) { cookieDomain = cookieDomain . substring ( 1 ) ; } String [ ] domainTokens = cookieDomain . split ( "\\." ) ; String [ ] hostTokens = urlHostName . split ( "\\." ) ; int tokenDif = hostTokens . length - domainTokens . length ; if ( tokenDif < 0 ) { return false ; } for ( int i = domainTokens . length - 1 ; i >= 0 ; i -- ) { if ( ! domainTokens [ i ] . equalsIgnoreCase ( hostTokens [ i + tokenDif ] ) ) { return false ; } } return true ; } catch ( Exception e ) { return true ; } }
Helper method to check if url matches a cookie domain .