java .lang.IllegalArgumentException: недопустимый символ в авторитете в индексе 7 - PullRequest
0 голосов
/ 25 марта 2020

Я работаю на микросервисах и пытаюсь перенести всю свою конфигурацию в централизованный конфиг. Однако я не уверен, но что-то не так с кодировкой, расшифровкой или парсингом пароля для Spring Cloud Eureka (или URL-адрес в порядке, и он надежно защищен, потому что есть пароль?). Это то, что я получаю при запуске docker-compose up. Эти исключения генерируются для каждого из микросервисов.

movie_1            | java.lang.IllegalArgumentException: Illegal character in authority at index 7: http://u:${app.eureka-password}@eureka:8761/eureka/
movie_1            |    at java.base/java.net.URI.create(URI.java:906) ~[na:na]
movie_1            |    at com.sun.jersey.api.client.Client.resource(Client.java:434) ~[jersey-client-1.19.1.jar!/:1.19.1]
movie_1            |    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplicationsInternal(AbstractJerseyEurekaHttpClient.java:187) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplications(AbstractJerseyEurekaHttpClient.java:165) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1051) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:965) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1479) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1446) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
movie_1            |    at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]
movie_1            | Caused by: java.net.URISyntaxException: Illegal character in authority at index 7: http://u:${app.eureka-password}@eureka:8761/eureka/
movie_1            |    at java.base/java.net.URI$Parser.fail(URI.java:2936) ~[na:na]
movie_1            |    at java.base/java.net.URI$Parser.parseAuthority(URI.java:3270) ~[na:na]
movie_1            |    at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3181) ~[na:na]
movie_1            |    at java.base/java.net.URI$Parser.parse(URI.java:3137) ~[na:na]
movie_1            |    at java.base/java.net.URI.<init>(URI.java:623) ~[na:na]
movie_1            |    at java.base/java.net.URI.create(URI.java:904) ~[na:na]
movie_1            |    ... 25 common frames omitted
movie_1            | 
movie_1            | 2020-03-25 04:41:03.276  WARN 1 --- [freshExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: Illegal character in authority at index 7: http://u:${app.eureka-password}@eureka:8761/eureka/
movie_1            | 2020-03-25 04:41:03.276 ERROR 1 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_MOVIE/ef7c617370f2:movie:8080 - was unable to refresh its cache! status = Cannot execute request on any known server
movie_1            | 
movie_1            | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
movie_1            |    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1051) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:965) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1479) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1446) ~[eureka-client-1.9.8.jar!/:1.9.8]
movie_1            |    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
movie_1            |    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
movie_1            |    at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]
movie_1          

Вот так выглядит мой глобальный файл конфигурации: более того (из-за курса, из которого этот код) эти зашифрованные значения должны выглядеть следующим образом:

app.eureka-password: p 
spring.rabbitmq,password: quest

Весь этот код работает на старой сборке, где нет централизованной конфигурации и код не зашифрован. `

application.yml

app:
  eureka-username: u
  eureka-password: '{cipher}bf298f6d5f878b342f9e44bec08cb9ac00b4ce57e98316f030194a225fac89fb'
  eureka-server: localhost
  auth-server: localhost

eureka:
  client:
    serviceUrl:
      defaultZone: "http://${app.eureka-username}:${app.eureka-password}@${app.eureka-server}:8761/eureka/"
    initialInstanceInfoReplicationIntervalSeconds: 5
    registryFetchIntervalSeconds: 5
  instance:
    leaseRenewalIntervalInSeconds: 5
    leaseExpirationDurationInSeconds: 5

spring.rabbitmq:
  host: 127.0.0.1
  port: 5672
  username: guest
  password: '{cipher}17fcf0ae5b8c5cf87de6875b699be4a1746dd493a99d926c7a26a68c422117ef'

spring.cloud.stream.kafka.binder:
  brokers: 127.0.0.1
  defaultBrokerPort: 9092

# WARNING: Exposing all management endpoints over http should only be used during development, must be locked down in production!
management.endpoint.health.show-details: "ALWAYS"
management.endpoints.web.exposure.include: "*"

---
spring.profiles: docker

spring.rabbitmq.host: rabbitmq

spring.cloud.stream.kafka.binder.brokers: kafka

app:
  eureka-server: eureka
  auth-server: auth-server

Когда я заменяю эти зашифрованные данные и строю проект снова, я получаю что-то вроде:

ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN

Пожалуйста дайте мне знать, если вам нужна дополнительная информация или код. Любые идеи, помощь будет оценена.

Если речь идет о сервере eureka, есть только несколько строк кода:

Основной класс:

@Slf4j
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

Конфигурация безопасности:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final String username;
    private final String password;

    @Autowired
    public SecurityConfig(
        @Value("${app.eureka-username}") String username,
        @Value("${app.eureka-password}") String password
    ) {
        this.username = username;
        this.password = password;
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(NoOpPasswordEncoder.getInstance())
                .withUser(username).password(password)
                .authorities("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .httpBasic();
    }
}

и bootstrap .yml:

app.config-server: localhost

spring:
  application.name: eureka-server
  cloud.config:
    failFast: true
    retry:
      initialInterval: 3000
      multiplier: 1.3
      maxInterval: 10000
      maxAttempts: 20
    uri: http://${CONFIG_SERVER_USR}:${CONFIG_SERVER_PWD}@${app.config-server}:8888

---
spring.profiles: docker

app.config-server: config-server

Есть идеи?

...