Foros de discusión

(401)Unauthorized while accessing web service Liferay 6

thumbnail
Hir O, modificado hace 12 años.

(401)Unauthorized while accessing web service Liferay 6

Junior Member Mensajes: 30 Fecha de incorporación: 14/03/12 Mensajes recientes
Hi All,

I am trying to access web services in Liferay 6. I am using the following code.

java.net.URL url = new java.net.URL("http://test%40liferay.com:ldap@localhost:8080/tunnel-web/secure/axis/Portal_PermissionService");
cachedEndpoint = url;


I am getting (401) Unauthorized error and I am unable to access the services.

I am using Axis 1, and have generated stubs using SOAP UI.

I have implemented custom authorization, and that class actually gets called, I replaced %40 in the email address with @ (as I am have replaced @ symbol with %40 in the URL above) string in my custom authentication class and not that function returns success(i.e. 1) but still web service is unable to access the resources

I have in parallel tried the following as well

java.net.URL url1 = new java.net.URL("http://test%40liferay.com:ldap@localhost:8080/tunnel-web/secure/axis/Portal_PermissionService");
PermissionServiceSoap permissionService = service.getPortal_PermissionService(url1);
((Portal_PermissionServiceSoapBindingStub) permissionService).setUsername("test%40liferay.com");
((Portal_PermissionServiceSoapBindingStub)permissionService).setPassword("ldap");



Please help me solve this issue.
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Please check the following page. The sample is written for 6.0.5, but the concept is still the same.

http://www.liferay.com/community/wiki/-/wiki/Main/Web+Service+samples
thumbnail
Hir O, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Junior Member Mensajes: 30 Fecha de incorporación: 14/03/12 Mensajes recientes
Hi Hitoshi,

Thanks for replying. I am not finding any of the files in my package from your link.

Please look at my following approach at calling axis ws from axis ws client.

I have my code generated from SOAP UI and have written a main function in PermissionServiceSoapBindingStub.java to test the WS currently and the code in the main is as follows

main() {
Portal_PermissionServiceSoapBindingStub stub = new Portal_PermissionServiceSoapBindingStub();
stub.checkPermission(10149, 311);
}

public void PermissionServiceSoapBindingStub() {
//constructor
this(null);
java.net.URL url = getURL();
cachedEndpoint = url;
PermissionServiceSoapService service = new PermissionServiceSoapServiceLocator();

java.net.URL url1 = getURL1();
System.out.println("url1:" + url1);
PermissionServiceSoap permissionService = service.getPortal_PermissionService(url1);
((Portal_PermissionServiceSoapBindingStub) permissionService).setUsername("test%40liferay.com");
((Portal_PermissionServiceSoapBindingStub)permissionService).setPassword("ldap");
}


Please let me know if my approach of calling this axis client is wrong.
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Are you generating your own stub instead of using the one provided by Liferay in their SDK?
thumbnail
Hir O, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Junior Member Mensajes: 30 Fecha de incorporación: 14/03/12 Mensajes recientes
Hi Hitoshi,

Thanks for replying again. I don't know how to use this. I had seen the above link, but in my sdk I didn't found any of the file. Can you please provide me with some other links for this?

Thanks
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Sorry, I wrote that page some time ago. I think I've included what's needed to build in the sample download. When I have the time, I'll add the information on requirements and on building to the wiki page.

BTW, did you get liferay-portal-dependencies? I think that was required too.
thumbnail
Hir O, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Junior Member Mensajes: 30 Fecha de incorporación: 14/03/12 Mensajes recientes
and can't I use this ws through my own stubs?
thumbnail
Paul ., modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
Hi Hir O,

In case it helps, I was working on something similar, from you post it seems you are using http://127.0.0.1:8080/api/axis/Portal_PermissionService?wsdl

I built the client for Asset Category (
http://localhost:8080/api/axis/Portlet_Asset_AssetCategoryService?wsdl
) , if you'd generate the client using a java IDE for this one, it will generate "AssetCategoryServiceSoapServiceLocator.java" which contain the url of the form
http://localhost:8080/api/axis/Portlet_Asset_AssetCategoryService

In order to initialize the permission checker, you need to modify it slightly to the from
http://localhost:8080/api/secure/axis/Portlet_Asset_AssetCategoryService


