cancel
Showing results for 
Search instead for 
Did you mean: 

Opensearch query and Authenticated session with ticket

keepcool
Champ in-the-making
Champ in-the-making
Hi all,
I want my external application gets the content of alfresco repository by querying it. For this reason I use Alfresco Keyword Search to obtain an OpenSearch response from alfesco. To do that first I need to obtain an authenticated session by asking the ticket (because my application is in java I suppose that I have to use uthenticationUtils.startSession("admin","admin")), then I need to use this ticket in some way to work in an authenticated way with alfresco. Maybe I have to append the ticket to my opensearch query search, or invoke some method that takes this ticket as parameter.
Another  question: is there a different way to obtain an authenticathed work session?

I really hope that someone really could help me

best regards

A.
5 REPLIES 5

pmonks
Star Contributor
Star Contributor
For programmatic access to Alfresco it's generally a better idea to use REST (Web Scripts) and authenticate using HTTP Basic Authentication.  This is done by accessing Web Scripts via /alfresco/service, and doesn't require an explicit login call, nor does it require ticket management on the calling side.

For your specific case (OpenSearch) there is a REST API (Web Script) included in Alfresco.  You'll need to look at the Web Script registry to find it though, as I don't have ready access to an Alfresco instance at the moment to fund it myself.

Cheers,
Peter

keepcool
Champ in-the-making
Champ in-the-making
Dear Pmonks,

I used the opensearch url template, http://<host>:<port>/alfresco/service/api/search/keyword?q={searchTerms}&p={startPage?}&c={count?}&l={language?}, to query "alfresco repository". The problem is that the query returned the http 500 error "A valid SecureContext was not provided in the RequestContext"

Can you provide me instructions or examples to implement Http Basic Authentication?

Thank you for your support

A.

pmonks
Star Contributor
Star Contributor
HTTP Basic Authentication is defined in RFC2617 (http://www.ietf.org/rfc/rfc2617.txt).  Most HTTP client libraries include native support for it, although Java's java.net.URLConnection class doesn't, so if you're using Java a better bet is the Apache HTTP Client library (http://hc.apache.org/).

Cheers,
Peter

keepcool
Champ in-the-making
Champ in-the-making
Hi pmonks,
I've watched some examples class in the apache component distribution. I've also tried to use them for my purpose. For example I've tried to connect and authenticate to  alfresco using ClientAuthentication class, here the principal lines of code:

        DefaultHttpClient httpclient = new DefaultHttpClient();
        httpclient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080), new UsernamePasswordCredentials("admin", "admin"));       
   HttpGet httpget = new HttpGet("http://localhost:8080/alfresco/service/api/search/keyword.rss?q=lingo");

However I continue to obtain an http 500 error :"A valid SecureContext was not provided in the RequestContext". Specifing username and password, I was hoping to get an authenticated session, but it is not.
I also tried to use the class ClientInteractiveAuthentication but the result is the same. Maybe I'm not using it properly.

I really need advice
Thank you again for your valuable help

A.

analyzediz
Champ in-the-making
Champ in-the-making
I am the exact same problem. I am also using HttpClient. In my case I'm trying to use the WebDAV component of Alfresco to retrieve content. I keep getting Http 401 error code, which just means that it can't authorize me.

Here's the code that I'm using:

      DefaultHttpClient defaultClient = (DefaultHttpClient)client;
      
      List<String> authTargetSchemes = new ArrayList<String>();
      authTargetSchemes.add(AuthPolicy.BASIC);
      defaultClient.getParams().setParameter("http.auth.target-scheme-pref", authTargetSchemes);
      defaultClient.getParams().setParameter("http.protocol.handle-authentication", true);
      
      defaultClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", "8080", "webdav"),
            new UsernamePasswordCredentials(username, password));
      defaultClient.execute(method);

Any ideas?

Thanks.