You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/06/22 13:57:14 UTC
kylin git commit: fix UserService backward compatibility
Repository: kylin
Updated Branches:
refs/heads/master def979d9c -> 8d8ec0636
fix UserService backward compatibility
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/8d8ec063
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/8d8ec063
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/8d8ec063
Branch: refs/heads/master
Commit: 8d8ec0636cc1a66e1e3969dcd0b78a439ec420f4
Parents: def979d
Author: Yang Li <li...@apache.org>
Authored: Wed Jun 22 21:56:53 2016 +0800
Committer: Yang Li <li...@apache.org>
Committed: Wed Jun 22 21:56:53 2016 +0800
----------------------------------------------------------------------
.../apache/kylin/rest/service/UserService.java | 36 +++++++++++++-------
1 file changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/8d8ec063/server/src/main/java/org/apache/kylin/rest/service/UserService.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/service/UserService.java b/server/src/main/java/org/apache/kylin/rest/service/UserService.java
index 2e27ca4..a3b4293 100644
--- a/server/src/main/java/org/apache/kylin/rest/service/UserService.java
+++ b/server/src/main/java/org/apache/kylin/rest/service/UserService.java
@@ -58,6 +58,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
@Component("userService")
public class UserService implements UserManager {
+ private static final String PWD_PREFIX = "PWD:";
+
private Serializer<UserGrantedAuthority[]> ugaSerializer = new Serializer<UserGrantedAuthority[]>(UserGrantedAuthority[].class);
private String userTableName = null;
@@ -97,36 +99,46 @@ public class UserService implements UserManager {
return null;
String username = Bytes.toString(result.getRow());
-
+
byte[] valueBytes = result.getValue(Bytes.toBytes(AclHBaseStorage.USER_AUTHORITY_FAMILY), Bytes.toBytes(AclHBaseStorage.USER_AUTHORITY_COLUMN));
UserGrantedAuthority[] deserialized = ugaSerializer.deserialize(valueBytes);
-
- // password is stored as the [0] authority
- String password = deserialized[0].getAuthority();
- List<UserGrantedAuthority> authorities = Arrays.asList(deserialized).subList(1, deserialized.length);
-
+
+ String password = "";
+ List<UserGrantedAuthority> authorities = Collections.emptyList();
+
+ // password is stored at [0] of authorities for backward compatibility
+ if (deserialized != null) {
+ if (deserialized.length > 0 && deserialized[0].getAuthority().startsWith(PWD_PREFIX)) {
+ password = deserialized[0].getAuthority().substring(PWD_PREFIX.length());
+ authorities = Arrays.asList(deserialized).subList(1, deserialized.length);
+ } else {
+ authorities = Arrays.asList(deserialized);
+ }
+ }
+
return new User(username, password, authorities);
}
private Pair<byte[], byte[]> userToHBaseRow(UserDetails user) throws JsonProcessingException {
byte[] key = Bytes.toBytes(user.getUsername());
-
+
Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
if (authorities == null)
authorities = Collections.emptyList();
-
+
UserGrantedAuthority[] serializing = new UserGrantedAuthority[authorities.size() + 1];
+
// password is stored as the [0] authority
- serializing[0] = new UserGrantedAuthority(user.getPassword());
+ serializing[0] = new UserGrantedAuthority(PWD_PREFIX + user.getPassword());
int i = 1;
for (GrantedAuthority a : authorities) {
serializing[i++] = new UserGrantedAuthority(a.getAuthority());
}
-
+
byte[] value = ugaSerializer.serialize(serializing);
return Pair.newPair(key, value);
}
-
+
@Override
public void createUser(UserDetails user) {
updateUser(user);
@@ -230,7 +242,7 @@ public class UserService implements UserManager {
public UserGrantedAuthority(String authority) {
setAuthority(authority);
}
-
+
@Override
public String getAuthority() {
return authority;