Fórum

Logic behind ScreenNameValidator

Michał Kochanowicz, modificado 13 Anos atrás.

Logic behind ScreenNameValidator

New Member Postagens: 7 Data de Entrada: 08/03/11 Postagens Recentes
Hello

The implementataion of ScreenNameValidator in Liferay 5.2.3 seems bit odd. Take a look:

if (Validator.isEmailAddress(screenName) ||
	(screenName.equalsIgnoreCase(CYRUS)) ||
	(screenName.equalsIgnoreCase(POSTFIX)) ||
	(screenName.indexOf(StringPool.SLASH) != -1) ||
	(screenName.indexOf(StringPool.UNDERLINE) != -1)) {
	return false;
} else {
	return true;
}


If screen name is a valid email address, it is rejected.

But it can be almost anything, it can even contain newline or all sorts of non-printable characters and it will be accepted.

Is it right??

Regards
Michał
thumbnail
Amos Fong, modificado 13 Anos atrás.

RE: Logic behind ScreenNameValidator

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hi Michal,

I think this is the logic that can be changed because this is an overriable class. The logic that must be enforced is in UserLocalServiceImpl.validate() which includes this:

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

				throw new UserScreenNameException();
			}
		}
Michał Kochanowicz, modificado 13 Anos atrás.

RE: Logic behind ScreenNameValidator

New Member Postagens: 7 Data de Entrada: 08/03/11 Postagens Recentes
Amos Fong:
I think this is the logic that can be changed because this is an overriable class.


I know it can be overriden, I did it. Don't you think that this code doesn't make any sense?

Amos Fong:
The logic that must be enforced is in UserLocalServiceImpl.validate() which includes this:


Well, now it gets even stranger emoticon

I need to let users with underline from LDAP log into Liferay. I've changed (overriden) only SceeenNameValidator and it works! Didn't touch UserLocalServiceImpl!

It seems the screen name validation code got out of control...

Regards
Michał
thumbnail
Amos Fong, modificado 13 Anos atrás.

RE: Logic behind ScreenNameValidator

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hi Michal,

I know it can be overriden, I did it. Don't you think that this code doesn't make any sense?


Yea I am not sure what the reason is behind the code.

I need to let users with underline from LDAP log into Liferay. I've changed (overriden) only SceeenNameValidator and it works! Didn't touch UserLocalServiceImpl!


If you look at the code, the screenname allows letters, numbers, underlines, dash, or periods so it is working fine with your screenname.
thumbnail
Milen Dyankov, modificado 13 Anos atrás.

RE: Logic behind ScreenNameValidator

Regular Member Postagens: 171 Data de Entrada: 23/09/09 Postagens Recentes
Amos Fong:
Hi Michal,

I know it can be overriden, I did it. Don't you think that this code doesn't make any sense?


Yea I am not sure what the reason is behind the code.



Luckily there is SVN history containing references to JIRA issues causing subsequent code changes: http://svn.liferay.com/browse/portal/trunk/portal-impl/src/com/liferay/portal/security/auth/ScreenNameValidator.java