RE: [URGENT] Custom Authenticator Exception

Vincent Pradeilles, modified 10 Years ago. New Member Posts: 7 Join Date: 10/29/14 Recent Posts
Hello,

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 !
thumbnail
Bangaru Raju Potnuru, modified 7 Years ago. New Member Posts: 22 Join Date: 11/22/14 Recent Posts

Hi All,
I am having the same type of requirement could any one help me out.

Thanks & Regards,

P.V.B.Raju

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

Hi All,

 

How to implement this requirement in DXP

Can any help me out.

 

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

Hi All,

 

Any Idea on this..

thumbnail
Tomas Polesovsky, modified 7 Years ago. Liferay Master Posts: 677 Join Date: 2/13/09 Recent Posts

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

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

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.

thumbnail
Tomas Polesovsky, modified 7 Years ago. Liferay Master Posts: 677 Join Date: 2/13/09 Recent Posts

Hi,

 

not sure what you mean. 

 

I mean simply throw the exception:

throw new MyException();
Chanakya P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

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?

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
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.

thumbnail
Tomas Polesovsky, modified 7 Years ago. Liferay Master Posts: 677 Join Date: 2/13/09 Recent Posts
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.