RE: Login Error Messages

thumbnail
Michael Charles, modified 13 Years ago. New Member Posts: 15 Join Date: 1/20/11 Recent Posts
Looking at the Liferay source, portal-web/docroot/html/portlet/login/login.jsp has different error messages depending on the exception thrown.

<liferay-ui:error exception="<%= AuthException.class %>" message="authentication-failed" />
<liferay-ui:error exception="<%= CookieNotSupportedException.class %>" message="authentication-failed-please-enable-browser-cookies" />
<liferay-ui:error exception="<%= NoSuchUserException.class %>" message="please-enter-a-valid-login" />
<liferay-ui:error exception="<%= PasswordExpiredException.class %>" message="your-password-has-expired" />
<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-login" />
<liferay-ui:error exception="<%= UserLockoutException.class %>" message="this-account-has-been-locked" />
<liferay-ui:error exception="<%= UserPasswordException.class %>" message="please-enter-a-valid-password" />
<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />


However, "com.liferay.portal.security.auth.Authenticator" only throws an "AuthException", and prevents any class that implements it from bubbling up a different exception bubble up.

Seems seems like either a bug or an inflexible design.

Are there any thoughts out there as to why this is the case?

If there are no good reason I'd like to submit/recommend changes to com.liferay.portal.security.auth.Authenticator that would allow a more flexible custom authentication experience.

Also for for reference the following thread has some information as well. Changing Login Error Messages
thumbnail
David H Nebinger, modified 13 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
Login failures will typically show two failures, the first is the 'invalid data' or something, the second is the valuable one from the language bundle.

I used CSS to disable the display of the first one (since it has little if any value) and only show the good one.
Vincent Pradeilles, modified 10 Years ago. New Member Posts: 7 Join Date: 10/29/14 Recent Posts
Hello,

I'm having the same problem : I'm implementing a custom Authenticator :


public class PreAuthAction implements Authenticator {
	@Override
	public int authenticateByEmailAddress(...) {
		if (... custom call to a database ...) {
			... There I need to throw or return some thing 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 do bring this information to the portlet/login/login.jsp ?

Thank you !
Jan Tošovský, modified 7 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
I've tried several ways but ended up with the Java reflection.

So you basically need to extend AuthException class in your hook:

public class MyAuthException extends AuthException {

    public MyAuthException() {
        super();
    }
}

As your code is in the hook, but JSP served from ROOT, you have to use reflection to access it. As no params are passed, the final code is not so complex:

&lt;%@page import="com.liferay.portal.kernel.bean.PortletBeanLocatorUtil" %&gt;
&lt;%@page import="java.lang.reflect.Method" %&gt;
...
&lt;%
    ClassLoader classLoader = PortletBeanLocatorUtil.getBeanLocator("my-hook").getClassLoader();
    Class myAuthExceptionClass = classLoader.loadClass("com.company.hook.MyAuthException");
%&gt;

<liferay-ui:error exception="<%= myAuthExceptionClass %>" message="my-error-msg" />


Jan
Chanakya P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Hi,

How to add MyAuthException in implemented authenticateByScreenName( ) method of CustomAthenticator class.

 

I tried with above code , I was unable get the myAuthException message.

and more over <%@page import="com.liferay.portal.kernel.bean.PortletBeanLocatorUtil" %>  not imported in login.jsp

 

 

Srinivas P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Hi All,

 

Can any one help me out.