留言板
Fetching ActionRequest from HttpServletRequest
ramathulasi kudumula,修改在9 年前。
Fetching ActionRequest from HttpServletRequest
Junior Member 帖子: 51 加入日期: 11-10-6 最近的帖子
Hi ,
I have a requirement of fetching Fetching ActionRequest from HttpServletRequest . Please help with the issue.
Regards
Thulasi
I have a requirement of fetching Fetching ActionRequest from HttpServletRequest . Please help with the issue.
Regards
Thulasi
Jan Geißler,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
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.
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,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Junior Member 帖子: 51 加入日期: 11-10-6 最近的帖子
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.
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.
Jan Geißler,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
what does
request.getClass().getName()
tell you?
request.getClass().getName()
tell you?
ramathulasi kudumula,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Junior Member 帖子: 51 加入日期: 11-10-6 最近的帖子
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();
}
}
}
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();
}
}
}
Jan Geißler,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
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.
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,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Junior Member 帖子: 51 加入日期: 11-10-6 最近的帖子
Output is com.liferay.portal.kernel.servlet.ProtectedServletRequest
Regards
Thulasi
Regards
Thulasi
srikanth velugoti,修改在9 年前。
RE: Fetching ActionRequest from HttpServletRequest
Junior Member 帖子: 79 加入日期: 09-4-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
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,修改在7 年前。
RE: Fetching ActionRequest from HttpServletRequest
New Member 帖子: 3 加入日期: 17-2-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?