掲示板

Custom UserLocalServiceImpl class not taking effect

11年前 に Yogesh Garg によって更新されました。

Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi All,

I have to develop a custom class so that I can override the validateScreeName function of UserLocalServiceImpl class. This is because I want to allow email address as screename.

The steps I followed are ->
• Created a new folder named META-INF under docroot/WEB-INF/ext-impl/src in the Ext folder.

• Create a new file named ext-spring.xml under docroot/WEB-INF/ext-impl/src/META-INF.

• From Liferay source distribution, copied the portal-spring.xml file. In Liferay 6.1.1 it can be found at portal-impl/src/META-INF/portal-spring.xml.

• Copied the content of portal-spring.xml to the ext-spring.xml file that was created earlier.

• Remove all bean entries from ext-spring.xml, except for those that correspond to classes that will be replaced/extended.
so the my ext-spring.xml looks like

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="com.liferay.portal.service.UserLocalService" class="com.liferay.portal.service.impl.XXXUserLocalServiceImpl" /></beans>

Created the class com.liferay.portal.service.impl.XXXUserLocalServiceImpl

public class XXXUserLocalServiceImpl extends UserLocalServiceImpl {

protected void validateScreenName(
long companyId, long userId, String screenName)
throws PortalException, SystemException {

_log.info("in cscsuserlocalcreenameimplclass");
...................... further code for valiation.......................
}
}
I deploy my plugin and restart the server.

I am not sure where my plugin is deployed correctly or not because I do not see a log message in the function I have override.

I also added the log category with the log lever DEBUG but still do not see the message.

Please can someone help me figure out what am I missing in the steps. Also, if I am doing it incorrectly help me out with the properway of doing it.

Thanks,
Yogesh.
thumbnail
11年前 に Tejas Kanani によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Liferay Master 投稿: 654 参加年月日: 09/01/06 最新の投稿
Hi Yogesh,

Why don't you use Liferay Hook to override OOTB portal service ? Liferay Hook provides way to override existing Liferay Services.
Check Overriding a Portal Service using Liferay Hook.

Regards,
Tejas
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi Tejas,

I will look at this posting you suggested.

Thanks,
Yogesh.
thumbnail
11年前 に Harish Kumar によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 483 参加年月日: 10/07/31 最新の投稿
Hi Yogesh,

You can have a look at following property in portal.properties

users.screen.name.validator=com.liferay.portal.security.auth.LiberalScreenNameValidator


Use LiberalScreenNameValidator as it only checks for null screenName.


Regards,
11年前 に Siby Mathew によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Harish,
If you see UserLocalServiceImpl.validateScreenName(), after invoking the screenNameValidator instance, it uses still more code to perform the validations.
So we cant possibly override the full validation using a hook.

Thanks,
Siby
thumbnail
11年前 に Harish Kumar によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 483 参加年月日: 10/07/31 最新の投稿
Yes, you are right. UserLocalServiceImpl.validateScreenName() is declared as protected also.
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
Yogesh Garg:
I have to develop a custom class so that I can override the validateScreeName function of UserLocalServiceImpl class. This is because I want to allow email address as screename.


You do not need to do any of this junk.

Just set "company.security.auth.type=emailAddress" in portal-ext.properties or change the value in the control panel.
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi David,
Thanks for the response. I know this setting. I do not want to use email address as the authentication rather I want to make sure that I can insert email address as well in the screenname.
Some of my clients want screename as xyz and some want xyz@abc.com. So I want to make sure that screename accepts email address.
I have seen someposting that tells that if you want to allow @ in screename you have to change the validateScreenName function of UserLocalServiceImpl.

Thanks,
Yogesh.
thumbnail
11年前 に Gaurav Jain によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Regular Member 投稿: 145 参加年月日: 11/01/31 最新の投稿
Yes, if its just about using email - then you can change the authentication type from screenname to emailaddress.

But sill if you have specific requirement to change the validateScreenName method, then you can go for:
- ServiceHook - you will be needing to write all those methods which directly or indirectly use this method,and in you custom class you can make a copy of this method. So that all those methods which use this protected method of UserLocalServiceImpl will be hooked by your Custom class. But it can also be difficult if in implementations of those methods, there will be classes used from portal-impl as portal-impl clases are not available in hooks

- Ext : When you create ext plugin using plugins-sdk you just need to add UserLocalServiceImpl class in the same location. So ext-impl>com>liferay>portal>service>impl>UserLocalServiceImpl
Just make this a copy of liferay's UserLocalServiceImpl and change the method validateScreenName as you want. Deploy the plugin. Restart liferay. And you are done.
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi Gaurav,
Yes I want to change the validateScreeName function. I want to use the ext plugin. The only issue is I have changed the bean setting to point to a new Java file which extend the UserLocalServiceImpl and I have override the validateScreenName function. It is not been called. I guess instead of extending the UserLocalServiceImpl I have to change the UserLocalServiceImpl itself.

Any suggestions?

Thanks,
Yogesh
11年前 に Siby Mathew によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Yogesh,
You can still store the email inside the emailAddress column.
During user log-in, we can check the authentication dynamically.

I have an idea !
Consider : You have set the authentication by : emailAddress
Override using Hook :UserLocalServiceImpl.authenticateByEmailAddress()
Inside the method :
- Check if the email param sent is a valid emailAddress
- If its not call super.authenticateByScreenName()

Hope that helps !

Thanks,
Siby Mathew
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi Siby,
THe issue is when I am extending the UserLocalServiceWrapper it is not able to resolve the "authenticate" method. This is because it is not able to find userPersistence or groupPersistence Objects.

Still finding a hard time to resolve the issue.

