Skip to content

Commit

Permalink
Issue 21392 (#21410)
Browse files Browse the repository at this point in the history
* #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 2c9b40b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
@@ -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()));
}
}
Expand Up @@ -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;
}
}

Expand Down
11 changes: 7 additions & 4 deletions dotCMS/src/main/java/com/liferay/portal/model/UserModel.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down

0 comments on commit 2c9b40b

Please sign in to comment.