Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: [URGENT] Custom Authenticator Exception
I'm implementing a custom Authenticator and I have to throw a custom status :
public class PreAuthAction implements Authenticator {
@Override
public int authenticateByEmailAddress(...) {
if (... custom call to a database ...) {
... There I need to throw or return something in order the user receives a custom message in login.jsp ...
} else {
return Authenticator.SUCCESS;
}
}
I need to check the email and check a custom table.
Then, if check fails, I have to ask another authentication value to the user, this is not an error,
The user must have a custom message when my custom Authenticator fails.
How to bring this information to the portlet/login/login.jsp ?
reading the file, there is a custom error management with language messages :
<liferay-ui:error exception="<%= UserPasswordException.class %>" message="authentication-failed" />
<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="authentication-failed" />
How are these messages used ? and how can I add my own exception ? and how can I throw it from Authenticator ?
Thank you !
Hi All,
I am having the same type of requirement could any one
help me out.
Thanks & Regards,
P.V.B.Raju
Hi All,
How to implement this requirement in DXP
Can any help me out.
Hi All,
Any Idea on this..
Hi,
in DXP it should be possible to create and throw your custom "MyException extends AuthException" inside the Authenticator.
Then, looking at https://github.com/liferay/liferay-portal/blob/7.0.6-ga7/modules/apps/foundation/login/login-web/src/main/resources/META-INF/resources/login.jsp#L71 it should be possible to register a DynamicInclude OSGi service for
com.liferay.login.web#/login.jsp#alertPre
And use <liferay-ui:error> to print your custom message:
<liferay-ui:error exception="<%= MyException.class %>" message="something-failed" />
Here is some info about DynamicInclude https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-0/jsp-overrides-using-dynamic-includes
Hi Tomas Polesovsky,
Thanks for your reply.
How to throw CustomException/MyException from overridden method authenticateByScreenName() of CustomAuthenticator class?
Can you please help me out.
Hi,
not sure what you mean.
I mean simply throw the exception:
throw new MyException();
HI Tomas Polesovsky,
dynamicIncludeRegistry.register("com.liferay.login.web#/login.jsp#alertPre"); registered successfully, when deploying respective module.
But getting below error when open login jsp.
Error in Javac compilation for JSP__PWC6197: An error occurred at line: 170 in the jsp file: /login.jsp_PWC6199: Generated servlet error:_cannot find symbol_ symbol: class MyException_ location: class org.apache.jsp.login_jsp__ [Sanitized]
Actually I customized login.jsp and Authenticator.
Both are different module projects.
I created myexception class in custom autheticator module project and there am throwing MyException class from overridden authenticateByScreenName() method of my customauthenticator class.
How to import MyException class in customized login.jsp?
Chanakya P:How to import MyException class in customized login.jsp?
On the surface, it sounds like a limitation to the whole dynamic include registry concept.
However, let's try to dig deeper. Have you tried working around the
limitation by moving your MyException
class to a fragment
bundle, where the fragment host is set to
com.liferay.login.web
? If you're lucky, the dynamic
includes are using the original host bundle's class loader for JSP
compilation, and you'll be able to provide new classes that can be
consumed by the host bundle via bundle fragments.
Chanakya P:Actually I customized login.jsp and Authenticator.
Both are different module projects.
How to import MyException class in customized login.jsp?
Would be better to have them together inside the same module.
Otherwise you need to export the exception class package from the "authenticator module" and import it from the "login.jsp module".
This should work. If that doesn't work please try Minhchau's trick.
Powered by Liferay™