@Test public void getAllUserRolesOneSuperadminTest() { List<UserRole> userRoleList = new ArrayList<>(); userRoleList.add( UserRole.builder().appName("*").role("superadmin").userId("test").build() ); List<UserInfo> userInfo = new ArrayList<>(); userInfo.add(UserInfo.builder() .firstName("test1") .lastName("test1") .userEmail("test1@test.com") .userId("test") .build()); when(userInfoAccessor.getUserInfoBy(eq("test"))).thenReturn(userInfoResult); when(userInfoResult.iterator()).thenReturn(userInfo.iterator()); when(userRoleAccessor.getAllUserRoles()).thenReturn(userRoleResult); when(userRoleResult.all()).thenReturn(userRoleList); List<com.intuit.wasabi.authorizationobjects.UserRole> result = repository.getSuperAdminRoleList(); logger.info(result.toString()); assertThat(result.size(), is(1)); }
@Override public List<UserRole> getSuperAdminRoleList() { LOGGER.debug("Getting super admin role list"); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> allUserRoles = userRoleAccessor.getAllUserRoles().all(); LOGGER.debug("Received all roles {}", allUserRoles); List<UserRole> superAdmins = allUserRoles.stream().filter( userRole -> Role.SUPERADMIN.toString().equalsIgnoreCase( userRole.getRole().toString()) && ALL_APPLICATIONS.equals(userRole.getAppName())).map( userRole -> getRoleWithUserInfo(userRole)).collect(Collectors.toList()); LOGGER.debug("Returning {} roles", superAdmins); return superAdmins; }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public List<UserRole> getSuperAdminRoleList() { LOGGER.debug("Getting super admin role list"); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> allUserRoles = userRoleAccessor.getAllUserRoles().all(); LOGGER.debug("Received all roles {}", allUserRoles); List<UserRole> superAdmins = allUserRoles.stream().filter( userRole -> Role.SUPERADMIN.toString().equalsIgnoreCase( userRole.getRole().toString()) && ALL_APPLICATIONS.equals(userRole.getAppName())).map( userRole -> getRoleWithUserInfo(userRole)).collect(Collectors.toList()); LOGGER.debug("Returning {} roles", superAdmins); return superAdmins; } }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public List<UserRole> getSuperAdminRoleList() { LOGGER.debug("Getting super admin role list"); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> allUserRoles = userRoleAccessor.getAllUserRoles().all(); LOGGER.debug("Received all roles {}", allUserRoles); List<UserRole> superAdmins = allUserRoles.stream().filter( userRole -> Role.SUPERADMIN.toString().equalsIgnoreCase( userRole.getRole().toString()) && ALL_APPLICATIONS.equals(userRole.getAppName())).map( userRole -> getRoleWithUserInfo(userRole)).collect(Collectors.toList()); LOGGER.debug("Returning {} roles", superAdmins); return superAdmins; } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public List<UserRole> getSuperAdminRoleList() { LOGGER.debug("Getting super admin role list"); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> allUserRoles = userRoleAccessor.getAllUserRoles().all(); LOGGER.debug("Received all roles {}", allUserRoles); List<UserRole> superAdmins = allUserRoles.stream().filter( userRole -> Role.SUPERADMIN.toString().equalsIgnoreCase( userRole.getRole().toString()) && ALL_APPLICATIONS.equals(userRole.getAppName())).map( userRole -> getRoleWithUserInfo(userRole)).collect(Collectors.toList()); LOGGER.debug("Returning {} roles", superAdmins); return superAdmins; } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); @Override UserPermissionsList getUserPermissionsList(UserInfo.Username userID); @Override UserRoleList getApplicationUsers(Application.Name applicationName); @Override UserPermissions getUserPermissions(@Nonnull UserInfo.Username username,
                                              @Nonnull Application.Name applicationName); @Override void deleteUserRole(UserInfo.Username userID, Application.Name applicationName); @Override void setUserRole(UserRole userRole); @Override UserRoleList getUserRoleList(UserInfo.Username userID); @Override UserInfo getUserInfo(UserInfo.Username userID); @Override void setUserInfo(UserInfo userInfo); @Override UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName); @Override void assignUserToSuperAdminRole(UserInfo candidateUser); @Override void removeUserFromSuperAdminRole(UserInfo candidateUser); @Override List<UserRole> getSuperAdminRoleList(); }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public List<UserRole> getSuperAdminRoleList() { LOGGER.debug("Getting super admin role list"); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> allUserRoles = userRoleAccessor.getAllUserRoles().all(); LOGGER.debug("Received all roles {}", allUserRoles); List<UserRole> superAdmins = allUserRoles.stream().filter( userRole -> Role.SUPERADMIN.toString().equalsIgnoreCase( userRole.getRole().toString()) && ALL_APPLICATIONS.equals(userRole.getAppName())).map( userRole -> getRoleWithUserInfo(userRole)).collect(Collectors.toList()); LOGGER.debug("Returning {} roles", superAdmins); return superAdmins; } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); @Override UserPermissionsList getUserPermissionsList(UserInfo.Username userID); @Override UserRoleList getApplicationUsers(Application.Name applicationName); @Override UserPermissions getUserPermissions(@Nonnull UserInfo.Username username,
                                              @Nonnull Application.Name applicationName); @Override void deleteUserRole(UserInfo.Username userID, Application.Name applicationName); @Override void setUserRole(UserRole userRole); @Override UserRoleList getUserRoleList(UserInfo.Username userID); @Override UserInfo getUserInfo(UserInfo.Username userID); @Override void setUserInfo(UserInfo userInfo); @Override UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName); @Override void assignUserToSuperAdminRole(UserInfo candidateUser); @Override void removeUserFromSuperAdminRole(UserInfo candidateUser); @Override List<UserRole> getSuperAdminRoleList(); static final String ALL_APPLICATIONS; }