使用 Spring Cloud Config 未获取加密值?

Using Spring Cloud Config not getting encrypted value?

我正在试验 Spring 云配置服务器 encryption/decryption 配置值。

为此,在Config Server项目下做了如下修改:

bootstrap.properties

encrypt.key=abcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh

我还在 Ubuntu 18.04 机器上使用以下命令更新了 JCE:

sudo apt install oracle-java8-unlimited-jce-policy

但是在发出 POST 请求后,我没有看到任何响应。

理想情况下,请求正文的加密文本应该作为响应出现。

示例项目:https://github.com/Omkar-Shetkar/pluralsight-springcloud-m2-git

这里可能遗漏了什么?

谢谢。

实际上是由于 CSRF,正在收到 401 未经授权的响应。由于 Spring Boot 2.0,我们可以在代码中禁用它。

这里有详细的答案: spring config server encrypt forbidden

按照上述步骤解决了问题。

只是放在那里,如果有人被我的愚蠢错误所困扰,即使在做了以上所有事情之后,如果 /encrypt 端点仍然没有被授权。

请检查您的安全适配器class。如果你也重写了下面的方法

  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication()
        .withUser("user")
        .password(passwordEncoder().encode(userPassword))
        .roles("USER")
        .and()
        .withUser("admin")
        .password(passwordEncoder().encode(adminPassword))
        .roles("USER", "ADMIN");
  }

您需要在“授权”选项卡的“基本身份验证”选项下提供这些凭据