Thanks,
Yogesh.
thumbnail
11年前 に Harish Kumar によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 483 参加年月日: 10/07/31 最新の投稿
Instead of using userPersistence or groupPersistence Objects, you can make use of respective LocalServiceUtil classes like UserLocalServiceUtil class

HTH
11年前 に Siby Mathew によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Yogesh,
The methods I am referring to are : authenticateByScreenName and authenticateByEmailAddress
Both are available inside the UserLocalServiceWrapper class.

Thanks,
Siby
thumbnail
11年前 に Gaurav Jain によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Regular Member 投稿: 145 参加年月日: 11/01/31 最新の投稿
Yogesh Garg:
Hi Gaurav,
Yes I want to change the validateScreeName function. I want to use the ext plugin. The only issue is I have changed the bean setting to point to a new Java file which extend the UserLocalServiceImpl and I have override the validateScreenName function. It is not been called. I guess instead of extending the UserLocalServiceImpl I have to change the UserLocalServiceImpl itself.

Any suggestions?

Thanks,
Yogesh


This way also worked fine for me. Maybe you deployed your ext more than once? If so first clearup your existing ext from portal , then redeploy it.
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
Hi ,
I cleaned everything. I have unzipped a fresh liferay bundle.

I have the ext-spring.xml in the META-INF folder like this
<?xml version="1.0"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="com.liferay.portal.service.UserLocalService" class="com.liferay.portal.service.impl.MyUserLocalServiceImpl" />
</beans>
Here is my class -

public class MyUserLocalServiceImpl extends UserLocalServiceImpl {

protected void validateScreenName(
long companyId, long userId, String screenName)
throws PortalException, SystemException {

_log.info("My Validate ScreenName is called.");
if (Validator.isNull(screenName)) {
throw new UserScreenNameException();
}

ScreenNameValidator screenNameValidator =
ScreenNameValidatorFactory.getInstance();

if (!screenNameValidator.validate(companyId, screenName)) {
throw new UserScreenNameException();
}

if (Validator.isNumber(screenName)) {
if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
throw new UserScreenNameException();
}

if (!screenName.equals(String.valueOf(userId))) {
Group group = groupPersistence.fetchByPrimaryKey(
GetterUtil.getLong(screenName));

if (group != null) {
throw new UserScreenNameException();
}
}
}

for (char c : screenName.toCharArray()) {
if ((!Validator.isChar(c)) && (!Validator.isDigit(c)) &&
(c != CharPool.DASH) && (c != CharPool.PERIOD) &&
(c != CharPool.UNDERLINE) && (c != CharPool.AT)) {

throw new UserScreenNameException();
}
}

String[] anonymousNames = PrincipalBean.ANONYMOUS_NAMES;

for (String anonymousName : anonymousNames) {
if (screenName.equalsIgnoreCase(anonymousName)) {
throw new UserScreenNameException();
}
}

User user = userPersistence.fetchByC_SN(companyId, screenName);

if ((user != null) && (user.getUserId() != userId)) {
throw new DuplicateUserScreenNameException();
}

String friendlyURL = StringPool.SLASH + screenName;

Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);

if ((group != null) && (group.getClassPK() != userId)) {
throw new GroupFriendlyURLException(
GroupFriendlyURLException.DUPLICATE);
}

int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);

if (exceptionType != -1) {
throw new UserScreenNameException(
new GroupFriendlyURLException(exceptionType));
}

String[] reservedScreenNames = PrefsPropsUtil.getStringArray(
companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES,
StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_SCREEN_NAMES);

for (String reservedScreenName : reservedScreenNames) {
if (screenName.equalsIgnoreCase(reservedScreenName)) {
throw new ReservedUserScreenNameException();
}
}
}

private static Log _log = LogFactoryUtil.getLog(CSCUserLocalServiceImpl.class);

}
Then I have used the following commands -

1. ant compile to compile
2. ant war to get the war.

Then I deployed the war to the liferay bundle and restart it.
I do not see the log message. . Therefore, I think my class is not called.

Do you think I am missing anthying?
11年前 に Yogesh Garg によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Junior Member 投稿: 51 参加年月日: 08/11/10 最新の投稿
I did not a real solution to modify the authenticateByScreenName or any other solution that helps me allow email address as screenName. So for the work around what I did to complete the POC is create the screenName as per the validation and then updating the screenName with email address directly in the database in user_ table.

The good thing is it is working. There is no error that is coming in the Portal if I make the change in database.

I know this is not the correct way of doing it but I was running out of time for the solution. But I am still looking for a solution for this.

Thanks,
Yogesh.
11年前 に Siby Mathew によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Yogesh,
Your approach is wrong.
But can you please let me know why you couldn't implement my idea.

Thanks,
Siby
6年前 に tying Yan によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

New Member 投稿: 2 参加年月日: 17/03/06 最新の投稿
After few years...

I retake this ticket because i have a similar situation and i found a solution creating an EXT.
The Steps :
1 - Create an EXT (i used plugins-sdk) and in the folder ext-impl/src I put my source. In my case i had only 1 file : com.......portal.CustomUserLocalServiceImpl.
2 - I created a sub-folder META-INF (ext-impl/src/META-INF) that contained the file "ext-spring.xml" :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="com.liferay.portal.service.UserLocalService" class="com.......portal.CustomUserLocalServiceImpl" />
</beans>
3 - Build the war in command line :
ant clear
ant compile
ant war
4- Drop off the war file in the folder deploy's Liferay
5- You must to restart your liferay server

Hope to help you
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Custom UserLocalServiceImpl class not taking effect

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
tying Yan:
I retake this ticket because i have a similar situation and i found a solution creating an EXT.


If you want to override a service, do not use an Ext. It's way more maintainable to do so via a hook. (Linking to the 6.2 documentation, which is good for 6.x. Instructions for 7.0 are here)