@SuppressWarnings("unchecked") @Test void populate() { User user = mock(User.class); when(userFactory.create()).thenReturn(user); Role role = mock(Role.class); when(roleFactory.create()).thenReturn(role); usersRolesPopulatorImpl.populate(); verify(dataService).add(eq("sys_sec_User"), any(Stream.class)); verify(dataService).add(eq("sys_sec_Role"), any(Stream.class)); }
@Override @Transactional @RunAsSystem public void populate() { boolean changeAdminPassword = false; if (adminPassword == null) { adminPassword = UUID.randomUUID().toString(); changeAdminPassword = true; LOG.info("Password for user 'admin': {}", adminPassword); } User userAdmin = userFactory.create(); userAdmin.setUsername(USERNAME_ADMIN); userAdmin.setPassword(adminPassword); userAdmin.setEmail(adminEmail); userAdmin.setActive(true); userAdmin.setSuperuser(true); userAdmin.setChangePassword(changeAdminPassword); User anonymousUser = userFactory.create(); anonymousUser.setUsername(ANONYMOUS_USERNAME); anonymousUser.setPassword(ANONYMOUS_USERNAME); anonymousUser.setEmail(anonymousEmail); anonymousUser.setActive(true); anonymousUser.setSuperuser(false); anonymousUser.setChangePassword(false); Role anonymousRole = roleFactory.create(); anonymousRole.setName(getRoleName(AUTHORITY_ANONYMOUS)); anonymousRole.setLabel("Anonymous"); anonymousRole.setLabel("en", "Anonymous"); anonymousRole.setLabel("nl", "Anoniem"); anonymousRole.setDescription( "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "en", "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "nl", "Rol voor alle gebruikers, inclusief ongeauthenticeerde gebruikers."); Role userRole = roleFactory.create(); userRole.setName(getRoleName(AUTHORITY_USER)); userRole.setLabel("User"); userRole.setLabel("en", "User"); userRole.setLabel("nl", "Gebruiker"); userRole.setDescription("All authenticated users are a member of this Role."); userRole.setDescription("en", "All authenticated users are a member of this role."); userRole.setDescription("nl", "Alle geauthenticeerde gebruikers hebben deze rol."); userRole.setIncludes(ImmutableList.of(anonymousRole)); Role viewer = roleFactory.create(); viewer.setName(getRoleName(AUTHORITY_VIEWER)); viewer.setLabel("Viewer"); viewer.setDescription( "Role containing permissions needed to view data. This role is included in all group viewer roles."); Role editor = roleFactory.create(); editor.setName(getRoleName(AUTHORITY_EDITOR)); editor.setLabel("Editor"); editor.setDescription( "Role containing permissions needed to edit data. This role is included in all group editor roles."); editor.setIncludes(ImmutableList.of(viewer)); Role manager = roleFactory.create(); manager.setName(getRoleName(AUTHORITY_MANAGER)); manager.setLabel("Manager"); manager.setDescription( "Role containing permissions needed to manage groups. This role is included in all group manager roles."); manager.setIncludes(ImmutableList.of(editor)); Role metrics = roleFactory.create(); metrics.setName(getRoleName(ROLE_METRICS)); metrics.setLabel("View metrics"); metrics.setDescription("Role granting the permission to view metrics."); Role aclTakeOwnership = roleFactory.create(); aclTakeOwnership.setName(getRoleName(ROLE_ACL_TAKE_OWNERSHIP)); aclTakeOwnership.setLabel("Take resource ownership"); aclTakeOwnership.setDescription("Role granting the permission to change resource ownership."); Role aclModifyAuditing = roleFactory.create(); aclModifyAuditing.setName(getRoleName(ROLE_ACL_MODIFY_AUDITING)); aclModifyAuditing.setLabel("Modify access control auditing"); aclModifyAuditing.setDescription("Role granting the permission to modify auditing details."); Role aclGeneralChanges = roleFactory.create(); aclGeneralChanges.setName(getRoleName(ROLE_ACL_GENERAL_CHANGES)); aclGeneralChanges.setLabel("General access control changes"); aclGeneralChanges.setDescription( "Role granting the permission to make general access control list changes."); Role su = roleFactory.create(); su.setName(getRoleName(AUTHORITY_SU)); su.setLabel("Superuser"); su.setDescription("Role granted to superusers."); su.setIncludes( ImmutableList.of(aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics)); Role system = roleFactory.create(); system.setName(getRoleName(ROLE_SYSTEM)); system.setLabel("System"); system.setDescription("Role granted to system."); system.setIncludes(ImmutableList.of(su)); dataService.add(USER, Stream.of(userAdmin, anonymousUser)); dataService.add( ROLE, Stream.of( anonymousRole, userRole, aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics, viewer, editor, manager, su, system)); }
UsersRolesPopulatorImpl implements UsersRolesPopulator { @Override @Transactional @RunAsSystem public void populate() { boolean changeAdminPassword = false; if (adminPassword == null) { adminPassword = UUID.randomUUID().toString(); changeAdminPassword = true; LOG.info("Password for user 'admin': {}", adminPassword); } User userAdmin = userFactory.create(); userAdmin.setUsername(USERNAME_ADMIN); userAdmin.setPassword(adminPassword); userAdmin.setEmail(adminEmail); userAdmin.setActive(true); userAdmin.setSuperuser(true); userAdmin.setChangePassword(changeAdminPassword); User anonymousUser = userFactory.create(); anonymousUser.setUsername(ANONYMOUS_USERNAME); anonymousUser.setPassword(ANONYMOUS_USERNAME); anonymousUser.setEmail(anonymousEmail); anonymousUser.setActive(true); anonymousUser.setSuperuser(false); anonymousUser.setChangePassword(false); Role anonymousRole = roleFactory.create(); anonymousRole.setName(getRoleName(AUTHORITY_ANONYMOUS)); anonymousRole.setLabel("Anonymous"); anonymousRole.setLabel("en", "Anonymous"); anonymousRole.setLabel("nl", "Anoniem"); anonymousRole.setDescription( "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "en", "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "nl", "Rol voor alle gebruikers, inclusief ongeauthenticeerde gebruikers."); Role userRole = roleFactory.create(); userRole.setName(getRoleName(AUTHORITY_USER)); userRole.setLabel("User"); userRole.setLabel("en", "User"); userRole.setLabel("nl", "Gebruiker"); userRole.setDescription("All authenticated users are a member of this Role."); userRole.setDescription("en", "All authenticated users are a member of this role."); userRole.setDescription("nl", "Alle geauthenticeerde gebruikers hebben deze rol."); userRole.setIncludes(ImmutableList.of(anonymousRole)); Role viewer = roleFactory.create(); viewer.setName(getRoleName(AUTHORITY_VIEWER)); viewer.setLabel("Viewer"); viewer.setDescription( "Role containing permissions needed to view data. This role is included in all group viewer roles."); Role editor = roleFactory.create(); editor.setName(getRoleName(AUTHORITY_EDITOR)); editor.setLabel("Editor"); editor.setDescription( "Role containing permissions needed to edit data. This role is included in all group editor roles."); editor.setIncludes(ImmutableList.of(viewer)); Role manager = roleFactory.create(); manager.setName(getRoleName(AUTHORITY_MANAGER)); manager.setLabel("Manager"); manager.setDescription( "Role containing permissions needed to manage groups. This role is included in all group manager roles."); manager.setIncludes(ImmutableList.of(editor)); Role metrics = roleFactory.create(); metrics.setName(getRoleName(ROLE_METRICS)); metrics.setLabel("View metrics"); metrics.setDescription("Role granting the permission to view metrics."); Role aclTakeOwnership = roleFactory.create(); aclTakeOwnership.setName(getRoleName(ROLE_ACL_TAKE_OWNERSHIP)); aclTakeOwnership.setLabel("Take resource ownership"); aclTakeOwnership.setDescription("Role granting the permission to change resource ownership."); Role aclModifyAuditing = roleFactory.create(); aclModifyAuditing.setName(getRoleName(ROLE_ACL_MODIFY_AUDITING)); aclModifyAuditing.setLabel("Modify access control auditing"); aclModifyAuditing.setDescription("Role granting the permission to modify auditing details."); Role aclGeneralChanges = roleFactory.create(); aclGeneralChanges.setName(getRoleName(ROLE_ACL_GENERAL_CHANGES)); aclGeneralChanges.setLabel("General access control changes"); aclGeneralChanges.setDescription( "Role granting the permission to make general access control list changes."); Role su = roleFactory.create(); su.setName(getRoleName(AUTHORITY_SU)); su.setLabel("Superuser"); su.setDescription("Role granted to superusers."); su.setIncludes( ImmutableList.of(aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics)); Role system = roleFactory.create(); system.setName(getRoleName(ROLE_SYSTEM)); system.setLabel("System"); system.setDescription("Role granted to system."); system.setIncludes(ImmutableList.of(su)); dataService.add(USER, Stream.of(userAdmin, anonymousUser)); dataService.add( ROLE, Stream.of( anonymousRole, userRole, aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics, viewer, editor, manager, su, system)); } }
UsersRolesPopulatorImpl implements UsersRolesPopulator { @Override @Transactional @RunAsSystem public void populate() { boolean changeAdminPassword = false; if (adminPassword == null) { adminPassword = UUID.randomUUID().toString(); changeAdminPassword = true; LOG.info("Password for user 'admin': {}", adminPassword); } User userAdmin = userFactory.create(); userAdmin.setUsername(USERNAME_ADMIN); userAdmin.setPassword(adminPassword); userAdmin.setEmail(adminEmail); userAdmin.setActive(true); userAdmin.setSuperuser(true); userAdmin.setChangePassword(changeAdminPassword); User anonymousUser = userFactory.create(); anonymousUser.setUsername(ANONYMOUS_USERNAME); anonymousUser.setPassword(ANONYMOUS_USERNAME); anonymousUser.setEmail(anonymousEmail); anonymousUser.setActive(true); anonymousUser.setSuperuser(false); anonymousUser.setChangePassword(false); Role anonymousRole = roleFactory.create(); anonymousRole.setName(getRoleName(AUTHORITY_ANONYMOUS)); anonymousRole.setLabel("Anonymous"); anonymousRole.setLabel("en", "Anonymous"); anonymousRole.setLabel("nl", "Anoniem"); anonymousRole.setDescription( "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "en", "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "nl", "Rol voor alle gebruikers, inclusief ongeauthenticeerde gebruikers."); Role userRole = roleFactory.create(); userRole.setName(getRoleName(AUTHORITY_USER)); userRole.setLabel("User"); userRole.setLabel("en", "User"); userRole.setLabel("nl", "Gebruiker"); userRole.setDescription("All authenticated users are a member of this Role."); userRole.setDescription("en", "All authenticated users are a member of this role."); userRole.setDescription("nl", "Alle geauthenticeerde gebruikers hebben deze rol."); userRole.setIncludes(ImmutableList.of(anonymousRole)); Role viewer = roleFactory.create(); viewer.setName(getRoleName(AUTHORITY_VIEWER)); viewer.setLabel("Viewer"); viewer.setDescription( "Role containing permissions needed to view data. This role is included in all group viewer roles."); Role editor = roleFactory.create(); editor.setName(getRoleName(AUTHORITY_EDITOR)); editor.setLabel("Editor"); editor.setDescription( "Role containing permissions needed to edit data. This role is included in all group editor roles."); editor.setIncludes(ImmutableList.of(viewer)); Role manager = roleFactory.create(); manager.setName(getRoleName(AUTHORITY_MANAGER)); manager.setLabel("Manager"); manager.setDescription( "Role containing permissions needed to manage groups. This role is included in all group manager roles."); manager.setIncludes(ImmutableList.of(editor)); Role metrics = roleFactory.create(); metrics.setName(getRoleName(ROLE_METRICS)); metrics.setLabel("View metrics"); metrics.setDescription("Role granting the permission to view metrics."); Role aclTakeOwnership = roleFactory.create(); aclTakeOwnership.setName(getRoleName(ROLE_ACL_TAKE_OWNERSHIP)); aclTakeOwnership.setLabel("Take resource ownership"); aclTakeOwnership.setDescription("Role granting the permission to change resource ownership."); Role aclModifyAuditing = roleFactory.create(); aclModifyAuditing.setName(getRoleName(ROLE_ACL_MODIFY_AUDITING)); aclModifyAuditing.setLabel("Modify access control auditing"); aclModifyAuditing.setDescription("Role granting the permission to modify auditing details."); Role aclGeneralChanges = roleFactory.create(); aclGeneralChanges.setName(getRoleName(ROLE_ACL_GENERAL_CHANGES)); aclGeneralChanges.setLabel("General access control changes"); aclGeneralChanges.setDescription( "Role granting the permission to make general access control list changes."); Role su = roleFactory.create(); su.setName(getRoleName(AUTHORITY_SU)); su.setLabel("Superuser"); su.setDescription("Role granted to superusers."); su.setIncludes( ImmutableList.of(aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics)); Role system = roleFactory.create(); system.setName(getRoleName(ROLE_SYSTEM)); system.setLabel("System"); system.setDescription("Role granted to system."); system.setIncludes(ImmutableList.of(su)); dataService.add(USER, Stream.of(userAdmin, anonymousUser)); dataService.add( ROLE, Stream.of( anonymousRole, userRole, aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics, viewer, editor, manager, su, system)); } UsersRolesPopulatorImpl(
      DataService dataService, UserFactory userFactory, RoleFactory roleFactory); }
