Fórum

Custom Logout functionality

Vishwanath Mathapati, modificado 13 Anos atrás.

Custom Logout functionality

New Member Postagens: 5 Data de Entrada: 26/04/10 Postagens Recentes
Hi,


I am working for custom log out using liferay 5.2.3 version.
Actually I want to implement the functionality for log out/not-allowed to login user if he is not fulfilling some of constraints in my application.

I have started it from implementing in to LoginPostAction and checking the condition on some of dates lie if user subscriptionfall under some date range then,I want to allow that user to login other wise not.

Please help in this.

Regards,
Vishwanath.
thumbnail
Sandeep Nair, modificado 13 Anos atrás.

RE: Custom Logout functionality

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Hi,

Basically what you are looking for is authenticator i guess, like you want to have one more authentication in pipeline. In that case you have to mention your authenticator in auth.pipeline.pre

which will throw AuthException if it doesnt match your criteria. Read teh following and add your class in teh pipeline.

##
## Authentication Pipeline
##

#
# Input a list of comma delimited class names that implement
# com.liferay.portal.security.auth.Authenticator. These classes will run
# before or after the portal authentication begins.
#
# The Authenticator class defines the constant values that should be used
# as return codes from the classes implementing the interface. If
# authentication is successful, return SUCCESS; if the user exists but the
# passwords do not match, return FAILURE; and if the user does not exist on
# the system, return DNE.
#
# Constants in Authenticator:
# public static final int SUCCESS = 1;
# public static final int FAILURE = -1;
# public static final int DNE = 0;
#
# In case you have several classes in the authentication pipeline, all of
# them have to return SUCCESS if you want the user to be able to login. If
# one of the authenticators returns FAILURE or DNE, the login fails.
#
# Under certain circumstances, you might want to keep the information in the
# portal database in sync with an external database or an LDAP server. This
# can easily be achieved by implementing a class via LDAPAuth that updates
# the information stored in the portal user database whenever a user signs
# in.
#
# Each portal instance can be configured at run time to either authenticate
# based on user ids or email addresses. See the Admin portlet for more
# information.
#
# Available authenticators are:
# com.liferay.portal.security.auth.LDAPAuth
#
# See the LDAP properties to configure the behavior of the LDAPAuth class.
#
auth.pipeline.pre=com.liferay.portal.security.auth.LDAPAuth
#auth.pipeline.post=


Regards,
sandeep
Vishwanath Mathapati, modificado 13 Anos atrás.

RE: Custom Logout functionality

New Member Postagens: 5 Data de Entrada: 26/04/10 Postagens Recentes
Hey thanks for the reply first of all,

So that means you want me to implement custom Authenticator to application.
So that if the user falls under contract period we have to return string as SUCCESS or else FAILURE from authenticator.

But I need one more help that can you guide me to implement authenticator?

Thanks,
Vishwanath.
thumbnail
Sandeep Nair, modificado 13 Anos atrás.

RE: Custom Logout functionality

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Hi,

You can see LDAPAuth for reference. There are three methods that you need to override as it is done in LDAPAuth. Write your logic in those methods and return the status as your requirement.

Regards,
Sandeep
Vishwanath Mathapati, modificado 13 Anos atrás.

RE: Custom Logout functionality

New Member Postagens: 5 Data de Entrada: 26/04/10 Postagens Recentes
Now have have written my own Authenticator as MyAuthenticator by implementing com.liferay.portal.security.auth.Authenticator

and i have added the two properties to portal-ext.properties

auth.pipeline.pre=com.test.MyAuthenticator
auth.pipeline.enable.liferay.check=true


the code inside MyAuthenticator looks as


***************************************************
package com.test;

import java.util.Map;

import com.liferay.portal.security.auth.AuthException;
import com.liferay.portal.security.auth.Authenticator;

public class MyAuthenticator implements Authenticator {

public int authenticateByEmailAddress(long arg0, String arg1, String arg2,
Map<String, String[]> arg3, Map<String, String[]> arg4)
throws AuthException {
// TODO Auto-generated method stub
return 1;
}

public int authenticateByScreenName(long arg0, String arg1, String arg2,
Map<String, String[]> arg3, Map<String, String[]> arg4)
throws AuthException {
// TODO Auto-generated method stub
return 1;
}

public int authenticateByUserId(long arg0, long arg1, String arg2,
Map<String, String[]> arg3, Map<String, String[]> arg4)
throws AuthException {
// TODO Auto-generated method stub
return 1;
}

public int authenticateByContractPeriod(long arg0, long arg1, String arg2,
Map<String, String[]> arg3, Map<String, String[]> arg4)
throws AuthException {

System.out.println("authenticateByContractPeriod------------------------------->");
if(contractperiod){
return 1;
}else{
return -1;
}
}
}

This much only is need to do right..?
thumbnail
Sandeep Nair, modificado 13 Anos atrás.

RE: Custom Logout functionality

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Yes did it work?

No you have to write your authentication logic inside all the three default methods and return success or failure there. Like for example try overriding the following default method

public int authenticateByEmailAddress(
			long companyId, String emailAddress, String password,
			Map<string, string[]> headerMap, Map<string, string[]> parameterMap)
		throws AuthException {

		throw new AuthException(e);
	}</string,></string,>



