Commit 666aaaeb authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'initial-admin-on-startup' into 'master'

Initial admin on startup

See merge request !121
parents 5bbb5449 4e1a9070
......@@ -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
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.catalog.server.config;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
/**
* Scheduler config.
*/
@EnableAsync
@EnableScheduling
@Configuration
public class SchedulerConfig {
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskExecutor taskExecutor() {
final ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setCorePoolSize(4);
pool.setMaxPoolSize(8);
pool.setQueueCapacity(10);
pool.setThreadNamePrefix("genesys-background-");
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return pool;
}
}
......@@ -23,6 +23,7 @@ import org.genesys.blocks.model.EntityId;
import org.genesys.catalog.server.config.ApplicationConfig;
import org.genesys.catalog.server.config.CacheConfig;
import org.genesys.catalog.server.config.DatabaseConfig;
import org.genesys.catalog.server.config.SchedulerConfig;
import org.genesys.catalog.server.config.SecurityConfig;
import org.genesys.catalog.server.config.SpringAclConfig;
import org.junit.runner.RunWith;
......@@ -47,7 +48,7 @@ import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@EnableAspectJAutoProxy
@ContextConfiguration(name = "root", classes = { DatabaseConfig.class, ApplicationConfig.class, SpringAclConfig.class,
SecurityConfig.class, CacheConfig.class })
SecurityConfig.class, SchedulerConfig.class, CacheConfig.class })
public abstract class BaseTest {
protected final Logger LOG = LoggerFactory.getLogger(getClass());
......
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