Search in sources :

Example 1 with UserRepositoryRoles

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);
}
Also used : UserRepositoryRoles(org.eclipse.vorto.repository.domain.UserRepositoryRoles)

Example 2 with UserRepositoryRoles

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);
}
Also used : User(org.eclipse.vorto.repository.domain.User) UserRepositoryRoles(org.eclipse.vorto.repository.domain.UserRepositoryRoles) InvalidUserException(org.eclipse.vorto.repository.services.exceptions.InvalidUserException) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder)

Aggregations

UserRepositoryRoles (org.eclipse.vorto.repository.domain.UserRepositoryRoles)2 User (org.eclipse.vorto.repository.domain.User)1 UserBuilder (org.eclipse.vorto.repository.services.UserBuilder)1 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)1