shaofengshi closed pull request #317: KYLIN-3562, optimization the logic that 
updating the user when user logged in.
URL: https://github.com/apache/kylin/pull/317
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 dd9cbad0a8..d96b3583de 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 Authentication authenticate(Authentication 
authentication) throws Authent
                 }
                 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 00e0045357..48d44405a1 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.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.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 boolean isEnabled() {
     }
 
     @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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to