nichunen commented on a change in pull request #803: KYLIN-4139 Compatible old
user security xml config when user upgrate …
URL: https://github.com/apache/kylin/pull/803#discussion_r316130626
##########
File path:
server-base/src/main/java/org/apache/kylin/rest/service/KylinUserService.java
##########
@@ -58,6 +61,67 @@
public static final Serializer<ManagedUser> SERIALIZER = new
JsonSerializer<>(ManagedUser.class);
+ private static final String ACTIVE_PROFILES_NAME =
"spring.profiles.active";
+
+ private static final String ADMIN = "ADMIN";
+ private static final String MODELER = "MODELER";
+ private static final String ANALYST = "ANALYST";
+ private static final String ADMIN_DEFAULT = "KYLIN";
+ private BCryptPasswordEncoder pwdEncoder;
+ public List<User> configUsers;
+
+ public KylinUserService() {
+ }
+
+ public KylinUserService(List<User> users) throws IOException {
+ pwdEncoder = new BCryptPasswordEncoder();
+ synchronized (KylinUserService.class) {
+ if (!StringUtils.equals("testing",
System.getProperty(ACTIVE_PROFILES_NAME))) {
+ return;
+ }
+ List<ManagedUser> all = listUsers();
+ configUsers = users;
+ // old security.xml config user pwd sync to user metadata
+ if (!configUsers.isEmpty()) {
+ for (User cuser : configUsers) {
+ try {
+ String username = cuser.getUsername();
+ ManagedUser userDetail = (ManagedUser)
loadUserByUsername(username);
+ if (userDetail != null && new
KylinVersion(userDetail.getVersion()).major < KylinVersion
+ .getCurrentVersion().major) {
+ updateUser(new ManagedUser(cuser.getUsername(),
cuser.getPassword(), false,
+ cuser.getAuthorities()));
+ }
+ } catch (UsernameNotFoundException e) {
+ // add new security user in security.xml if it is not
in metadata
+ createUser(new ManagedUser(cuser.getUsername(),
cuser.getPassword(), false,
+ cuser.getAuthorities()));
+ }
+ }
+ }
+ // add default user info in metadata
+ if (all.isEmpty() && configUsers.isEmpty()) {
+ createUser(new ManagedUser(ADMIN,
pwdEncoder.encode(ADMIN_DEFAULT), true, Constant.ROLE_ADMIN,
+ Constant.GROUP_ALL_USERS));
+ createUser(new ManagedUser(ANALYST,
pwdEncoder.encode(ANALYST), true, Constant.GROUP_ALL_USERS));
+ createUser(new ManagedUser(MODELER,
pwdEncoder.encode(MODELER), true, Constant.GROUP_ALL_USERS));
+ }
+ }
+
+ }
+
+ private User getConfigUser(String userName) {
Review comment:
Seems useless
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services