UsersRolesPopulatorImpl implements UsersRolesPopulator { @Override @Transactional @RunAsSystem public void populate() { boolean changeAdminPassword = false; if (adminPassword == null) { adminPassword = UUID.randomUUID().toString(); changeAdminPassword = true; LOG.info("Password for user 'admin': {}", adminPassword); } User userAdmin = userFactory.create(); userAdmin.setUsername(USERNAME_ADMIN); userAdmin.setPassword(adminPassword); userAdmin.setEmail(adminEmail); userAdmin.setActive(true); userAdmin.setSuperuser(true); userAdmin.setChangePassword(changeAdminPassword); User anonymousUser = userFactory.create(); anonymousUser.setUsername(ANONYMOUS_USERNAME); anonymousUser.setPassword(ANONYMOUS_USERNAME); anonymousUser.setEmail(anonymousEmail); anonymousUser.setActive(true); anonymousUser.setSuperuser(false); anonymousUser.setChangePassword(false); Role anonymousRole = roleFactory.create(); anonymousRole.setName(getRoleName(AUTHORITY_ANONYMOUS)); anonymousRole.setLabel("Anonymous"); anonymousRole.setLabel("en", "Anonymous"); anonymousRole.setLabel("nl", "Anoniem"); anonymousRole.setDescription( "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "en", "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "nl", "Rol voor alle gebruikers, inclusief ongeauthenticeerde gebruikers."); Role userRole = roleFactory.create(); userRole.setName(getRoleName(AUTHORITY_USER)); userRole.setLabel("User"); userRole.setLabel("en", "User"); userRole.setLabel("nl", "Gebruiker"); userRole.setDescription("All authenticated users are a member of this Role."); userRole.setDescription("en", "All authenticated users are a member of this role."); userRole.setDescription("nl", "Alle geauthenticeerde gebruikers hebben deze rol."); userRole.setIncludes(ImmutableList.of(anonymousRole)); Role viewer = roleFactory.create(); viewer.setName(getRoleName(AUTHORITY_VIEWER)); viewer.setLabel("Viewer"); viewer.setDescription( "Role containing permissions needed to view data. This role is included in all group viewer roles."); Role editor = roleFactory.create(); editor.setName(getRoleName(AUTHORITY_EDITOR)); editor.setLabel("Editor"); editor.setDescription( "Role containing permissions needed to edit data. This role is included in all group editor roles."); editor.setIncludes(ImmutableList.of(viewer)); Role manager = roleFactory.create(); manager.setName(getRoleName(AUTHORITY_MANAGER)); manager.setLabel("Manager"); manager.setDescription( "Role containing permissions needed to manage groups. This role is included in all group manager roles."); manager.setIncludes(ImmutableList.of(editor)); Role metrics = roleFactory.create(); metrics.setName(getRoleName(ROLE_METRICS)); metrics.setLabel("View metrics"); metrics.setDescription("Role granting the permission to view metrics."); Role aclTakeOwnership = roleFactory.create(); aclTakeOwnership.setName(getRoleName(ROLE_ACL_TAKE_OWNERSHIP)); aclTakeOwnership.setLabel("Take resource ownership"); aclTakeOwnership.setDescription("Role granting the permission to change resource ownership."); Role aclModifyAuditing = roleFactory.create(); aclModifyAuditing.setName(getRoleName(ROLE_ACL_MODIFY_AUDITING)); aclModifyAuditing.setLabel("Modify access control auditing"); aclModifyAuditing.setDescription("Role granting the permission to modify auditing details."); Role aclGeneralChanges = roleFactory.create(); aclGeneralChanges.setName(getRoleName(ROLE_ACL_GENERAL_CHANGES)); aclGeneralChanges.setLabel("General access control changes"); aclGeneralChanges.setDescription( "Role granting the permission to make general access control list changes."); Role su = roleFactory.create(); su.setName(getRoleName(AUTHORITY_SU)); su.setLabel("Superuser"); su.setDescription("Role granted to superusers."); su.setIncludes( ImmutableList.of(aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics)); Role system = roleFactory.create(); system.setName(getRoleName(ROLE_SYSTEM)); system.setLabel("System"); system.setDescription("Role granted to system."); system.setIncludes(ImmutableList.of(su)); dataService.add(USER, Stream.of(userAdmin, anonymousUser)); dataService.add( ROLE, Stream.of( anonymousRole, userRole, aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics, viewer, editor, manager, su, system)); } UsersRolesPopulatorImpl(
      DataService dataService, UserFactory userFactory, RoleFactory roleFactory); @Override @Transactional @RunAsSystem void populate(); }
