cancel
Showing results for 
Search instead for 
Did you mean: 

Portal Authentication from Java

Former Member
0 Kudos

Hi all,

I need to open a file from KM using its absolute URL (i.e. http://<hostname>/irj/.../<filename>) from a WD java.

I tried to use the URL class to access this file but I have 401 error.

How can I authenticate to the portal from Java?

Best Regards,

Raffaele Frattini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

How can I authenticate to the portal from Java?

You can use the HTTPClient which is available from apache to do this in Java, If its webdynpro do what sanyev have mentioned above

HTTPClient and its corresponding jars can be downloaded from apache website.

Regards

Ayyapparaj

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi ,

first of all thanks for all your replies, however Sanyev solution doesn't work, because I try to open a new Http connection which is independent from the connection to the portal.

But I found a solution, using the class HttpURLConnection and the method setRequestProperty of this class.

Best Regards,

Raffaele Frattini

Former Member
0 Kudos

Hi Raffaele ,

How did you use the class and the method mentioned to solve the problem.

Could you please provide us the code?

Thanks in advance

Former Member
0 Kudos

Hi Venkata,

below you can find some code lines neded for the Basic Authentication:

URL url = new URL("The URL in String format");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

String userPass = <username> + ":"+ <password>;

String encoding = new BASE64Encoder().encode(userPass.getBytes());

conn.setRequestProperty("Authorization", "Basic " + encoding);

InputStream in = conn.getInputStream();

I hope this help you.

Regards,

Raffaele Frattini

Former Member
0 Kudos

Hi,

I've already tried to do this, but it doesn't work.

Any other suggestion?

Best Regards,

Raffaele Frattini

sanyev
Active Participant
0 Kudos

Hi Raffaele,

When you are accessing the KM folders through webdynpro, Webdynpro will use the same user permission to access the file. If that user does not have permission to access the content then you will get an authentication error.

So while testing the application it might not work. Integrate your application to the portal and try. Then it will use the logged in user to access the KM folder and if the user has permission it should work.

Regards,

Sanyev

Former Member
0 Kudos

Hi

You can set the Application property Authentication to true in your application. Just open your Webdynpro application and then go to properties. Just add Authentication as a property and set the value to true.

Thanks,

Prasanthi.