behavior and windows authenticated rest call

Showing results for 
Search instead for 
Did you mean: 

behavior and windows authenticated rest call

Hi all!

This one is unusual so I hope it will be a challenge for alfresco veterans Smiley Happy

I need to make a windows authenticated REST API call from a behavior bound to a onContentRead policy. Windows authentication must be provided from a user that triggered onContentRead event. Is there any possible way to do this?

2 Replies
Senior Member

Re: behavior and windows authenticated rest call

Are you trying to call out to an external (non Alfresco API) from within your behavior code? Not quite sure I understand the question here.


Re: behavior and windows authenticated rest call

Sorry i wasn't clear in the start: I'm trying to call external REST using windows authentication of the user that triggered the event.
I'm using AuthenticationUtils and I can get the username of the user that initiated the event but I can't seem to get NTML authentication provider to use with http client making the request. Also, I tried to use the Apache WinHttpCLient to make the REST API call but with no success. This is the code:

CloseableHttpClient client = WinHttpClients.createDefault();
try {
URI uri = URI.create(uriString);
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = client.execute(httpGet);
HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.toString(responseEntity, "UTF-8");
return responseString;
} catch (ParseException | IOException e) {
logger.error("executeImpl Error: " + e.toString());
return "error";

It's interesting that the above code works when sending POST to external REST service from the ServiceTask in Process Services (in the implementation of the JavaDelegate interface).
Any help would be appreciated.