@Test public void checkSuperAdminPermissionsTest() { List<UserRole> spiedUserRole = new ArrayList<>(); spiedUserRole.add( UserRole.builder() .appName("test") .role(CassandraAuthorizationRepository.SUPERADMIN) .userId("test") .build() ); doReturn(spiedUserRole).when(spyRepository).getUserRolesWithWildcardAppName( com.intuit.wasabi.authenticationobjects.UserInfo.Username.valueOf("test"), Application.Name.valueOf("test") ); UserPermissions result = spyRepository.checkSuperAdminPermissions( com.intuit.wasabi.authenticationobjects.UserInfo.Username.valueOf("test"), Application.Name.valueOf("test") ); assertThat(result.getApplicationName().toString(), is("test")); assertThat(result.getPermissions(), is(Role.SUPERADMIN.getRolePermissions())); }
@Override public UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRolesWithWildcardAppName(userID, applicationName); Optional<com.intuit.wasabi.repository.cassandra.pojo.UserRole> adminRole = resultList .stream() .filter(t -> SUPERADMIN.equalsIgnoreCase(t.getRole())) .findAny(); if (!adminRole.isPresent()) return null; else return UserPermissions.newInstance(applicationName, Role.SUPERADMIN.getRolePermissions()) .build(); }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRolesWithWildcardAppName(userID, applicationName); Optional<com.intuit.wasabi.repository.cassandra.pojo.UserRole> adminRole = resultList .stream() .filter(t -> SUPERADMIN.equalsIgnoreCase(t.getRole())) .findAny(); if (!adminRole.isPresent()) return null; else return UserPermissions.newInstance(applicationName, Role.SUPERADMIN.getRolePermissions()) .build(); } }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRolesWithWildcardAppName(userID, applicationName); Optional<com.intuit.wasabi.repository.cassandra.pojo.UserRole> adminRole = resultList .stream() .filter(t -> SUPERADMIN.equalsIgnoreCase(t.getRole())) .findAny(); if (!adminRole.isPresent()) return null; else return UserPermissions.newInstance(applicationName, Role.SUPERADMIN.getRolePermissions()) .build(); } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); }
CassandraAuthorizationRepository implements AuthorizationRepository { @Override public UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRolesWithWildcardAppName(userID, applicationName); Optional<com.intuit.wasabi.repository.cassandra.pojo.UserRole> adminRole = resultList .stream() .filter(t -> SUPERADMIN.equalsIgnoreCase(t.getRole())) .findAny(); if (!adminRole.isPresent()) return null; else return UserPermissions.newInstance(applicationName, Role.SUPERADMIN.getRolePermissions()) .build(); } @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 UserPermissions checkSuperAdminPermissions(UserInfo.Username userID, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> resultList = getUserRolesWithWildcardAppName(userID, applicationName); Optional<com.intuit.wasabi.repository.cassandra.pojo.UserRole> adminRole = resultList .stream() .filter(t -> SUPERADMIN.equalsIgnoreCase(t.getRole())) .findAny(); if (!adminRole.isPresent()) return null; else return UserPermissions.newInstance(applicationName, Role.SUPERADMIN.getRolePermissions()) .build(); } @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; }