Commit 890707d6 authored by Matija Obreza's avatar Matija Obreza
Browse files

Creating initial admin on start updated

parent 5bbb5449
......@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -42,7 +43,7 @@ import com.google.common.collect.Sets;
/**
* The Class UserServiceImpl.
*/
@Service(value = "userService")
@Service
@Transactional(readOnly = true)
public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implements UserService {
private static final Logger LOG = LoggerFactory.getLogger(UserServiceImpl.class);
......@@ -52,6 +53,11 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
protected static final List<UserRole> availableRoles = Collections.unmodifiableList(Lists.newArrayList(UserRole.values()));
@Override
protected JpaRepository<User, Long> getUserRepository() {
return userRepository;
}
@Override
public UserRole getDefaultUserRole() {
return UserRole.USER;
......
......@@ -109,11 +109,14 @@ public class StartupInitializer implements InitializingBean {
public void ensure1Admin() throws NotUniqueUserException, PasswordPolicyException, UserException {
LOG.info("Startup initializer checking stuff");
if (userRepository.count() == 0) {
// The other user is SYSTEM_ADMIN!
if (userRepository.count() <= 1) {
final User admin = userService.createUser(defaultAdminEmail, "Administrator", defaultAdminPassword, BasicUser.AccountType.LOCAL);
userService.setRoles(admin, Sets.newHashSet(UserRole.ADMINISTRATOR));
LOG.warn("Default admin email={} password={}", defaultAdminEmail, defaultAdminPassword);
LOG.warn("Default admin email={} password={}", admin.getEmail(), defaultAdminPassword);
}
LOG.info("Startup initializer done.");
}
}
......@@ -60,7 +60,6 @@ public class OAuth2ServerConfig {
private int refreshTokenValiditySeconds;
@Autowired
@Qualifier("userService")
private UserDetailsService userDetailsService;
@Bean
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment