Forums de discussion

Fetching ActionRequest from HttpServletRequest

ramathulasi kudumula, modifié il y a 9 années.

Fetching ActionRequest from HttpServletRequest

Junior Member Publications: 51 Date d'inscription: 06/10/11 Publications récentes
Hi ,

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

Regards
Thulasi
thumbnail
Juan Gonzalez, modifié il y a 9 années.

Moved to right category

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Moved to right category
thumbnail
Jan Geißler, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
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, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Publications: 51 Date d'inscription: 06/10/11 Publications récentes
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, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
what does
request.getClass().getName()
tell you?
ramathulasi kudumula, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Publications: 51 Date d'inscription: 06/10/11 Publications récentes
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, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
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, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Publications: 51 Date d'inscription: 06/10/11 Publications récentes
Output is com.liferay.portal.kernel.servlet.ProtectedServletRequest

Regards
Thulasi
thumbnail
srikanth velugoti, modifié il y a 9 années.

RE: Fetching ActionRequest from HttpServletRequest

Junior Member Publications: 79 Date d'inscription: 24/04/09 Publications récentes
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, modifié il y a 7 années.

RE: Fetching ActionRequest from HttpServletRequest

New Member Publications: 3 Date d'inscription: 14/02/17 Publications récentes
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?