@Test public void getUserRolesListTest() { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> userRoleList = new ArrayList<>(); userRoleList.add(com.intuit.wasabi.repository.cassandra.pojo.UserRole.builder() .appName("test1") .role("role1") .userId("user1") .build() ); userRoleList.add(com.intuit.wasabi.repository.cassandra.pojo.UserRole.builder() .appName("test2") .role("role2") .userId("user2") .build() ); userRoleList.add(com.intuit.wasabi.repository.cassandra.pojo.UserRole.builder() .appName("test3") .role("role3") .userId("user3") .build() ); when(userRoleAccessor.getUserRolesByUserId(eq("test"))).thenReturn(userRoleResult); when(userRoleResult.iterator()).thenReturn(userRoleList.iterator()); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = repository.getUserRoleList(com.intuit.wasabi.authenticationobjects.UserInfo.Username.valueOf("test"), Optional.empty()); assertThat(result.size(), is(3)); }
@Override public UserRoleList getUserRoleList(UserInfo.Username userID) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> possibleSuperAdmin = getUserRolesWithWildcardAppName(userID, WILDCARD); UserInfo userInfo = retrieveOrDefaultUser(userID); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> superAdmins = possibleSuperAdmin.stream() .filter(v -> SUPERADMIN.equalsIgnoreCase(v.getRole())) .collect(Collectors.toList()); UserRoleList userRoleList = new UserRoleList(); if (superAdmins.size() > 0) { List<String> allAppNamesList = getAllApplicationNameFromApplicationList(); superAdmins.stream() .map(t -> allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build() ).collect(Collectors.toList()) ) .flatMap(Collection::stream) .forEach(userRoleList::addRole); return userRoleList; } List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRoleList(userID, Optional.empty()); resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole()) ) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .withUserEmail(userInfo.getEmail()) .withUserID(userID) .build() ).forEach(userRoleList::addRole); return userRoleList; }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserRoleList getUserRoleList(UserInfo.Username userID) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> possibleSuperAdmin = getUserRolesWithWildcardAppName(userID, WILDCARD); UserInfo userInfo = retrieveOrDefaultUser(userID); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> superAdmins = possibleSuperAdmin.stream() .filter(v -> SUPERADMIN.equalsIgnoreCase(v.getRole())) .collect(Collectors.toList()); UserRoleList userRoleList = new UserRoleList(); if (superAdmins.size() > 0) { List<String> allAppNamesList = getAllApplicationNameFromApplicationList(); superAdmins.stream() .map(t -> allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build() ).collect(Collectors.toList()) ) .flatMap(Collection::stream) .forEach(userRoleList::addRole); return userRoleList; } List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRoleList(userID, Optional.empty()); resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole()) ) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .withUserEmail(userInfo.getEmail()) .withUserID(userID) .build() ).forEach(userRoleList::addRole); return userRoleList; } }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserRoleList getUserRoleList(UserInfo.Username userID) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> possibleSuperAdmin = getUserRolesWithWildcardAppName(userID, WILDCARD); UserInfo userInfo = retrieveOrDefaultUser(userID); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> superAdmins = possibleSuperAdmin.stream() .filter(v -> SUPERADMIN.equalsIgnoreCase(v.getRole())) .collect(Collectors.toList()); UserRoleList userRoleList = new UserRoleList(); if (superAdmins.size() > 0) { List<String> allAppNamesList = getAllApplicationNameFromApplicationList(); superAdmins.stream() .map(t -> allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build() ).collect(Collectors.toList()) ) .flatMap(Collection::stream) .forEach(userRoleList::addRole); return userRoleList; } List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRoleList(userID, Optional.empty()); resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole()) ) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .withUserEmail(userInfo.getEmail()) .withUserID(userID) .build() ).forEach(userRoleList::addRole); return userRoleList; } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserRoleList getUserRoleList(UserInfo.Username userID) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> possibleSuperAdmin = getUserRolesWithWildcardAppName(userID, WILDCARD); UserInfo userInfo = retrieveOrDefaultUser(userID); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> superAdmins = possibleSuperAdmin.stream() .filter(v -> SUPERADMIN.equalsIgnoreCase(v.getRole())) .collect(Collectors.toList()); UserRoleList userRoleList = new UserRoleList(); if (superAdmins.size() > 0) { List<String> allAppNamesList = getAllApplicationNameFromApplicationList(); superAdmins.stream() .map(t -> allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build() ).collect(Collectors.toList()) ) .flatMap(Collection::stream) .forEach(userRoleList::addRole); return userRoleList; } List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRoleList(userID, Optional.empty()); resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole()) ) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .withUserEmail(userInfo.getEmail()) .withUserID(userID) .build() ).forEach(userRoleList::addRole); return userRoleList; } @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 UserRoleList getUserRoleList(UserInfo.Username userID) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> possibleSuperAdmin = getUserRolesWithWildcardAppName(userID, WILDCARD); UserInfo userInfo = retrieveOrDefaultUser(userID); List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> superAdmins = possibleSuperAdmin.stream() .filter(v -> SUPERADMIN.equalsIgnoreCase(v.getRole())) .collect(Collectors.toList()); UserRoleList userRoleList = new UserRoleList(); if (superAdmins.size() > 0) { List<String> allAppNamesList = getAllApplicationNameFromApplicationList(); superAdmins.stream() .map(t -> allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build() ).collect(Collectors.toList()) ) .flatMap(Collection::stream) .forEach(userRoleList::addRole); return userRoleList; } List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRoleList(userID, Optional.empty()); resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole()) ) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .withUserEmail(userInfo.getEmail()) .withUserID(userID) .build() ).forEach(userRoleList::addRole); return userRoleList; } @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; }