Forums

Home » Liferay Portal » English » Liferay Legacy

Combination View Flat View Tree View
Threads [ Previous | Next ]
Ken Ko
401 Unauthorized when calling webservice
August 26, 2007 4:07 PM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

Hi,

I have a newbie question, I am probably missing some simple configuration?

When calling the soap webservice, I am getting a (401)Unauthorized from the server, and tomcat message that says "This request required HTTP authentication".

This is the endpoint URL I am using (where 12345 is the userId of an admin user)
http://12345:qUqP5cyxm6YcTAhz05Hph5gvu9M=@localhost:8015/tunnel-web/secure/axis/Portal_UserService

I have tried using the code from sample-portal-client-portlet.war as well as calling directly with Axis, with the same results...

Any ideas what is wrong?
Ken Ko
RE: 401 Unauthorized when calling webservice
August 26, 2007 4:53 PM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

When I try to hit in the browser...
http://localhost:8015/tunnel-web/secure/axis/Portal_UserService?wsdl

It is asking for a username/password. I've tried various combinations, what username and password am I supposed to use?
Ken Ko
RE: 401 Unauthorized when calling webservice
August 26, 2007 6:44 PM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

There appears to be some change, or a problem in version 4.3

Using the following combination works in 4.2.2
(http://localhost:8080/tunnel/secure/axis/Portal_UserService?wsdl)
username: liferay.com.1
password: qUqP5cyxm6YcTAhz05Hph5gvu9M=

version 4.3 is using numeric IDs, so I tried the following, which does NOT work.
(http://localhost:8080/tunnel-web/secure/axis/Portal_UserService?wsdl)
username: 2
password: qUqP5cyxm6YcTAhz05Hph5gvu9M=
or
username: 2
password: test

any ideas?
Ken Ko
RE: 401 Unauthorized when calling webservice
August 27, 2007 12:50 AM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

Still no luck, I'll post my progress thus far:

* default liferay tomcat 4.3.0 installation, using default HSQLDB database
* changed my java.security file of the JVM, to configure login.config.url.1=file:${user.home}/jaas.config
* added jaas.config file to my user home directory
* The jaas.config file has the following contents:

PortalRealm {
com.liferay.portal.kernel.security.jaas.PortalLoginModule required;
};


* I login to the webservice on the browser:
url: http://localhost:8080/tunnel-web/secure/axis/Portal_UserService?wsdl
username: 2
password: qUqP5cyxm6YcTAhz05Hph5gvu9M=

* It authenticates OK, passes the login. stepping through the code, I see it goes through PortalLoginModule.commit()

* returns tomcat error page, (403)Access to the requested resource has been denied

So it looks like I am getting an Authorization error now. Any ideas?
Jonathan Johnson
RE: 401 Unauthorized when calling webservice
August 27, 2007 1:24 PM
Answer

Jonathan Johnson

Rank: New Member

Posts: 5

Join Date: July 16, 2007

Recent Posts

I might have missed you mentioning it, but have you tried adding the following to your portal-ext.properties file where {123.123.123.123} is your ip address? for some reason when I tried this earlier, I couldn't use just 127.0.0.1


# Access to the Liferay API (tunnel-web)
axis.servlet.hosts.allowed=127.0.0.1,SERVER_IP,123.123.123.123
Ken Ko
403 - Access to the requested resource has been denied
August 27, 2007 3:42 PM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

still no good, anyone have any other ideas?
Ken Ko
RE: 403 - Access to the requested resource has been denied
August 29, 2007 4:21 PM
Answer

Ken Ko

Rank: New Member

Posts: 8

Join Date: August 26, 2007

Recent Posts

Just an update on my progress.

* The Jetty bundle 4.3.1 has JAAS all setup correctly and webservices work as expected.
* JBOSS bundle doesnt appear to be hooked up to JAAS at all (401)
* I specified jaas.config for the Tomcat bundle, and got authenticated, but couldn't get authorised (403)

For my current requirements, using the Jetty bundle will be fine.

But I'd be interested to know how to setup the Tomcat or the JBOSS bundles to work. Should be an easy thing for those who know JAAS, hope you can comment.

thanks.
C.S. L
RE: 403 - Access to the requested resource has been denied
January 15, 2008 2:10 AM
Answer

C.S. L

Rank: Junior Member

Posts: 83

Join Date: January 5, 2007

Recent Posts

Hi,

Does anyone have any idea whether this 403 issue has been fixed in 4.3.5?

I encountered the same error in tomcat 6.0 / mysql and 4.3.5.

Thanks!

/CS
Surya Choudhury
RE: 403 - Access to the requested resource has been denied
March 19, 2008 7:39 AM
Answer

Surya Choudhury

Rank: New Member

Posts: 1

Join Date: March 12, 2008

Recent Posts

Hi,

Even i was suffering with the same issue while trying to make a service call to LifeRay from a Generic WS client, the service call was failing due due to SOAP Authentication failure at Portal Realm. The below code (suggestion) successfully able to make a service call in LifeRay.

public static void call() throws Exception {
String URL1 = "http://10117:test@localhost:8080/tunnel-web/secure/axis/Portlet_Wiki_WikiNodeService?wsdl";

org.apache.axis.description.OperationDesc oper;
org.apache.axis.description.ParameterDesc param;
org.apache.axis.description.TypeDesc typeDesc;

oper = new org.apache.axis.description.OperationDesc();
oper.setName("getNode");

param = new org.apache.axis.description.ParameterDesc(
new javax.xml.namespace.QName("", "nodeId"),
org.apache.axis.description.ParameterDesc.IN,
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "long"),
long.class,
false,
false);

oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName("urn:http.service.wiki.portlet.liferay.com", "WikiNodeSoap"));
oper.setReturnClass(WikiNodeSoap.class);
oper.setReturnQName(new javax.xml.namespace.QName("", "getNodeReturn"));
oper.setStyle(org.apache.axis.constants.Style.RPC);
oper.setUse(org.apache.axis.constants.Use.ENCODED);

Service service = new Service();
service.setTypeMappingVersion("1.2");

org.apache.axis.client.Call call = new Call(service);
call.setOperation(oper);
call.setTargetEndpointAddress(URL1);
call.setUseSOAPAction(true);
call.setSOAPActionURI("");
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
call.setOperationName(new javax.xml.namespace.QName("urn:http.service.wiki.portlet.liferay.com", "getNode"));

java.lang.Class cls;
javax.xml.namespace.QName qName;
java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;
java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;

qName = new javax.xml.namespace.QName("http://model.wiki.portlet.liferay.com", "WikiNodeSoap");

cls = WikiNodeSoap.class;

call.registerTypeMapping(cls, qName, beansf, beandf);

System.out.println(((WikiNodeSoap)call.invoke(new Object[]{10503L})).getGroupId());
}

This a static code that i can suggest... all the static/hard coded value can be fetched dynamically. I apologize that, i will not be able to provide you the dynamic code as part restriction. Please make sure to register appropriate Serialize, Deserializer and encoding type.

Thank you,
Upendra Penegalapati
RE: 401 Unauthorized when calling webservice
July 7, 2008 10:57 AM
Answer

Upendra Penegalapati

Rank: New Member

Posts: 4

Join Date: June 6, 2008

Recent Posts

Even I am having the same problem. Please find my Liferay configuration below.

Liferay - 5.0.1
DB - MySQL
WS Client - sample-portal-service-portlet-5.0.0.1.war

Exception:

13:45:19,996 ERROR AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Unauthorized
faultActor:
faultNode:
faultDetail:
{}:return code: 401
<html><head><title>JBossWeb/2.0.1.GA - 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>JBossWeb/2.0.1.GA</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 com.liferay.util.axis.SimpleHTTPSender.invoke(SimpleHTTPSender.java:83)

Please help me.

Thanks in advance.
Upendra Penegalapati
RE: 401 Unauthorized when calling webservice
July 8, 2008 1:22 PM
Answer

Upendra Penegalapati

Rank: New Member

Posts: 4

Join Date: June 6, 2008

Recent Posts

Finally I made it working.

the syntax for the web services url is as follows

url = "http://" + screenName+ ":" + password + "@localhost:8080/tunnel-web/secure/axis/" + serviceName;

Also there is bug in the service method of AxisServlet.

super.service(req, stringServletRes);

String xml = stringServletRes.getString();

xml = fixXml(xml);

res.setContentType(ContentTypes.TEXT_XML_UTF8);

ServletResponseUtil.write(res, xml.getBytes(StringPool.UTF8));

After super.service() method the res object's status is changed to commited as both res and stringServletRes are using the same memory (its not a clone).
So when you check for res status in 'res.isCommitted()', the status is true and nothing will be written to the response, which is throwing Premature end of file.

To fix this either we need skip the check condition for committed status or we need to clone the response object before sending it to ServletResponseUtil.
Eric Devlin
RE: 401 Unauthorized when calling webservice
October 22, 2008 12:12 PM
Answer

Eric Devlin

Rank: Regular Member

Posts: 154

Join Date: February 19, 2008

Recent Posts

Here is the backport for the AxisServlet to 4.4.2. You'll need to get UncommittedServletResponse from the 5.1 branch.

/**
* Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.liferay.portal.servlet;

import com.liferay.portal.kernel.servlet.StringServletResponse;
import com.liferay.portal.kernel.servlet.UncommittedServletResponse;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.PrincipalThreadLocal;
import com.liferay.portal.security.permission.PermissionCheckerFactory;
import com.liferay.portal.security.permission.PermissionCheckerImpl;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.util.servlet.ServletResponseUtil;
import com.liferay.util.xml.XMLFormatter;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* <a href="AxisServlet.java.html"><b><i>View Source</i></b></a>
*
* @author Brian Wing Shun Chan
*
*/
public class AxisServlet extends org.apache.axis.transport.http.AxisServlet {

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {

PermissionCheckerImpl permissionChecker = null;

try {
String remoteUser = req.getRemoteUser();

if (_log.isDebugEnabled()) {
_log.debug("Remote user " + remoteUser);
}

if (remoteUser != null) {
PrincipalThreadLocal.setName(remoteUser);

long userId = GetterUtil.getLong(remoteUser);

User user = UserLocalServiceUtil.getUserById(userId);

permissionChecker = PermissionCheckerFactory.create(user, true);

PermissionThreadLocal.setPermissionChecker(permissionChecker);
}

StringServletResponse stringResponse = new StringServletResponse(
res);

super.service(req, stringResponse);

String contentType = stringResponse.getContentType();

res.setContentType(contentType);

String content = stringResponse.getString();

if (contentType.contains(ContentTypes.TEXT_XML)) {
content = fixXml(content);
}

ServletResponseUtil.write(
new UncommittedServletResponse(res),
content.getBytes(StringPool.UTF8));
}
catch (Exception e) {
_log.error(e, e);
}
finally {
try {
PermissionCheckerFactory.recycle(permissionChecker);
}
catch (Exception e) {
}
}
}

protected String fixXml(String xml) throws Exception {
if (xml.indexOf("<wsdl:definitions") == -1) {
return xml;
}

xml = StringUtil.replace(
xml,
new String[] {
"\r\n",
"\n",
" ",
"> <",
_INCORRECT_LONG_ARRAY,
_INCORRECT_STRING_ARRAY
},
new String[] {
StringPool.BLANK,
StringPool.BLANK,
StringPool.BLANK,
"><",
_CORRECT_LONG_ARRAY,
_CORRECT_STRING_ARRAY
});

xml = XMLFormatter.toString(xml);

return xml;
}

private static final String _INCORRECT_LONG_ARRAY =
"<complexType name=\"ArrayOf_xsd_long\"><simpleContent><extension/>" +
"</simpleContent></complexType>";

private static final String _CORRECT_LONG_ARRAY =
"<complexType name=\"ArrayOf_xsd_long\"><complexContent>" +
"<restriction base=\"soapenc:Array\"><attribute ref=\"soapenc:" +
"arrayType\" wsdl:arrayType=\"soapenc:long[]\"/>" +
"</restriction></complexContent></complexType>";

private static final String _INCORRECT_STRING_ARRAY =
"<complexType name=\"ArrayOf_xsd_string\"><simpleContent><extension/>" +
"</simpleContent></complexType>";

private static final String _CORRECT_STRING_ARRAY =
"<complexType name=\"ArrayOf_xsd_string\"><complexContent>" +
"<restriction base=\"soapenc:Array\"><attribute ref=\"soapenc:" +
"arrayType\" wsdl:arrayType=\"soapenc:string[]\"/>" +
"</restriction></complexContent></complexType>";

private static Log _log = LogFactory.getLog(AxisServlet.class);

}
Nagaraj Desingurajan
RE: 401 Unauthorized when calling webservice - Need Help Badly
April 1, 2011 1:54 AM
Answer

Nagaraj Desingurajan

Rank: Junior Member

Posts: 37

Join Date: February 20, 2011

Recent Posts

Hi Updendra,

Even I have the same setup of liferay as yours. I also get
the same error as yours.

But the as with the fix u said, I can't really understand how to do this ans the AxisServlet is from the jar axis.jar.

Can u brief me on this fix.

To brief you about what I did,

I developed some sample portlets calling Liferay Web Services and used Liferay Default Hypersonic Database and thing worked fine.

Now, I changed the Db from HSQL to Msql by overriding the portal.properties with new file portal-ext.properties and placing it in liferay-portal-6.0.5\tomcat-6.0.26\webapps\ROOT\WEB-INF\classes (This change of Database is getting reflected in Server Logs.)

I even Changed the liferay-portal-6.0.5\tomcat-6.0.26\conf\Catalina\localhost\ROOT.xml, by putting,

<Resource
name="jdbc/LiferayPool"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/lportal605_db?useUnicode=true;characterEncoding=UTF-8;useFastDateParsing=false"
username="root"
password="User1234"
maxActive="100"
maxIdle="30"
maxWait="10000" />

Still I get the
(401)Unauthorized
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
,error.

Kindly Need your help

Thanks,
nagaraj.
Nagaraj Desingurajan
RE: 401 Unauthorized when calling webservice
April 1, 2011 5:24 AM
Answer

Nagaraj Desingurajan

Rank: Junior Member

Posts: 37

Join Date: February 20, 2011

Recent Posts

Hi Upendra,

I resolved the HSQL Mysql switching issue.

After placing the portal-ext.properties(which has my MySql database properties) inside liferay-portal-6.0.5\tomcat-6.0.26\webapps\ROOT\WEB-INF\classes, There is one more property in portal-impl.jar/portal.properties,

#
# Set this to to true to populate with the minimal amount of data. Set this
# to false to populate with a larger amount of sample data.
#
schema.run.minimal=true

I Override this property also in my portal-ext.properties setting the value to false.

#
# Set this to to true to populate with the minimal amount of data. Set this
# to false to populate with a larger amount of sample data.
#
schema.run.minimal=false

And got it working. Now My sample web service portlets are displaying the response from the web services using my MySql Database.

Thanks,
Nagaraj.
Gaurang G
RE: 401 Unauthorized when calling webservice
January 28, 2011 2:22 AM
Answer

Gaurang G

Rank: New Member

Posts: 16

Join Date: April 28, 2010

Recent Posts

Ken Ko:
There appears to be some change, or a problem in version 4.3

Using the following combination works in 4.2.2
(http://localhost:8080/tunnel/secure/axis/Portal_UserService?wsdl)
username: liferay.com.1
password: qUqP5cyxm6YcTAhz05Hph5gvu9M=

version 4.3 is using numeric IDs, so I tried the following, which does NOT work.
(http://localhost:8080/tunnel-web/secure/axis/Portal_UserService?wsdl)
username: 2
password: qUqP5cyxm6YcTAhz05Hph5gvu9M=
or
username: 2
password: test

any ideas?


In case someone is having the same problem, for liferay 6 it works with:-
username: test@liferay.com
password: test

however there is catch to it, with service endpoint it won't be possible to use it as:-
1
2http://test@liferay.com:test@localhost:8080/tunnel/secure/axis/Portal_UserService?wsdl


change the authentication method to screenname or as a check modify the email address of 'test' user to 'test' only in place of test@liferay.com then it should be accessible with:-
1
2http://test:test@localhost:8080/tunnel/secure/axis/Portal_UserService?wsdl
Atif Hussain
RE: 401 Unauthorized when calling webservice
January 9, 2013 4:15 AM
Answer

Atif Hussain

Rank: Junior Member

Posts: 46

Join Date: April 3, 2012

Recent Posts

In my case it worked with

username: test@liferay.com
password : test