1

I have created a jhipster gateway and micro-service project along with a UAA server. It is working fine in my local environment. However, when I try to deploy it to a server and run it, I get an error similar to the below when I try to log in from the server-deployed gateway project:

Not a valid Domain name

Error :

    2018-01-25 12:02:42.242 DEBUG 10852 --- [  XNIO-2 task-6] w.i.s.o.OAuth2TokenEndpointClientAdapter : contacting OAuth2 token endpoint to login user: admin
2018-01-25 12:02:42.419 ERROR 10852 --- [  XNIO-2 task-6] c.w.i.s.o.OAuth2AuthenticationService    : failed to get OAuth2 tokens from UAA

java.lang.IllegalArgumentException: Not a valid domain name: '192.168.0.202'
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:210)
        at com.google.common.net.InternetDomainName.<init>(InternetDomainName.java:155)
        at com.google.common.net.InternetDomainName.from(InternetDomainName.java:216)
        at com.wdsi.iloads.security.oauth2.OAuth2CookieHelper.getCookieDomain(OAuth2CookieHelper.java:296)
        at com.wdsi.iloads.security.oauth2.OAuth2CookieHelper.createCookies(OAuth2CookieHelper.java:109)
        at com.wdsi.iloads.security.oauth2.OAuth2AuthenticationService.authenticate(OAuth2AuthenticationService.java:70)
        at com.wdsi.iloads.web.rest.AuthResource.authenticate(AuthResource.java:51)
        at com.wdsi.iloads.web.rest.AuthResource$$FastClassBySpringCGLIB$$fdfdf7ca.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
        at com.wdsi.iloads.aop.logging.LoggingAspect.logAround(LoggingAspect.java:85)

Any help is appreciated.

Agi Hammerthief
  • 2,114
  • 1
  • 22
  • 38

1 Answers1

4

This was fixed recently in JHipster's generator by this pull request.

To fix it locally in your project, edit OAuth2CookieHelper.java (in the security/oauth2/ package of your Java folder). Add an extra check for IP addresses before parsing the address as a domain name.

// add this import
import com.google.common.net.InetAddresses;


    // add this if-statement surrounding the domain name parsing
    // 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();
        }
    }
Jon Ruddell
  • 6,244
  • 1
  • 22
  • 40