Java 使用 VersionOne 访问令牌的 SDK 身份验证

Java SDK Authentication with VersionOne Access Tokens

我正在尝试使用 V1 Java SDK 和 V1 访问令牌对我的 VersionOne 实例进行身份验证。我按照 creating acess tokens and creating a connection 的文档准备让它工作。

问题是我将 运行 保存到 ConnectionException 中,声明“401 无法验证”消息(下面的堆栈跟踪)。可能是什么原因造成的?


开发环境

  1. VersionOne Winter '15 (15.0.13.7283) 使用 Windows 集成身份验证
  2. VersionOne.SDK.Java.APIClient 15.0.0

源代码

    // build the connector using an access token
    V1Connector connector = V1Connector.withInstanceUrl("https://servername/instancetoauthenticate")
        .withUserAgentHeader("Application", "1.0")
        .withAccessToken("1.WkEciqwKNW7Pnvw9CNmPgQWIdL4=")
        .build();

    // use the connector to instantiate a Services object
    IServices services = new Services(connector);

    // check the logged in member
    Oid oid = services.loggedIn;
    System.out.println("Member Oid: " + oid);

堆栈跟踪

Exception in thread "main" com.versionone.apiclient.exceptions.ConnectionException:
HTTP/1.1 401 Unauthorized error code: 401 Could not authenticate. The VersionOne credentials may be incorrect or the access tokens may have expired.
    at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:423)
    at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
    at com.versionone.apiclient.Services.retrieve(Services.java:114)
    at com.versionone.apiclient.Services.getLoggedIn(Services.java:254)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:73)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at com.netsuite.versionone.exporttasks.Authenticator.main(Authenticator.groovy:30)

从 Java SDK 的 15.1.0 版本开始,您可以使用访问令牌连接到 VersionOne 实例,即使该实例配置为使用 Windows 集成身份验证。诀窍是使用 V1Connector 的新 useOAuthEndpoints() 方法:

V1Connector connector = V1Connector
    .withInstanceUrl("<Server Base URI>")
    .withUserAgentHeader("AppName", "1.0")
    .withAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
    .useOAuthEndpoints()
    .build();

请注意,您只需为 NTLM 配置的实例使用 useOAuthEndpoints() 方法。

VersionOne Java SDK 连接文档可在此处找到:https://community.versionone.com/Developers/Developer-Library/Documentation/Java_SDK/Creating_a_Connection