EurekaオープンHTTP Baic認証

2606 ワード

1つ エウレカ Server
1 設定ファイル
appication.yml
spring:
  profiles:
    active: security
appication-security.yml
server:
  port: 8761


spring:
  security:
    basic:
      enabled: true
    user:
      name: admin
      password: Xk38CNHigBP5jK75
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
      waitTimeInMsWhenSyncEmpty: 0
      enableSelfPreservation: false
2 csrfプロファイル
package cn.springcloud.book.config;


import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


/**
* Created by caibosi on 2018-06-25.
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http.csrf().disable();
    }
}
二番目 エウレカ Cient
1 appication.yml
spring:
  profiles:
    active: security
2 appication-security.yml
server:
  port: 8081


spring:
  application:
    name: client1


eureka:
  client:
    security:
      basic:
        user: admin
        password: Xk38CNHigBP5jK75
    serviceUrl:
      defaultZone: http://${eureka.client.security.basic.user}:${eureka.client.security.basic.password}@localhost:8761/eureka/
三番目 起動
1 Eurekaを起動します Server
mvn spring-boot:run -Dspring.profiles.active=security
2 Eurekaを起動します Cient
mvn spring-boot:run -Dspring.profiles.active=security
四番目 テスト
1 入力http://localhost:8761/eureka/apps
2 次のページをイジェクトして、ユーザー名とパスワードを入力します.
Eureka开启HTTP Basic认证_第1张图片
3 ポップアップの結果は以下の通りです
Eureka开启HTTP Basic认证_第2张图片