And then in the client provide the username / password using:-
AssetCategoryServiceSoapServiceLocator locator = new AssetCategoryServiceSoapServiceLocator();
AssetCategoryServiceSoap portlet_Asset_AssetCategoryService = locator.getPortlet_Asset_AssetCategoryService();
((Portlet_Asset_AssetCategoryServiceSoapBindingStub) portlet_Asset_AssetCategoryService).setUsername("test@liferay.com");
((Portlet_Asset_AssetCategoryServiceSoapBindingStub) portlet_Asset_AssetCategoryService).setPassword("test");


which should work.

Hope it helps.
thumbnail
Hir O, modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Junior Member Mensajes: 30 Fecha de incorporación: 14/03/12 Mensajes recientes
Hi Paul
I tried this but still the same..

I have "/tunnel-web/" instead of "/api/" in URL.

I tried with both this simple url and merging email ids with URL as well but still it's not working


Please let me know is there are some points to take care of or there is some other approach
thumbnail
Paul ., modificado hace 12 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
The implementation snippet I gave is for Liferay 6.1 , even if I try to open
http://127.0.0.1:8080/tunnel-web/axis

it's redirect to
http://127.0.0.1:8080/api/axis
on browser.

Did you change the access url in service Locator as well? (assuming it's 6.1) it should work.

It's important that in service locator url should be of the form
http://localhost:8080/api/secure/axis/Portlet_Asset_AssetCategoryService
for 6.1
Smilelws2010 lwz, modificado hace 11 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Regular Member Mensajes: 160 Fecha de incorporación: 16/12/10 Mensajes recientes
Hi Bart,
I have a slightly different question, I have a service builder which is working fine and I can remotely access the service too. But whenever a user tries to hit the service it asks for username, passowrd auhentication. I want to bypass the authentication part while accessing services. Is it possible?

Even if I am logged in at the time of making the service call, when you actually hit the service url on a browser it says "you must log in to area “PortalRealm” on localhost:8080." is there a way to avoid this.
thumbnail
Bart Simpson, modificado hace 11 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
yes, it's possible to access it, better option would be to supply the credentials in client created for the service. I have posted a way to get this done on http://www.liferay.com/community/forums/-/message_boards/message/15037937
Otherwise you will have to change liferay's code to remove the authentication. I'd suggest doing it by passing the credentials.
Smilelws2010 lwz, modificado hace 11 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Regular Member Mensajes: 160 Fecha de incorporación: 16/12/10 Mensajes recientes
Thanks Bart for the suggestion and redirecting to post. Will have to try out.

I had another question, again related to service builder. My service builder portlet works on tomcat and can access remote services as I said before, but when I deployed the same portlet on WebLogic environment , even the portlet got deployed and the methods are working form within the portlet, I am not able to access the services remotely.

Any idea?

Thanks
Smile
thumbnail
Bart Simpson, modificado hace 11 años.

RE: (401)Unauthorized while accessing web service Liferay 6

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
There could be an issue on how the service interface are shared across, and therefore may not be accessible, as sharing libraries is different then how it's done in tomcat. Additionally it also is dependent on your server setup / configuration. Managed servers are more strict in access of shared libraries. It would help to pinpoint the issue if you could share any exception appears on the console.
suneel kumar, modificado hace 8 años.

RE: (401)Unauthorized while accessing web service Liferay 6

New Member Mensajes: 15 Fecha de incorporación: 15/09/15 Mensajes recientes
remoteUser = "test";
password = "test";
String url = "http://" + remoteUser + ":" + password + "@localhost:8080/api/secure/axis/" + serviceName;
when i run this url i got this exception. can anybody help me?

Jan 27, 2016 6:16:25 PM org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Unauthorized
faultActor:
faultNode:
faultDetail:
{}:return code: 401
<html><head><title>Apache Tomcat/7.0.27 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-coloremoticon525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-coloremoticon525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-coloremoticon525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-coloremoticon525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.27</h3></body></html>
{http://xml.apache.org/axis/}HttpErrorCode:401

(401)Unauthorized
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.liferay.client.soap.portal.service.http.Portal_CompanyServiceSoapBindingStub.getCompanyByVirtualHost(Portal_CompanyServiceSoapBindingStub.java:495)
at Org.main(Org.java:34)
suneel kumar, modificado hace 8 años.

RE: (401)Unauthorized while accessing web service Liferay 6

New Member Mensajes: 15 Fecha de incorporación: 15/09/15 Mensajes recientes
Hi all,
Yessssss.......... I got that issue....

Just change the authentication type as ScreenName in portal-ext.properties file and control panel-->Portal setting-->Authentication

company.security.auth.type=screenName