フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/28 6:46
RE: Custom UserLocalServiceImpl class not taking effect Tejas Kanani 2012/10/28 22:57
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/30 0:57
RE: Custom UserLocalServiceImpl class not taking effect Harish Kumar 2012/10/30 1:07
RE: Custom UserLocalServiceImpl class not taking effect Siby Mathew 2012/10/30 6:55
RE: Custom UserLocalServiceImpl class not taking effect Harish Kumar 2012/10/30 7:07
RE: Custom UserLocalServiceImpl class not taking effect David H Nebinger 2012/10/29 5:39
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/30 0:48
RE: Custom UserLocalServiceImpl class not taking effect Gaurav Jain 2012/10/29 6:24
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/30 0:55
RE: Custom UserLocalServiceImpl class not taking effect Siby Mathew 2012/10/30 7:25
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/31 3:32
RE: Custom UserLocalServiceImpl class not taking effect Harish Kumar 2012/10/31 4:52
RE: Custom UserLocalServiceImpl class not taking effect Siby Mathew 2012/10/31 10:05
RE: Custom UserLocalServiceImpl class not taking effect Gaurav Jain 2012/10/30 12:46
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/10/31 8:11
RE: Custom UserLocalServiceImpl class not taking effect Yogesh Garg 2012/11/06 3:01
RE: Custom UserLocalServiceImpl class not taking effect Siby Mathew 2012/11/06 6:07
Yogesh Garg
Custom UserLocalServiceImpl class not taking effect
2012/10/28 6:46
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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.
Tejas Kanani
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/28 22:57
答え

Tejas Kanani

ランク: Liferay Master

投稿: 653

参加年月日: 2009/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
David H Nebinger
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/29 5:39
答え

David H Nebinger

ランク: Liferay Legend

投稿: 7157

参加年月日: 2006/09/01

最近の投稿

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.
Gaurav Jain
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/29 6:24
答え

Gaurav Jain

ランク: Regular Member

投稿: 141

参加年月日: 2011/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.
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 0:48
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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.
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 0:55
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 0:57
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/11/10

最近の投稿

Hi Tejas,

I will look at this posting you suggested.

Thanks,
Yogesh.
Harish Kumar
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 1:07
答え

Harish Kumar

ランク: Expert

投稿: 333

参加年月日: 2010/07/31

最近の投稿

Hi Yogesh,

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

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


Use LiberalScreenNameValidator as it only checks for null screenName.


Regards,
Siby Mathew
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 6:55
答え

Siby Mathew

ランク: Expert

投稿: 261

参加年月日: 2011/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
Harish Kumar
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 7:07
答え

Harish Kumar

ランク: Expert

投稿: 333

参加年月日: 2010/07/31

最近の投稿

Yes, you are right. UserLocalServiceImpl.validateScreenName() is declared as protected also.
Siby Mathew
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 7:25
答え

Siby Mathew

ランク: Expert

投稿: 261

参加年月日: 2011/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
Gaurav Jain
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/30 12:46
答え

Gaurav Jain

ランク: Regular Member

投稿: 141

参加年月日: 2011/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.
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/31 3:32
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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.
Harish Kumar
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/31 4:52
答え

Harish Kumar

ランク: Expert

投稿: 333

参加年月日: 2010/07/31

最近の投稿

Instead of using userPersistence or groupPersistence Objects, you can make use of respective LocalServiceUtil classes like UserLocalServiceUtil class

HTH
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/31 8:11
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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?
Siby Mathew
RE: Custom UserLocalServiceImpl class not taking effect
2012/10/31 10:05
答え

Siby Mathew

ランク: Expert

投稿: 261

参加年月日: 2011/03/04

最近の投稿

Hi Yogesh,
The methods I am referring to are : authenticateByScreenName and authenticateByEmailAddress
Both are available inside the UserLocalServiceWrapper class.

Thanks,
Siby
Yogesh Garg
RE: Custom UserLocalServiceImpl class not taking effect
2012/11/06 3:01
答え

Yogesh Garg

ランク: Junior Member

投稿: 51

参加年月日: 2008/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.
Siby Mathew
RE: Custom UserLocalServiceImpl class not taking effect
2012/11/06 6:07
答え

Siby Mathew

ランク: Expert

投稿: 261

参加年月日: 2011/03/04

最近の投稿

Hi Yogesh,
Your approach is wrong.
But can you please let me know why you couldn't implement my idea.

Thanks,
Siby