Question about authentication with VersionOne.SDK.Java.APIClient

75 views
Skip to first unread message

Saxon, Will

unread,
Sep 23, 2014, 7:09:47 AM9/23/14
to version...@googlegroups.com

Hello,

 

I am trying to use the Java API client against a hosted V1 instance.

 

The 'GettingStarted' example code linked from readme.md uses an EnvironmentContext to set everything up. This appears to depend on editing the APIConfiguration.properties file in the api client jar. I do not want to do this; my integration needs to accept the username and password at runtime.

 

I'm creating instances of V1APIConnector with the appropriate URL, username and password, then passing those into the constructors for MetaModel and Services. Later I try to pass a Query to Services.retrieve(). As soon as I do, I get a SecurityException() from V1APIConnector.getData().

 

I inspected the traffic at this point and it looks like the credentials are not being processed for some reason. The initial connection attempt has no authentication header, and after the 401 error is returned by the server there is no followup - the SecurityException() is generated instead. When I catch the exception and print out the user/pass, they are correct; if I test the same URLs and credentials in a browser they work fine.

 

The Authenticator/Credentials stuff in V1APIConnector.java looks like it should work based on the docs (http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-auth.html), so I am not sure why this is happening.

 

I am going to try rolling my own basic auth header and sticking it in V1APIConnector.customHttpHeaders, but I don't think this is the right way to use the SDK. What am I doing wrong?

 

Thanks,

 

-Will

NOTICE: This e-mail message and all attachments transmitted with it may contain legally privileged and confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by electronic mail and delete this message and all copies and backups thereof. Thank you. Greenway Health.

Acey Bunch

unread,
Sep 23, 2014, 7:30:36 AM9/23/14
to version...@googlegroups.com, will....@greenwayhealth.com
Hi Will,

Sounds like you are doing everything right, using the V1APIConnector is definitely the way to go. First I would double check that your URL, username, and password are correct.

Second, compare the following to what you are using (updating the URL and credentials to match your environment):

private static IMetaModel metaModel;
private static IServices dataService;
private final static String V1_URL = "http://{server}/{instance}/;
private final static String V1_USERNAME = "{username}";
private final static String V1_PASSWORD = "{password}";
private final static String DATA_PATH = "rest-1.v1/";
private final static String META_PATH = "meta.v1/";
    
private static V1APIConnector dataConnector;
private static V1APIConnector metaConnector;

public static void main(String[] args) {
connectToV1();
}
public static void connectToV1() {
try
{
            dataConnector = new V1APIConnector(V1_URL + DATA_PATH, V1_USERNAME, V1_PASSWORD);
            metaConnector = new V1APIConnector(V1_URL + META_PATH);
            
            metaModel = new MetaModel(metaConnector);
            dataService = new Services(metaModel, dataConnector);
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}

If those two suggestions do not resolve the issue, open a ticket with VersionOne Support so that we can help you troubleshoot.

Hope this helps...

Acey Bunch
VersionOne

Saxon, Will

unread,
Sep 23, 2014, 9:39:58 AM9/23/14
to Acey Bunch, version...@googlegroups.com

I figured this out as soon as I sent the mail. It was a dumb error – checking if username was null vs. not null incorrectly. I was never sending credentials if they were present.

 

Sorry for the list noise.

 

-Will

Reply all
Reply to author
Forward
0 new messages