加密Eureka服务器密码

时间:2015-03-17 17:11:22

标签: spring-cloud

有没有办法加密密码。我尝试下面的代码,但它不起作用(不使用spring-cloud-config)。

StandardPasswordEncoder encoder = new StandardPasswordEncoder("eurekaserverpassword");
String encryptedValue = encoder.encode("password");

生成的密码放在application.yml

security:
  user:
    password: '{cipher}3da45506d8dd45b29d5db2a52c23bd6bc2e129372846cc51cdb8397e2a641eb12dfbc61757ddcf42'

并在bootstrap.yml中定义了密钥

encrypt:
  key:eurekaserverpassword

我收到以下错误

UnsupportedOperationException: No decryption for FailsafeTextEncryptor. Did you configure the keystore correctly?

我没有使用非对称方法,为什么要查找密钥库?

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.eureka</groupId>
  <artifactId>eureka-server</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>com.demo.EurekaApplication</start-class>
    <java.version>1.7</java.version>
    <spring-cloud.version>1.0.0.RELEASE</spring-cloud.version>
  </properties>
  <name>Eureka Server</name>
  <description>Eureka Server</description>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency> 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
   </dependency> 
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-rsa</artifactId>
   </dependency>   
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.2.1.RELEASE</version>
        <executions>
            <execution>
                <goals>
                   <goal>repackage</goal>
                </goals>
             </execution>
        </executions>
        <configuration>
          <requiresUnpack>
            <dependency>
              <groupId>com.netflix.eureka</groupId>
              <artifactId>eureka-core</artifactId>
            </dependency>
            <dependency>
              <groupId>com.netflix.eureka</groupId>
              <artifactId>eureka-client</artifactId>
            </dependency>
          </requiresUnpack>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

1 个答案:

答案 0 :(得分:0)

它得到了解决。首先,我使用配置服务器加密我的密码,然后使用配置服务器(bootstrap.yml)中的密钥存储区详细信息到eureka-server bootstrap.yml。