Skip to content
Permalink
Browse files
Issue 21392 (#21410)
* #21392 do not return a user

* #21392 user id immutable

* #21392 Fixing typo

Co-authored-by: Will Ezell <will@dotcms.com>
Co-authored-by: jdotcms <jonathan.sanchez@dotcms.com>
Co-authored-by: nollymar <nollymarlonga@Nollymars-MacBook-Pro-2.local>
  • Loading branch information
4 people committed Dec 14, 2021
1 parent ccad093 commit 2c9b40bd73957205adfae7211f82f7de6b890ff7
@@ -0,0 +1,24 @@
package com.liferay.portal.model;

import org.junit.Assert;
import org.junit.Test;

public class UserTest {

/**
* Method to test: {@link User#setUserId(String)}
* Given Scenario: The user id can not be override
* ExpectedResult: Try to set the user id twice, the second time won't work
*
*/
@Test()
public void test_immutable_user_id() {

final User user = new User();
user.setUserId("dotcms.1");
user.setUserId("dotcms.2");

Assert.assertTrue("dotcms.1".equals(user.getUserId()));
Assert.assertFalse("dotcms.2".equals(user.getUserId()));
}
}
@@ -69,7 +69,7 @@ public User getUserByEmail(String email) {
return APILocator.getUserAPI().loadByUserByEmail(email, APILocator.getUserAPI().getSystemUser(), false);
} catch (Exception e) {
Logger.error(CMSUsersWebAPI.class,e.getMessage(), e);
return new User();
return null;
}
}

@@ -22,6 +22,7 @@

package com.liferay.portal.model;

import com.dotmarketing.util.Logger;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.liferay.portal.util.PropsUtil;
import com.liferay.util.GetterUtil;
@@ -209,16 +210,18 @@ public String getUserId() {
}

public void setUserId(String userId) {
if (((userId == null) && (_userId != null)) ||
((userId != null) && (_userId == null)) ||
((userId != null) && (_userId != null) &&
!userId.equals(_userId))) {

if (null == this.getUserId()) {

if (!XSS_ALLOW_USERID) {
userId = Xss.strip(userId);
}

_userId = userId;
setModified(true);
Logger.info(this, "User id has been modified");
} else {
Logger.info(this, "User id has not been modified");
}
}

0 comments on commit 2c9b40b

Please sign in to comment.