@Test void addNonExistingUserToRole() { Attribute userNameAttr = mock(Attribute.class); when(userNameAttr.getName()).thenReturn("username"); when(userMetadata.getAttribute(USERNAME)).thenReturn(userNameAttr); when(userMetadata.getId()).thenReturn("sys_sec_User"); String username = "henk"; when(userService.getUser(username)).thenReturn(null); Exception exception = assertThrows( UnknownEntityException.class, () -> roleMembershipService.addUserToRole(username, "GCC_MANAGER")); assertThat(exception.getMessage()) .containsPattern("type:sys_sec_User id:henk attribute:username"); }
@RunAsSystem @Override public void addUserToRole(String username, String roleName) { User user = userService.getUser(username); if (user == null) { throw new UnknownEntityException(userMetadata, userMetadata.getAttribute(USERNAME), username); } Role role = dataService.query(RoleMetadata.ROLE, Role.class).eq(NAME, roleName).findOne(); if (role == null) { throw new UnknownEntityException(roleMetadata, roleMetadata.getAttribute(NAME), roleName); } this.addUserToRole(user, role); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public void addUserToRole(String username, String roleName) { User user = userService.getUser(username); if (user == null) { throw new UnknownEntityException(userMetadata, userMetadata.getAttribute(USERNAME), username); } Role role = dataService.query(RoleMetadata.ROLE, Role.class).eq(NAME, roleName).findOne(); if (role == null) { throw new UnknownEntityException(roleMetadata, roleMetadata.getAttribute(NAME), roleName); } this.addUserToRole(user, role); } }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public void addUserToRole(String username, String roleName) { User user = userService.getUser(username); if (user == null) { throw new UnknownEntityException(userMetadata, userMetadata.getAttribute(USERNAME), username); } Role role = dataService.query(RoleMetadata.ROLE, Role.class).eq(NAME, roleName).findOne(); if (role == null) { throw new UnknownEntityException(roleMetadata, roleMetadata.getAttribute(NAME), roleName); } this.addUserToRole(user, role); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public void addUserToRole(String username, String roleName) { User user = userService.getUser(username); if (user == null) { throw new UnknownEntityException(userMetadata, userMetadata.getAttribute(USERNAME), username); } Role role = dataService.query(RoleMetadata.ROLE, Role.class).eq(NAME, roleName).findOne(); if (role == null) { throw new UnknownEntityException(roleMetadata, roleMetadata.getAttribute(NAME), roleName); } this.addUserToRole(user, role); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); @RunAsSystem @Override void addUserToRole(String username, String roleName); @RunAsSystem @Override void addUserToRole(final User user, final Role role); @RunAsSystem @Override void removeMembership(final RoleMembership roleMembership); @RunAsSystem @Override void updateMembership(RoleMembership roleMembership, Role newRole); @RunAsSystem @Override Collection<RoleMembership> getMemberships(Collection<Role> roles); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public void addUserToRole(String username, String roleName) { User user = userService.getUser(username); if (user == null) { throw new UnknownEntityException(userMetadata, userMetadata.getAttribute(USERNAME), username); } Role role = dataService.query(RoleMetadata.ROLE, Role.class).eq(NAME, roleName).findOne(); if (role == null) { throw new UnknownEntityException(roleMetadata, roleMetadata.getAttribute(NAME), roleName); } this.addUserToRole(user, role); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); @RunAsSystem @Override void addUserToRole(String username, String roleName); @RunAsSystem @Override void addUserToRole(final User user, final Role role); @RunAsSystem @Override void removeMembership(final RoleMembership roleMembership); @RunAsSystem @Override void updateMembership(RoleMembership roleMembership, Role newRole); @RunAsSystem @Override Collection<RoleMembership> getMemberships(Collection<Role> roles);  }