This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new f56d671  DLAB-1060 fixed bug connected with roles
f56d671 is described below

commit f56d67187f32c29e2b883da867bf707820c47e37
Author: bhliva <[email protected]>
AuthorDate: Thu Sep 5 17:14:11 2019 +0300

    DLAB-1060 fixed bug connected with roles
---
 .../java/com/epam/dlab/backendapi/roles/UserRoles.java | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
index 0767c64..bbcf6da 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
@@ -70,16 +70,16 @@ public class UserRoles {
                LOGGER.trace("Loading roles from database...");
                if (userRoles == null) {
                        userRoles = new UserRoles();
-                       userRoles.load(dao, defaultAccess);
-                       LOGGER.trace("New roles are     : {}", getRoles());
                }
+               userRoles.load(dao, defaultAccess);
+               LOGGER.trace("New roles are     : {}", getRoles());
        }
 
        /**
         * Return the list of roles for all users.
         */
        public static List<UserRole> getRoles() {
-               return (userRoles == null ? null : userRoles.roles);
+               return (userRoles == null ? null : userRoles.roles());
        }
 
        /**
@@ -97,12 +97,8 @@ public class UserRoles {
 
        public static boolean isAdmin(UserInfo userInfo) {
                final List<UserRole> roles = UserRoles.getRoles();
-               if (roles == null || roles.isEmpty()) {
-                       System.out.println("=============EMPTY==========");
-               }
-               final boolean b = roles == null || roles.stream().anyMatch(r -> 
ADMIN_ROLE_NAME.equals(r.getId()) &&
+               return roles == null || roles.stream().anyMatch(r -> 
ADMIN_ROLE_NAME.equals(r.getId()) &&
                                (userRoles.hasAccessByGroup(userInfo, r, 
userInfo.getRoles()) || userRoles.hasAccessByUserName(userInfo, r)));
-               return b;
        }
 
        /**
@@ -149,6 +145,10 @@ public class UserRoles {
                }
        }
 
+       private synchronized List<UserRole> roles() {
+               return roles;
+       }
+
        /**
         * Append new role to the list if role not exists in list an return it, 
otherwise return
         * existence role.
@@ -293,4 +293,6 @@ public class UserRoles {
                                .addValue(roles)
                                .toString();
        }
+
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to