Fórum

Fetching ActionRequest from HttpServletRequest

ramathulasi kudumula, modificado 9 Anos atrás.

Fetching ActionRequest from HttpServletRequest

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Hi ,

I have a requirement of fetching Fetching ActionRequest from HttpServletRequest . Please help with the issue.

Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

Moved to right category

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Moved to right category
thumbnail
Jan Geißler, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Postagens: 735 Data de Entrada: 05/07/11 Postagens Recentes
I think nobody can, because it does not work that way. You can retrieve a HTTPServletRequest from an ActionRequest, like so:
PortalUtil.getHttpServletRequest(actionRequest)

But the other way round it is not possible. Why you want to do that anyway? Liferay handles all HTTPRequests and transforms them into Action/ Render /Resource Requests.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Basically i want to implement captcha in sign in portlet.

I have written a hook to override login.jsp of liferay. In my jsp for showing the captcha i have written the below code.

<portlet:resourceURL var="captchaURL">
<portlet:param name="struts_action" value="/login/captcha" />
</portlet:resourceURL>
<liferay-ui:captcha url="<%= captchaURL %>" />

For doing the validations before authentication, i have written one more hook. In that hook i need to do the captcha validation.

CaptchaUtil.check(request) is used to check the captcha. But in my case its not working.

In the above line request should be of either httprequest or Action request

Please tell me how to proceed with this.
thumbnail
Jan Geißler, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Postagens: 735 Data de Entrada: 05/07/11 Postagens Recentes
what does
request.getClass().getName()
tell you?
ramathulasi kudumula, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
My hook code looks like below where CaptchaUtil.check(request) expects the correct request which can be HttpRequest / ActionRequest.

public class LoginUtility extends Action{

Logger log = Logger.getLogger(this.getClass());
public LoginUtility()
{

}

public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException
{
try
{
doRun(request, response);
}
catch(Exception e)
{
throw new ActionException(e);
}
}

protected void doRun(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
log.debug("Entered in to pre hook");
Long companyId = CompanyThreadLocal.getCompanyId();

log.debug("Company id val::"+companyId);
try {
User user = UserLocalServiceUtil.getUserByScreenName(companyId, "test") ;
int attempts = user.getFailedLoginAttempts();
log.debug("number of failure attempts::"+attempts);
if(attempts >1) {
CaptchaUtil.check(request);
}

} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}

}
thumbnail
Jan Geißler, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Postagens: 735 Data de Entrada: 05/07/11 Postagens Recentes
Yes. I did understand that. My question was:
What kind of Object do you have? I mean the fully qualified Name of that request Object.
Just add a:
log.debug(request.getClass().getName());
to your method, and tell me what's the output of that.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Output is com.liferay.portal.kernel.servlet.ProtectedServletRequest

Regards
Thulasi
thumbnail
srikanth velugoti, modificado 9 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Postagens: 79 Data de Entrada: 24/04/09 Postagens Recentes
Hi Tulasi ,

follow the below steps .

1) write a jsp hook for login.jsp and incldue the below code

<c:if test="<%= actualAttempts >= 1 %>">
<portlet:resourceURL var="captchaURL">
<portlet:param name="struts_action" value="/login/captcha" />
</portlet:resourceURL>

<liferay-ui:captcha url="<%= captchaURL %>" />
</c:if>


2) create a struts hook for action /login/login

<struts-action>
<struts-action-path>/login/login</struts-action-path>
<struts-action-impl>
com.hook.action.CaptchaPortletAction
</struts-action-impl>
</struts-action>

2) write the validation in Struts process Action .
if captcha is not correct throw the error to login.jsp otherwise continue the flow .
find the sample code .
public class CaptchaPortletAction extends BaseStrutsPortletAction {
private static Logger logger = Logger
.getLogger(CaptchaPortletAction.class.getSimpleName());

public void processAction(StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
try {
String login= ParamUtil.getString(actionRequest, "login");


PortletSession portletSession = actionRequest.getPortletSession();
portletSession.setAttribute("showCaptcha", "false");

int remainingattempts = 1;




if (remainingattempts >= 1 ) {


CaptchaUtil.check(actionRequest);

}

originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, actionRequest,
actionResponse);

} catch (Exception e) {
if (e instanceof CaptchaTextException
|| e instanceof CaptchaMaxChallengesException) {

SessionErrors.add(actionRequest, e.getClass(), e);
}

}

}

}




HTH
srikanth velugoti
Ali Raza, modificado 7 Anos atrás.

RE: Fetching ActionRequest from HttpServletRequest

New Member Postagens: 3 Data de Entrada: 14/02/17 Postagens Recentes
ramathulasi kudumula:
Basically i want to implement captcha in sign in portlet.

I have written a hook to override login.jsp of liferay. In my jsp for showing the captcha i have written the below code.

<portlet:resourceURL var="captchaURL">
<portlet:param name="struts_action" value="/login/captcha" />
</portlet:resourceURL>
<liferay-ui:captcha url="<%= captchaURL %>" />

For doing the validations before authentication, i have written one more hook. In that hook i need to do the captcha validation.

CaptchaUtil.check(request) is used to check the captcha. But in my case its not working.

In the above line request should be of either httprequest or Action request

Please tell me how to proceed with this.



Hi,

Did you find any solution to validate the captcha while sign in? I am facing the same problem and need solution. can you please help me?