UsersRolesPopulatorImpl implements UsersRolesPopulator { @Override @Transactional @RunAsSystem public void populate() { boolean changeAdminPassword = false; if (adminPassword == null) { adminPassword = UUID.randomUUID().toString(); changeAdminPassword = true; LOG.info("Password for user 'admin': {}", adminPassword); } User userAdmin = userFactory.create(); userAdmin.setUsername(USERNAME_ADMIN); userAdmin.setPassword(adminPassword); userAdmin.setEmail(adminEmail); userAdmin.setActive(true); userAdmin.setSuperuser(true); userAdmin.setChangePassword(changeAdminPassword); User anonymousUser = userFactory.create(); anonymousUser.setUsername(ANONYMOUS_USERNAME); anonymousUser.setPassword(ANONYMOUS_USERNAME); anonymousUser.setEmail(anonymousEmail); anonymousUser.setActive(true); anonymousUser.setSuperuser(false); anonymousUser.setChangePassword(false); Role anonymousRole = roleFactory.create(); anonymousRole.setName(getRoleName(AUTHORITY_ANONYMOUS)); anonymousRole.setLabel("Anonymous"); anonymousRole.setLabel("en", "Anonymous"); anonymousRole.setLabel("nl", "Anoniem"); anonymousRole.setDescription( "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "en", "Role for permissions granted to all users, including unauthenticated users."); anonymousRole.setDescription( "nl", "Rol voor alle gebruikers, inclusief ongeauthenticeerde gebruikers."); Role userRole = roleFactory.create(); userRole.setName(getRoleName(AUTHORITY_USER)); userRole.setLabel("User"); userRole.setLabel("en", "User"); userRole.setLabel("nl", "Gebruiker"); userRole.setDescription("All authenticated users are a member of this Role."); userRole.setDescription("en", "All authenticated users are a member of this role."); userRole.setDescription("nl", "Alle geauthenticeerde gebruikers hebben deze rol."); userRole.setIncludes(ImmutableList.of(anonymousRole)); Role viewer = roleFactory.create(); viewer.setName(getRoleName(AUTHORITY_VIEWER)); viewer.setLabel("Viewer"); viewer.setDescription( "Role containing permissions needed to view data. This role is included in all group viewer roles."); Role editor = roleFactory.create(); editor.setName(getRoleName(AUTHORITY_EDITOR)); editor.setLabel("Editor"); editor.setDescription( "Role containing permissions needed to edit data. This role is included in all group editor roles."); editor.setIncludes(ImmutableList.of(viewer)); Role manager = roleFactory.create(); manager.setName(getRoleName(AUTHORITY_MANAGER)); manager.setLabel("Manager"); manager.setDescription( "Role containing permissions needed to manage groups. This role is included in all group manager roles."); manager.setIncludes(ImmutableList.of(editor)); Role metrics = roleFactory.create(); metrics.setName(getRoleName(ROLE_METRICS)); metrics.setLabel("View metrics"); metrics.setDescription("Role granting the permission to view metrics."); Role aclTakeOwnership = roleFactory.create(); aclTakeOwnership.setName(getRoleName(ROLE_ACL_TAKE_OWNERSHIP)); aclTakeOwnership.setLabel("Take resource ownership"); aclTakeOwnership.setDescription("Role granting the permission to change resource ownership."); Role aclModifyAuditing = roleFactory.create(); aclModifyAuditing.setName(getRoleName(ROLE_ACL_MODIFY_AUDITING)); aclModifyAuditing.setLabel("Modify access control auditing"); aclModifyAuditing.setDescription("Role granting the permission to modify auditing details."); Role aclGeneralChanges = roleFactory.create(); aclGeneralChanges.setName(getRoleName(ROLE_ACL_GENERAL_CHANGES)); aclGeneralChanges.setLabel("General access control changes"); aclGeneralChanges.setDescription( "Role granting the permission to make general access control list changes."); Role su = roleFactory.create(); su.setName(getRoleName(AUTHORITY_SU)); su.setLabel("Superuser"); su.setDescription("Role granted to superusers."); su.setIncludes( ImmutableList.of(aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics)); Role system = roleFactory.create(); system.setName(getRoleName(ROLE_SYSTEM)); system.setLabel("System"); system.setDescription("Role granted to system."); system.setIncludes(ImmutableList.of(su)); dataService.add(USER, Stream.of(userAdmin, anonymousUser)); dataService.add( ROLE, Stream.of( anonymousRole, userRole, aclTakeOwnership, aclModifyAuditing, aclGeneralChanges, metrics, viewer, editor, manager, su, system)); } UsersRolesPopulatorImpl(
      DataService dataService, UserFactory userFactory, RoleFactory roleFactory); @Override @Transactional @RunAsSystem void populate();  }