@Test public void getAppSpecificPermissionTest() { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> expected = new ArrayList<>(); com.intuit.wasabi.authenticationobjects.UserInfo.Username testUser = com.intuit.wasabi.authenticationobjects.UserInfo.Username.valueOf("testUser"); Optional<Application.Name> testApp = Optional.ofNullable(Application.Name.valueOf("TestApp")); doReturn(expected).when(spyRepository).getUserRoleList(eq(testUser), eq(testApp)); UserPermissions result = spyRepository.getAppSpecificPermission(testUser, testApp.get()); assertThat(result, is(nullValue())); }
UserPermissions getAppSpecificPermission(UserInfo.Username username, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = getUserRoleList(username, Optional.ofNullable(applicationName)); if (result.size() != 0) { assert result.size() <= 1 : "More than a single row returned"; com.intuit.wasabi.repository.cassandra.pojo.UserRole role = result.get(0); assert role.getRole() != null : "Role cannot be null"; return UserPermissions.newInstance(applicationName, Role.toRole(role.getRole()).getRolePermissions()) .build(); } return null; }
CassandraAuthorizationRepository implements AuthorizationRepository { UserPermissions getAppSpecificPermission(UserInfo.Username username, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = getUserRoleList(username, Optional.ofNullable(applicationName)); if (result.size() != 0) { assert result.size() <= 1 : "More than a single row returned"; com.intuit.wasabi.repository.cassandra.pojo.UserRole role = result.get(0); assert role.getRole() != null : "Role cannot be null"; return UserPermissions.newInstance(applicationName, Role.toRole(role.getRole()).getRolePermissions()) .build(); } return null; } }
CassandraAuthorizationRepository implements AuthorizationRepository { UserPermissions getAppSpecificPermission(UserInfo.Username username, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = getUserRoleList(username, Optional.ofNullable(applicationName)); if (result.size() != 0) { assert result.size() <= 1 : "More than a single row returned"; com.intuit.wasabi.repository.cassandra.pojo.UserRole role = result.get(0); assert role.getRole() != null : "Role cannot be null"; return UserPermissions.newInstance(applicationName, Role.toRole(role.getRole()).getRolePermissions()) .build(); } return null; } @Inject  CassandraAuthorizationRepository(ApplicationListAccessor applicationListAccessor,
                                            AppRoleAccessor appRoleAccessor,
                                            UserRoleAccessor userRoleAccessor,
                                            UserInfoAccessor userInfoAccessor,
                                            UserDirectory userDirectory,
                                            MappingManager mappingManager); }
CassandraAuthorizationRepository implements AuthorizationRepository { UserPermissions getAppSpecificPermission(UserInfo.Username username, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = getUserRoleList(username, Optional.ofNullable(applicationName)); if (result.size() != 0) { assert result.size() <= 1 : "More than a single row returned"; com.intuit.wasabi.repository.cassandra.pojo.UserRole role = result.get(0); assert role.getRole() != null : "Role cannot be null"; return UserPermissions.newInstance(applicationName, Role.toRole(role.getRole()).getRolePermissions()) .build(); } return null; } @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 { UserPermissions getAppSpecificPermission(UserInfo.Username username, Application.Name applicationName) { List<com.intuit.wasabi.repository.cassandra.pojo.UserRole> result = getUserRoleList(username, Optional.ofNullable(applicationName)); if (result.size() != 0) { assert result.size() <= 1 : "More than a single row returned"; com.intuit.wasabi.repository.cassandra.pojo.UserRole role = result.get(0); assert role.getRole() != null : "Role cannot be null"; return UserPermissions.newInstance(applicationName, Role.toRole(role.getRole()).getRolePermissions()) .build(); } return null; } @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; }