KYLIN-2535 minor, bug fix

Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/4c18526c
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/4c18526c
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/4c18526c

Branch: refs/heads/master
Commit: 4c18526cff0c8437f3724fb32833636050bb7fe1
Parents: d609809
Author: xiefan46 <958034...@qq.com>
Authored: Fri Apr 28 18:06:29 2017 +0800
Committer: hongbin ma <m...@kyligence.io>
Committed: Fri Apr 28 18:09:53 2017 +0800

----------------------------------------------------------------------
 .../rest/service/AclTableMigrationTool.java     |   6 +-
 .../rest/service/UserGrantedAuthority.java      |  74 +++++++++++++
 .../org/apache/kylin/rest/service/UserInfo.java |  79 +++++++++++++
 .../apache/kylin/rest/service/UserService.java  | 111 +------------------
 .../kylin/rest/service/ServiceTestBase.java     |   6 +-
 5 files changed, 164 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/4c18526c/server-base/src/main/java/org/apache/kylin/rest/service/AclTableMigrationTool.java
----------------------------------------------------------------------
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/service/AclTableMigrationTool.java
 
b/server-base/src/main/java/org/apache/kylin/rest/service/AclTableMigrationTool.java
index d147686..da017b3 100644
--- 
a/server-base/src/main/java/org/apache/kylin/rest/service/AclTableMigrationTool.java
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/service/AclTableMigrationTool.java
@@ -146,7 +146,7 @@ public class AclTableMigrationTool {
                     Result result = rs.next();
                     while (result != null) {
                         User user = hbaseRowToUser(result);
-                        UserService.UserInfo userInfo = convert(user);
+                        UserInfo userInfo = convert(user);
                         
store.deleteResource(UserService.getId(userInfo.getUsername()));
                         
store.putResource(UserService.getId(userInfo.getUsername()), userInfo, 0, 
UserService.UserInfoSerializer.getInstance());
                         result = rs.next();
@@ -252,10 +252,10 @@ public class AclTableMigrationTool {
         return newInfo;
     }
 
-    private UserService.UserInfo convert(User user) {
+    private UserInfo convert(User user) {
         if (user == null)
             return null;
-        UserService.UserInfo newInfo = new UserService.UserInfo();
+        UserInfo newInfo = new UserInfo();
         newInfo.setUsername(user.getUserName());
         newInfo.setPassword(user.getPassword());
         List<String> authorities = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/kylin/blob/4c18526c/server-base/src/main/java/org/apache/kylin/rest/service/UserGrantedAuthority.java
----------------------------------------------------------------------
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/service/UserGrantedAuthority.java
 
b/server-base/src/main/java/org/apache/kylin/rest/service/UserGrantedAuthority.java
new file mode 100644
index 0000000..4c2a392
--- /dev/null
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/service/UserGrantedAuthority.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.kylin.rest.service;
+
+import org.springframework.security.core.GrantedAuthority;
+
+
+public class UserGrantedAuthority implements GrantedAuthority {
+    private static final long serialVersionUID = -5128905636841891058L;
+
+    private String authority;
+
+    public UserGrantedAuthority() {
+    }
+
+    public UserGrantedAuthority(String authority) {
+        setAuthority(authority);
+    }
+
+    @Override
+    public String getAuthority() {
+        return authority;
+    }
+
+    public void setAuthority(String authority) {
+        this.authority = authority;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((authority == null) ? 0 : 
authority.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        UserGrantedAuthority other = (UserGrantedAuthority) obj;
+        if (authority == null) {
+            if (other.authority != null)
+                return false;
+        } else if (!authority.equals(other.authority))
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return authority;
+    }
+}

http://git-wip-us.apache.org/repos/asf/kylin/blob/4c18526c/server-base/src/main/java/org/apache/kylin/rest/service/UserInfo.java
----------------------------------------------------------------------
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/service/UserInfo.java 
b/server-base/src/main/java/org/apache/kylin/rest/service/UserInfo.java
new file mode 100644
index 0000000..c687c47
--- /dev/null
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/UserInfo.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.kylin.rest.service;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.kylin.common.persistence.RootPersistentEntity;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class UserInfo extends RootPersistentEntity {
+    @JsonProperty()
+    private String username;
+    @JsonProperty()
+    private String password;
+    @JsonProperty()
+    private List<String> authorities = new ArrayList<>();
+
+    public UserInfo(String username, String password, List<String> 
authorities) {
+        this.username = username;
+        this.password = password;
+        this.authorities = authorities;
+    }
+
+    public UserInfo(UserDetails user) {
+        this.username = user.getUsername();
+        this.password = user.getPassword();
+        for (GrantedAuthority a : user.getAuthorities()) {
+            this.authorities.add(a.getAuthority());
+        }
+    }
+
+    public UserInfo() {
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public List<String> getAuthorities() {
+        return authorities;
+    }
+
+    public void setAuthorities(List<String> authorities) {
+        this.authorities = authorities;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/kylin/blob/4c18526c/server-base/src/main/java/org/apache/kylin/rest/service/UserService.java
----------------------------------------------------------------------
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/service/UserService.java 
b/server-base/src/main/java/org/apache/kylin/rest/service/UserService.java
index dd75ace..2d8e006 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/UserService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/UserService.java
@@ -28,7 +28,6 @@ import javax.annotation.PostConstruct;
 
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.persistence.ResourceStore;
-import org.apache.kylin.common.persistence.RootPersistentEntity;
 import org.apache.kylin.common.persistence.Serializer;
 import org.apache.kylin.common.util.JsonUtil;
 import org.apache.kylin.rest.constant.Constant;
@@ -42,8 +41,6 @@ import 
org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.security.provisioning.UserDetailsManager;
 import org.springframework.stereotype.Component;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-
 /**
  */
 @Component("userService")
@@ -110,6 +107,9 @@ public class UserService implements UserDetailsManager {
     public UserDetails loadUserByUsername(String userName) throws 
UsernameNotFoundException {
         try {
             UserInfo userInfo = aclStore.getResource(getId(userName), 
UserInfo.class, UserInfoSerializer.getInstance());
+            if (userInfo == null) {
+                throw new UsernameNotFoundException("User:" + userName + " Not 
found");
+            }
             logger.debug("load user : {}", userName);
             return wrap(userInfo);
         } catch (IOException e) {
@@ -147,6 +147,8 @@ public class UserService implements UserDetailsManager {
     }
 
     private User wrap(UserInfo userInfo) {
+        if (userInfo == null)
+            return null;
         List<GrantedAuthority> authorities = new ArrayList<>();
         List<String> auths = userInfo.getAuthorities();
         for (String str : auths) {
@@ -180,107 +182,4 @@ public class UserService implements UserDetailsManager {
         }
     }
 
-    public static class UserInfo extends RootPersistentEntity {
-        @JsonProperty()
-        private String username;
-        @JsonProperty()
-        private String password;
-        @JsonProperty()
-        private List<String> authorities = new ArrayList<>();
-
-        public UserInfo(String username, String password, List<String> 
authorities) {
-            this.username = username;
-            this.password = password;
-            this.authorities = authorities;
-        }
-
-        public UserInfo(UserDetails user) {
-            this.username = user.getUsername();
-            this.password = user.getPassword();
-            for (GrantedAuthority a : user.getAuthorities()) {
-                this.authorities.add(a.getAuthority());
-            }
-        }
-
-        public UserInfo() {
-        }
-
-        public String getUsername() {
-            return username;
-        }
-
-        public void setUsername(String username) {
-            this.username = username;
-        }
-
-        public String getPassword() {
-            return password;
-        }
-
-        public void setPassword(String password) {
-            this.password = password;
-        }
-
-        public List<String> getAuthorities() {
-            return authorities;
-        }
-
-        public void setAuthorities(List<String> authorities) {
-            this.authorities = authorities;
-        }
-
-    }
-
-    public static class UserGrantedAuthority implements GrantedAuthority {
-        private static final long serialVersionUID = -5128905636841891058L;
-
-        private String authority;
-
-        public UserGrantedAuthority() {
-        }
-
-        public UserGrantedAuthority(String authority) {
-            setAuthority(authority);
-        }
-
-        @Override
-        public String getAuthority() {
-            return authority;
-        }
-
-        public void setAuthority(String authority) {
-            this.authority = authority;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((authority == null) ? 0 : 
authority.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
-                return true;
-            if (obj == null)
-                return false;
-            if (getClass() != obj.getClass())
-                return false;
-            UserGrantedAuthority other = (UserGrantedAuthority) obj;
-            if (authority == null) {
-                if (other.authority != null)
-                    return false;
-            } else if (!authority.equals(other.authority))
-                return false;
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            return authority;
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/4c18526c/server/src/test/java/org/apache/kylin/rest/service/ServiceTestBase.java
----------------------------------------------------------------------
diff --git 
a/server/src/test/java/org/apache/kylin/rest/service/ServiceTestBase.java 
b/server/src/test/java/org/apache/kylin/rest/service/ServiceTestBase.java
index 0442bb5..7370c48 100644
--- a/server/src/test/java/org/apache/kylin/rest/service/ServiceTestBase.java
+++ b/server/src/test/java/org/apache/kylin/rest/service/ServiceTestBase.java
@@ -70,17 +70,17 @@ public class ServiceTestBase extends 
LocalFileMetadataTestCase {
 
         if (!userService.userExists("ADMIN")) {
             userService.createUser(new User("ADMIN", "KYLIN", Arrays.asList(//
-                new UserService.UserGrantedAuthority(Constant.ROLE_ADMIN), new 
UserService.UserGrantedAuthority(Constant.ROLE_ANALYST), new 
UserService.UserGrantedAuthority(Constant.ROLE_MODELER))));
+                new UserGrantedAuthority(Constant.ROLE_ADMIN), new 
UserGrantedAuthority(Constant.ROLE_ANALYST), new 
UserGrantedAuthority(Constant.ROLE_MODELER))));
         }
 
         if (!userService.userExists("MODELER")) {
             userService.createUser(new User("MODELER", "MODELER", 
Arrays.asList(//
-                new UserService.UserGrantedAuthority(Constant.ROLE_ANALYST), 
new UserService.UserGrantedAuthority(Constant.ROLE_MODELER))));
+                new UserGrantedAuthority(Constant.ROLE_ANALYST), new 
UserGrantedAuthority(Constant.ROLE_MODELER))));
         }
 
         if (!userService.userExists("ANALYST")) {
             userService.createUser(new User("ANALYST", "ANALYST", 
Arrays.asList(//
-                new UserService.UserGrantedAuthority(Constant.ROLE_ANALYST))));
+                new UserGrantedAuthority(Constant.ROLE_ANALYST))));
         }
     }
 

Reply via email to