Skip to main content
I am using oAuth token to connect to salesforce in Java code. 

I have two salesforce org : one with older version that has an option to manually activate and deactivate the TLS version inside Critical Updates, another one is with new version where this option is removed and by default set to TLS1.2.

My code works perfectly for older version since there is no issue with TLS,because option for TLS1.0 and higher is deactivated , but no luck with the latter one.

I am using Java8 where TLS1.2 is set to default. 

Below is my java code :

String tokens = OAuthConnection.getUpdatedAccessToken( "https://login.salesforce.com/services/oauth2/token?", getOathToken("refresh_token",organization_id), propertiesDao.getConsumerOathKey(), propertiesDao.getSecret());

public static String[] getUpdatedAccessToken(String loginurl, String refresh_token,String customerKey, String secret){

String[] arr = new String[2];

String params = "grant_type=refresh_token&client_id="+customerKey+"&client_secret="+secret+"&refresh_token="+refresh_token;

try {

HttpUtility.sendGetRequest(loginurl+""+params);

String[] respons = HttpUtility.readMultipleLinesRespone();

JSONArray array;

StringBuilder temp = new StringBuilder();

for (String element : respons)

{

temp.append(element);

}

String singleLineResponse = temp.toString();

try {

array = new JSONArray("["+singleLineResponse+"]");

arr[0] = array.getJSONObject(0).getString("access_token");

arr[1] = array.getJSONObject(0).getString("id");

} catch (JSONException e) {

e.printStackTrace();

}

} catch (Exception e) {

e.printStackTrace();

}

finally{

HttpUtility.disconnect();

}

return arr;

}

I use this token to create salesforce connection further.

This gives error :

INVALID_LOGIN : Invalid username, password, security token; or user locked out.

So, I tried below code to use TLS1.2 before calling url :

System.setProperty("https.protocols", "TLSv1.2");

This works sometimes, but is inconsistent. Still gives same error. 

Please let me know how can I fix this issue.

 
1 answer
0/9000