使用VersionOne访问令牌的Java SDK身份验证
我正在尝试使用v1javasdk和v1access令牌对我的VersionOne实例进行身份验证。我按照文档进行操作,并准备将其付诸实施 问题是,我一直遇到一个ConnectionException,声明“401无法验证”消息(下面是堆栈跟踪)。这可能是什么原因造成的使用VersionOne访问令牌的Java SDK身份验证,java,access-token,versionone,Java,Access Token,Versionone,我正在尝试使用v1javasdk和v1access令牌对我的VersionOne实例进行身份验证。我按照文档进行操作,并准备将其付诸实施 问题是,我一直遇到一个ConnectionException,声明“401无法验证”消息(下面是堆栈跟踪)。这可能是什么原因造成的 开发环境 使用Windows集成身份验证的VersionOne Winter'15(15.0.13.7283) VersionOne.SDK.Java.APIClient 15.0.0 源代码 // build the
开发环境
// 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)
堆栈跟踪
// 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();
v1连接器=v1连接器
.withInstanceUrl(“”)
.withUserAgentHeader(“AppName”、“1.0”)
.withAccessToken(“1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=”)
.UseAuthendPoints()使用
.build();
请注意,对于NTLM配置的实例,只需使用UseAuthendPoints()方法
VersionOne Java SDK连接文档可在此处找到:是否能够使用.withWindowsIntegrated()方法进行身份验证?使用.withWindowsIntegrated()方法创建连接器效果良好。问题是,我们希望使用当前登录到计算机之外的帐户连接到VersionOne实例。除此之外,我还尝试使用当前windows用户的访问令牌,但没有成功。这是Java SDK的一个缺陷,VersionOne正在修复。