掲示板

Fetching ActionRequest from HttpServletRequest

9年前 に ramathulasi kudumula によって更新されました。

Fetching ActionRequest from HttpServletRequest

Junior Member 投稿: 51 参加年月日: 11/10/06 最新の投稿
Hi ,

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

Regards
Thulasi
thumbnail
9年前 に Juan Gonzalez によって更新されました。

Moved to right category

Liferay Legend 投稿: 3089 参加年月日: 08/10/28 最新の投稿
Moved to right category
thumbnail
9年前 に Jan Geißler によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
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.
9年前 に ramathulasi kudumula によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Junior Member 投稿: 51 参加年月日: 11/10/06 最新の投稿
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
9年前 に Jan Geißler によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
what does
request.getClass().getName()
tell you?
9年前 に ramathulasi kudumula によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Junior Member 投稿: 51 参加年月日: 11/10/06 最新の投稿
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
9年前 に Jan Geißler によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
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.
9年前 に ramathulasi kudumula によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Junior Member 投稿: 51 参加年月日: 11/10/06 最新の投稿
Output is com.liferay.portal.kernel.servlet.ProtectedServletRequest

Regards
Thulasi
thumbnail
9年前 に srikanth velugoti によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

Junior Member 投稿: 79 参加年月日: 09/04/24 最新の投稿
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
7年前 に Ali Raza によって更新されました。

RE: Fetching ActionRequest from HttpServletRequest

New Member 投稿: 3 参加年月日: 17/02/14 最新の投稿
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?