Foren

Fetching ActionRequest from HttpServletRequest

ramathulasi kudumula, geändert vor 9 Jahren.

Fetching ActionRequest from HttpServletRequest

Junior Member Beiträge: 51 Beitrittsdatum: 06.10.11 Neueste Beiträge
Hi ,

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

Regards
Thulasi
thumbnail
Juan Gonzalez, geändert vor 9 Jahren.

Moved to right category

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Moved to right category
thumbnail
Jan Geißler, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
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, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Beiträge: 51 Beitrittsdatum: 06.10.11 Neueste Beiträge
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, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
what does
request.getClass().getName()
tell you?
ramathulasi kudumula, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Beiträge: 51 Beitrittsdatum: 06.10.11 Neueste Beiträge
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, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
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, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Beiträge: 51 Beitrittsdatum: 06.10.11 Neueste Beiträge
Output is com.liferay.portal.kernel.servlet.ProtectedServletRequest

Regards
Thulasi
thumbnail
srikanth velugoti, geändert vor 9 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Beiträge: 79 Beitrittsdatum: 24.04.09 Neueste Beiträge
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, geändert vor 7 Jahren.

RE: Fetching ActionRequest from HttpServletRequest

New Member Beiträge: 3 Beitrittsdatum: 14.02.17 Neueste Beiträge
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?