diff --git a/dotCMS/src/integration-test/java/com/liferay/portal/model/UserTest.java b/dotCMS/src/integration-test/java/com/liferay/portal/model/UserTest.java new file mode 100644 index 000000000000..46891e98e3e4 --- /dev/null +++ b/dotCMS/src/integration-test/java/com/liferay/portal/model/UserTest.java @@ -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())); + } +} diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/CMSUsersWebAPI.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/CMSUsersWebAPI.java index 3860b8dfa0e5..18d93b372090 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/CMSUsersWebAPI.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/CMSUsersWebAPI.java @@ -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; } } diff --git a/dotCMS/src/main/java/com/liferay/portal/model/UserModel.java b/dotCMS/src/main/java/com/liferay/portal/model/UserModel.java index 6a306dbdcccd..803502b7b563 100644 --- a/dotCMS/src/main/java/com/liferay/portal/model/UserModel.java +++ b/dotCMS/src/main/java/com/liferay/portal/model/UserModel.java @@ -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"); } }