Java Code Examples for com.google.common.net.InternetDomainName#isTopPrivateDomain()

The following examples show how to use com.google.common.net.InternetDomainName#isTopPrivateDomain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuth2CookieHelper.java    From cubeai with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the top level domain of the server from the request. This is used to limit the Cookie
 * to the top domain instead of the full domain name.
 * <p>
 * A lot of times, individual gateways of the same domain get their own subdomain but authentication
 * shall work across all subdomains of the top level domain.
 * <p>
 * For example, when sending a request to <code>app1.domain.com</code>,
 * this returns <code>.domain.com</code>.
 *
 * @param request the HTTP request we received from the client.
 * @return the top level domain to set the cookies for.
 * Returns null if the domain is not under a public suffix (.com, .co.uk), e.g. for localhost.
 */
private String getCookieDomain(HttpServletRequest request) {
    String domain = oAuth2Properties.getWebClientConfiguration().getCookieDomain();
    if (domain != null) {
        return domain;
    }
    //if not explicitly defined, use top-level domain
    domain = request.getServerName().toLowerCase();
    //strip off leading www.
    if (domain.startsWith("www.")) {
        domain = domain.substring(4);
    }
    //if it isn't an IP address
    if (!InetAddresses.isInetAddress(domain)) {
        //strip off subdomains, leaving the top level domain only
        InternetDomainName domainName = InternetDomainName.from(domain);
        if (domainName.isUnderPublicSuffix() && !domainName.isTopPrivateDomain()) {
            //preserve leading dot
            return "." + domainName.topPrivateDomain().toString();
        }
    }
    //no top-level domain, stick with default domain
    return null;
}
 
Example 2
Source File: DigitalAssetLinksRepository.java    From input-samples with Apache License 2.0 5 votes vote down vote up
public static String getCanonicalDomain(String domain) {
    InternetDomainName idn = InternetDomainName.from(domain);
    while (idn != null && !idn.isTopPrivateDomain()) {
        idn = idn.parent();
    }
    return idn == null ? null : idn.toString();
}
 
Example 3
Source File: DigitalAssetLinksRepository.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
public static String getCanonicalDomain(String domain) {
    InternetDomainName idn = InternetDomainName.from(domain);
    while (idn != null && !idn.isTopPrivateDomain()) {
        idn = idn.parent();
    }
    return idn == null ? null : idn.toString();
}