当前位置: 首页 > 知识库问答 >
问题:

Spring AppRoleAuthentication错误-URI不是绝对的

卢出野
2023-03-14

我正试图使用AppRole身份验证从保险库中检索机密。但我得到了一个错误:

IllegalArgumentException:URI不是绝对的

我使用spring-vault-core-2.2.0.release

下面是我的代码:

VaultEndpoint ep = VaultEndpoint.create(host, portInt);
    if (scheme != null) {
        ep.setScheme(scheme);
    }

    if (authMethod.equals("token")) {
        vaultTemplate = new VaultTemplate(ep, new TokenAuthentication(token));

    } else if (authMethod.equals("appRole")) {

        RestOperations restOperations = VaultClients.createRestTemplate();

        AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
                .roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId))
                .secretId(AppRoleAuthenticationOptions.SecretId.wrapped(VaultToken.of(secretId))).build();

        vaultTemplate = new VaultTemplate(ep, new AppRoleAuthentication(options, restOperations));
    }
  }

如果尝试获取vaultToken,也会出现相同的错误:

            RestOperations restOperations = VaultClients.createRestTemplate();
        AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
                .roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId))
                .secretId(AppRoleAuthenticationOptions.SecretId.wrapped(VaultToken.of(uncryptedSecretId))).build();

        AppRoleAuthentication appRoleAuth = new AppRoleAuthentication(options, restOperations);
        VaultToken appRoleToken = appRoleAuth.login();
java.lang.IllegalArgumentException: URI is not absolute
    at java.net.URI.toURL(Unknown Source)
    at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:98)
    at org.springframework.vault.client.VaultClients.lambda$createRestTemplate$0(VaultClients.java:128)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:586)
    at org.springframework.vault.authentication.AppRoleAuthentication.getSecretId(AppRoleAuthentication.java:305)
    at org.springframework.vault.authentication.AppRoleAuthentication.getAppRoleLoginBody(AppRoleAuthentication.java:344)
    at org.springframework.vault.authentication.AppRoleAuthentication.createTokenUsingAppRole(AppRoleAuthentication.java:201)
    at org.springframework.vault.authentication.AppRoleAuthentication.login(AppRoleAuthentication.java:191)
public class AppRoleAuthenticationService extends AbstractVaultConfiguration {

private String roleId;
private String secretId;
private String host;
private String scheme;
private String port;

public AppRoleAuthenticationService(String roleId, String secretId, String host, String scheme, String port) {
    this.roleId = roleId;
    this.secretId = secretId;
    this.host = host;
    this.scheme = scheme;
    this.port = port;
}

@Override
public VaultEndpoint vaultEndpoint() {
    int portInt = Integer.parseInt(port);
    VaultEndpoint ep = VaultEndpoint.create(host, portInt);
    if (scheme != null) {
        ep.setScheme(scheme);
    }

    return ep;
}

@Override
public ClientAuthentication clientAuthentication() {

    AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
            .roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId))
            .secretId(AppRoleAuthenticationOptions.SecretId.provided(secretId)).build();

    return new AppRoleAuthentication(options, restOperations());
}
AppRoleAuthenticationService appRoleAuth = new AppRoleAuthenticationService(roleId, 
      uncryptedSecretId, host, scheme, port);
VaultEndpoint vaultEp = appRoleAuth.vaultEndpoint();
ClientAuthentication auth = appRoleAuth.clientAuthentication();

vaultTemplate = new VaultTemplate(vaultEp, auth);

共有1个答案

苗盛
2023-03-14

我设法解决了我的问题,我更新了原来的帖子分享答案。

 类似资料:
  • 问题内容: 以下代码段用于使用Restful API调用我的Web服务。 并在运行上述代码时获取此异常 我用谷歌搜索了很多文章,却没有弄错我做错了什么。 旁注: 在Apache tomacat7中的机器上部署了war 问题答案: 绝对URI指定方案;并非绝对的URI被认为是相对的。 http://docs.oracle.com/javase/8/docs/api/java/net/URI.html

  • 我有一个奇怪的问题。我只是想做一个基本的显示相对路径的目录内容。 在桌面上创建了一个测试目录 测试目录内容 测试内容。派克 摘要-绝对路径 工程-在视觉工作室代码 works-macOS终端python3 /Users/username/Desktop/test/test.py 但是,当使用变量时,我得到一个错误: 测试内容。派克 摘要-相对路径 作品-在visual studio代码中 错误-m

  • 为了尝试使用jstl,我用Maven安装了JSTL1.2库。但是,当我通过以下消息运行jsp页面时,“绝对URI:[http://java.sun.com/jsp/jstl/core]不能在web.xml或与此应用程序一起部署的jar文件中解析” 我已经阅读了这个stackoverflow页面,按照我的要求做了,但它并没有解决我的问题。 这是我的web.xml文件中简洁的一部分。 这是我的jsp代

  • 下面的代码片段用于使用restful API调用我的web服务。 并在运行上述代码时获取此异常 我在谷歌上搜索了很多文章,没有找到我做错的地方。 旁注:war在我的机器上部署在Apache tomacat7中

  • 问题内容: 我是GO的新手,在Windows中初始化GOPATH时遇到错误。在我的项目文件夹中是 C:\ Users \ kamin \ Documents \ pm-manager 我试图在环境变量(GOPATH)中设置路径,但是却出错了:GOPATH条目是相对的;必须为绝对路径:“:/ cygdrive / c / Users / kamin / Documents / pm-manager

  • 我有一个云负载平衡器/虚拟服务器/防火墙,它位于一组Quarkus pod前面,几乎就像一个反向代理。流量通过该公共入口进入,并被重新路由到内部网络。 我们使用Azure B2C登录应用程序,当您直接访问pod或内部负载平衡器时,这一功能非常好。 问题是,当使用外部负载平衡器时,重定向uri位于内部网络的上下文中,无法从公共端访问。 有没有办法将指向外部服务器的重定向uri设置为绝对uri而不是相