This will always fail if user comes in this authenticator and tries to authenticate by email address. You can throw AuthException according to ur biz logic.

Regards,
Sandeep
Vishwanath Mathapati, modificado 13 Anos atrás.

RE: Custom Logout functionality

New Member Postagens: 5 Data de Entrada: 26/04/10 Postagens Recentes
Hey Sandeep GM,

Thanks for all your help,
I have achieved the requirement what I have needed,
But still have one more small issue as described below-

As we know the Authenticator class entry should be given in portal-ext.properties file as

auth.pipeline.pre=com.test.MyAuthenticator
auth.pipeline.enable.liferay.check=true

And to load this class(com.test.MyAuthenticator) i have kept the class file in creating the jar and put in lib folder of the tomcat,because the properties-ext.properties scans the /lib and /classes folder when we start the tomcat server.

So my question is instead of creating .jar of the authenticator in /lib or putting .class file of authenticator file in /classes folder which scans when server is started,Can we have the authenticator in our application .war file and make authenticator available when request come to application can we authenticate with our authenticator of our application only?.

Does this can be done or is it possible?

Regards,
Vishwanath.
thumbnail
Sandeep Nair, modificado 13 Anos atrás.

RE: Custom Logout functionality

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Yes,

Try creating a property hook.

Check this link, the last part is property hook
http://www.liferay.com/community/wiki/-/wiki/Main/Portal+Hook+Plugins

Regards,
Sandeep
Vishwanath Mathapati, modificado 13 Anos atrás.

RE: Custom Logout functionality

New Member Postagens: 5 Data de Entrada: 26/04/10 Postagens Recentes
Hi sandeep,

Thanks for the suggestion for hooks implementation.

Now i am facing one small issue i.e. Presently I m throwing my custom exception as ContractPeriodInvalid(which extends AuthException) from all of aothenticator method viz. (authenticateByScreenName etc.).

But when I authenticate and throw my custom exception its showing my message with one more message as you-have-entered-invalid-data=You have entered invalid data. Please try again. from language_en.properties, which I don't want to show on my login.I want only my custom message as "Your contract period is over."

here is my code snippet-

1public int authenticateByEmailAddress(
2 long companyId, String emailAddress, String password,
3 Map<String, String[]> headerMap, Map<String, String[]> parameterMap)
4 throws AuthException {
5
6 throw new ContractPeriodInvalidException(e);
7 }
******************************
public class ContractPeriodInvalidException extends AuthException {

}

*******************************

<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" />
<liferay-ui:error exception="<%= ContractPeriodInvalidException.class %>" message="Your contract period is over." />

thanks,
Vishwanath.
thumbnail
ankit yakkundi, modificado 12 Anos atrás.

RE: Custom Logout functionality

Regular Member Postagens: 221 Data de Entrada: 05/03/10 Postagens Recentes
Hi..
I am using Liferay 6 and tomcat 6.
I have customized the Liferay Login and integrated with LDAP.
The condition for login into my application is user has to be admin or as to belong to a group.
I have configured my ldap i such a way that only those users in the ldap will be imported into lifeay who belong to specific group.
This is working fine.But now i am planning to import all the users.
My application works when email is not entered,password not entered,email and password does not match,and is email and password match but is not in group then it is redirected to login page. What i want is that user should get a message you are not authorized to view the community.
I have used preLogin and PostLogin java classes.
If i use authenticator,then whatever logic i had written in postlogin ,i have to copy it on my newly created classes extending authenticator class.

where i have to place my authenticator extended class and new exception class in my application.

Any idea or suggestions are welcome..
Thanks in advance..
thumbnail
ankit yakkundi, modificado 12 Anos atrás.

RE: Custom Logout functionality

Regular Member Postagens: 221 Data de Entrada: 05/03/10 Postagens Recentes
hi,,
I would like to know what my newly created class for exception would consists.
Where i have to copy the two class file in my project/application??

where i have to place the below code ie on which file??? As far as i know it has to be placed in jsp file.
<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" />
<liferay-ui:error exception="<%= ContractPeriodInvalidException.class %>" message="Your contract period is over." />[/quote

Where i would be writing my custom message??

I am attaching my authenticator java file for your reference...
Thanks in advance...
Any idea and suggestions are welcome..
Vincent Pradeilles, modificado 9 Anos atrás.

RE: Custom Logout functionality

New Member Postagens: 7 Data de Entrada: 29/10/14 Postagens Recentes
Vishwanath Mathapati:

<liferay-ui:error exception="<%= ContractPeriodInvalidException.class %>" message="Your contract period is over." />

Vishwanath.



Hello Vishwanath,

I'm interested in your code : you are using your custom exception in login.jsp.
Where did you define your class ? I'm having a compilation error saying :
login_jsp.java
Only a type can be imported. com.myCompany.icv.hooks.login.MissingHotelCodeException resolves to a package


Although I imported the package at the top of the login.jsp file :

I defined the class in src/main/java/com.myCompany.icv.hooks.login/MissingHotelCodeException.java
&lt;%@page import="com.myCompany.icv.hooks.login.MissingHotelCodeException"%&gt;


Any Idea why am I getting this error ?