use of org.eclipse.vorto.repository.domain.UserRepositoryRoles in project vorto by eclipse.
the class UserRepositoryRoleService method updateOrInsertSysadminRole.
private void updateOrInsertSysadminRole(User user) {
UserRepositoryRoles roles = cache.withUser(user).getUserRepositoryRoles().stream().findAny().orElseGet(() -> {
UserRepositoryRoles result = new UserRepositoryRoles();
result.setUser(user);
return result;
});
roles.setRoles(RepositoryRole.SYS_ADMIN.getRole());
userRepositoryRoleRepository.save(roles);
}
use of org.eclipse.vorto.repository.domain.UserRepositoryRoles in project vorto by eclipse.
the class RepositoryInitializer method createAdminUser.
private void createAdminUser(String username, long id) {
if (userRepository.findByUsername(username) == null) {
logger.info("Creating admin user: {}", username);
User user = null;
try {
user = new UserBuilder().withName(username).build();
} catch (InvalidUserException iue) {
logger.warn("Unable to create admin user - skipping.");
return;
}
// TODO : set to be configurable from configuration file
user.setEmailAddress("vorto-dev@bosch-si.com");
user.setAuthenticationProviderId("GITHUB");
user.setTechnicalUser(false);
userRepository.save(user);
}
User user = userRepository.findByUsername(username);
UserRepositoryRoles roles = userRepositoryRoleRepository.findByUser(user.getId()).orElse(new UserRepositoryRoles());
if (roles.getUser() == null) {
roles.setUser(user);
}
if (roles.getId() == null) {
roles.setId(id);
}
roles.setRoles(RepositoryRole.SYS_ADMIN.getRole());
userRepositoryRoleRepository.save(roles);
}
Aggregations