This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push: new 3bcbaa8 KYLIN-3562, optimization the logic that updating the user when user logged in. 3bcbaa8 is described below commit 3bcbaa88b97cf868ddf8f51a54b015ef3b7cc068 Author: tttMelody <245915...@qq.com> AuthorDate: Tue Sep 25 19:38:47 2018 +0800 KYLIN-3562, optimization the logic that updating the user when user logged in. --- .../rest/security/KylinAuthenticationProvider.java | 8 +++-- .../apache/kylin/rest/security/ManagedUser.java | 35 ++++++++++------------ 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java index dd9cbad..d96b358 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java +++ b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java @@ -110,10 +110,12 @@ public class KylinAuthenticationProvider implements AuthenticationProvider { } Assert.notNull(user, "The UserDetail is null."); - logger.debug("User {} authorities : {}", user.getUsername(), user.getAuthorities()); - if (!userService.userExists(user.getUsername())) { + String username = user.getUsername(); + logger.debug("User {} authorities : {}", username, user.getAuthorities()); + if (!userService.userExists(username)) { userService.createUser(user); - } else { + } else if (!userService.loadUserByUsername(username).equals(user)) { + // in case ldap users changing. userService.updateUser(user); } diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/ManagedUser.java b/server-base/src/main/java/org/apache/kylin/rest/security/ManagedUser.java index 00e0045..48d4440 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/security/ManagedUser.java +++ b/server-base/src/main/java/org/apache/kylin/rest/security/ManagedUser.java @@ -22,8 +22,8 @@ import java.io.IOException; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Objects; -import com.google.common.base.Preconditions; import org.apache.kylin.common.persistence.RootPersistentEntity; import org.apache.kylin.rest.service.UserGrantedAuthority; import org.springframework.security.core.GrantedAuthority; @@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; @SuppressWarnings("serial") @@ -231,28 +232,22 @@ public class ManagedUser extends RootPersistentEntity implements UserDetails { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((username == null) ? 0 : username.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ManagedUser that = (ManagedUser) o; + return disabled == that.disabled && defaultPassword == that.defaultPassword && locked == that.locked + && lockedTime == that.lockedTime && wrongTime == that.wrongTime + && Objects.equals(username, that.username) && Objects.equals(password, that.password) + && Objects.equals(authorities, that.authorities); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ManagedUser other = (ManagedUser) obj; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; + public int hashCode() { + return Objects.hash(super.hashCode(), username, password, authorities, disabled, defaultPassword, locked, + lockedTime, wrongTime); } @Override