cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco - Authentication token/ticket httprequest

pat9rv3sousa
Champ on-the-rise
Champ on-the-rise
I'm trying to access a file that I have on Alfresco, but I always get a 401 error - Unauthorized.

I'm trying to do something like this:


URL url = new URL (filepath);
String userPassword = user + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
URLConnection connection = url.openConnection();
uc.setRequestProperty("Authorization", "Basic " + encoding);


Then I use connection.getURL() and I open the stream to download the file into a byte[].

Unfortunately, the string userPassword cannot be accessed like this because I don't need to have access to the user and password of the current client that accesses the file. How can I get one token or something else to get authorization?

I make a javascript with connector.get (I think it's the same) but in java I don't find anything.

And other question, after making some modifications, as I return to update the same file?

EDIT: my question is not duplicated because I don't want to give username and password in the java code.
1 REPLY 1

openpj
Elite Collaborator
Elite Collaborator
Why don't use the OpenCMIS Client library?

OpenCMIS allows you to connect with your Alfresco and then manage your contents using a standard protocol without reinventing the wheel.

You practically have a Java stub for all the basics operations against the repository:
https://chemistry.apache.org/java/download.html

Hope this helps.