Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client can't register to nacos server #3209

Closed
zhangruhong opened this issue Jun 30, 2020 · 3 comments
Closed

client can't register to nacos server #3209

zhangruhong opened this issue Jun 30, 2020 · 3 comments
Labels
status/duplicate This issue or pull request already exists

Comments

@zhangruhong
Copy link

zhangruhong commented Jun 30, 2020

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

error log when myapplication start

`java.lang.reflect.UndeclaredThrowableException: null

at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:147) ~[spring-core-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:73) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:76) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
at com.xxxxxx.aaaaaa.openguard.OpenGuardApplication.main(OpenGuardApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.8.RELEASE.jar:2.2.8.RELEASE]
Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all 
servers([nacos.xxxxxx.com:8848]) tried: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit 
mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Jun 30 15:13:32 CST 2020</div><div>There 
was an unexpected error (type=Forbidden, status=403).</div><div>unknown user!</div></body></html>
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:495) ~[nacos-client-1.3.0.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:400) ~[nacos-client-1.3.0.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:396) ~[nacos-client-1.3.0.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:213) ~[nacos-client-1.3.0.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:207) ~[nacos-client-1.3.0.jar:na]
at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:64) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE]
... 25 common frames omitted

Describe what you expected to happen

myapplication can't start

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

nacos server version is <NACOS1.3.0>
client application dependency as follows!

    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>nacos-client</artifactId>
                <groupId>com.alibaba.nacos</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.alibaba.nacos</groupId>
        <artifactId>nacos-client</artifactId>
        <version>1.3.0</version>
    </dependency>


<!--版本管理-->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

Anything else we need to know?

I've seen that client put username in paramValues but password in body, I guess this mistake case the problems!
D:/software/repository/com/alibaba/nacos/nacos-client/1.2.1/nacos-client-1.2.1-sources.jar!/com/alibaba/nacos/client/security/SecurityProxy.java:114

    if (StringUtils.isNotBlank(username)) {
        Map<String, String> params = new HashMap<String, String>(2);
        params.put("username", username);
        String body = "password=" + password;
        String url = "http://" + server + contextPath + LOGIN_URL;

        if (server.contains(Constants.HTTP_PREFIX)) {
            url = server + contextPath + LOGIN_URL;
        }

        HttpClient.HttpResult result = HttpClient.request(url, new ArrayList<String>(2),
            params, body, Charsets.UTF_8.name(), HttpMethod.POST);

com/alibaba/nacos/console/security/nacos/NacosAuthManager.java:118

    private String resolveToken(HttpServletRequest request) throws AccessException {
      String bearerToken = request.getHeader(NacosAuthConfig.AUTHORIZATION_HEADER);
      if (StringUtils.isNotBlank(bearerToken) && bearerToken.startsWith(TOKEN_PREFIX)) {
          return bearerToken.substring(7);
      }
      bearerToken = request.getParameter(Constants.ACCESS_TOKEN);
      if (StringUtils.isBlank(bearerToken)) {
          String userName = request.getParameter("username");
          String password = request.getParameter("password");
          bearerToken = resolveTokenFromUser(userName, password);
      }
      return bearerToken;
    }
@KomachiSion
Copy link
Collaborator

See #3144 .

@KomachiSion KomachiSion added the status/duplicate This issue or pull request already exists label Jun 30, 2020
@zhangruhong
Copy link
Author

See #3144 .

I seen it ,yes! it's really similar to #3144, but I didn't import config starter.
And I have already filled in the account number and password in bootstrap.yml as follows, But it doesn't work!

  spring:
	  cloud:
		nacos:
		  server-addr: nacos.xxxx.com:8848
		  discovery:
			namespace: 6c8f9613-1896-4e60-93af-xxxx
			group: dev
			username: xxxx_dev
			password: *****,.
	  application:
		name: xxx-xxx11

@KomachiSion
Copy link
Collaborator

spring.cloud.nacos.naming.username=nacos
spring.cloud.nacos.naming.password=nacos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants