Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
David A Fay
Liferay, Tomcat & CGI
March 9, 2011 7:14 AM
Answer

David A Fay

Rank: New Member

Posts: 3

Join Date: April 1, 2008

Recent Posts

Hi All,

I am running the liferay-tomcat bundle version 6.0.5/6.0.26 and am trying to deploy a portlet that requires a CGI script. But, when I deploy, I get this error:

java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application

After lots of searching, the basic answer is to deploy the CGI servlet in Tomcat which is not deployed by default. This gets the CGI part working. Then, to get past the security issue, add a context parameter to set the "privileged" attribute to "true". Pretty straightforward...

...but it doesn't work. Every post I read seems to indicate that this is the solution, so the only thing I can come up with is that the presence Liferay is having some effect. None of the posts that discuss this issue talk about portlets. And searches on Liferay + CGI don't reveal anything.

I would really appreciate any suggestions.

Thanks!

David
David A Fay
RE: Liferay, Tomcat & CGI
April 6, 2011 4:49 AM
Answer

David A Fay

Rank: New Member

Posts: 3

Join Date: April 1, 2008

Recent Posts

I figured it out.

For anyone who runs into this, here's what I had to do:

1. Modify the WEB-INF/web.xml inside the web app, so <tomcat-dir>/webapps/<webapp-name>/WEB-INF/web.xml. Add the following to the area where servlets are defined:

<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>C:\Python32\python.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>

Note that you will need to install Python and change the location above to the location of your Python executable.

2. In the same web.xml, add the following to the area where servlet mappings are defined:

<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>

3. In the WEB-INF directory of your portlet, create a "cgi" directory and put your CGI Script there. Alternately, you can put it somewhere else. Just make sure that in your CGI servlet defined above that you change the value of the "cgiPathPrefix" parameter.

4. I'm not sure if this is the correct thing to do, but it worked for me. In the <tomcat-dir>/<conf-dir>/<Catalina-dir>/<hostname-dir> (e.g., <tomcat-dir>/conf/Catalina/localhost>), create an XML file that is named the same as the webapp, so <webapp-name>.xml. At a minimum, make it look like this (your app may need additional elements/attributes depending on your neeeds):

<Context privileged="true" >
</Context>

The important part to include in the Context element is 'privileged="true"'.

Steps 1-3 gets the CGI part running properly and step 4 gets beyond the security exception.

Good Luck!

David
Rajendra Singh
RE: Liferay, Tomcat & CGI
May 9, 2013 8:49 PM
Answer

Rajendra Singh

Rank: New Member

Posts: 1

Join Date: May 9, 2013

Recent Posts

HI David

I have configured everything as you mentioned above. But when i am accessing the URL from portlet i am getting xml parsing error no element found location moz-nullprincipal line number 1 column 1 in firebug and its printing /*]]>*/ on screen. Can you please accessing the CGI script from portlet.

Thanks
Rajendra