@Test public void hasPermissionToAccessUserReturnsTrueWhenUserIsStaffMember() { String accessedUserId = "other"; User accessedUserMock = mock(User.class); given(userMock.getId()).willReturn(USER_ID); given(userServiceMock.userExists(accessedUserId)).willReturn(true); given(userServiceMock.getUserById(accessedUserId)).willReturn(accessedUserMock); given(userServiceMock.userHasStaffMember(userMock, accessedUserMock)).willReturn(true); boolean actualHasPermission = evaluator.hasPermissionToAccessUser(authenticationMock, userMock, accessedUserId); assertThat(actualHasPermission).isTrue(); }
@Override public boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId) { return user.getId().equals(userId) || hasElevatedAccessToUser(authentication, user, userId); }
UserAccessExpressionEvaluator implements ExpressionEvaluator { @Override public boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId) { return user.getId().equals(userId) || hasElevatedAccessToUser(authentication, user, userId); } }
UserAccessExpressionEvaluator implements ExpressionEvaluator { @Override public boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId) { return user.getId().equals(userId) || hasElevatedAccessToUser(authentication, user, userId); } @Autowired  UserAccessExpressionEvaluator(UserService userService,
                                         UserAccessService userAccessService,
                                         ProjectService projectService,
                                         ApplicationService applicationService,
                                         BookmarkService bookmarkService,
                                         ProjectBoardConfigurationProperties properties); }
UserAccessExpressionEvaluator implements ExpressionEvaluator { @Override public boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId) { return user.getId().equals(userId) || hasElevatedAccessToUser(authentication, user, userId); } @Autowired  UserAccessExpressionEvaluator(UserService userService,
                                         UserAccessService userAccessService,
                                         ProjectService projectService,
                                         ApplicationService applicationService,
                                         BookmarkService bookmarkService,
                                         ProjectBoardConfigurationProperties properties); @Override boolean hasAccessToProjects(Authentication authentication, User user); @Override boolean hasAccessToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToApplyToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId); @Override boolean hasElevatedAccessToUser(Authentication authentication, User user, String userId); }
UserAccessExpressionEvaluator implements ExpressionEvaluator { @Override public boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId) { return user.getId().equals(userId) || hasElevatedAccessToUser(authentication, user, userId); } @Autowired  UserAccessExpressionEvaluator(UserService userService,
                                         UserAccessService userAccessService,
                                         ProjectService projectService,
                                         ApplicationService applicationService,
                                         BookmarkService bookmarkService,
                                         ProjectBoardConfigurationProperties properties); @Override boolean hasAccessToProjects(Authentication authentication, User user); @Override boolean hasAccessToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToApplyToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId); @Override boolean hasElevatedAccessToUser(Authentication authentication, User user, String userId);  }