Browse Source

Fixing app run

main
ddangelorb 3 years ago
parent
commit
906b85539c
  1. 45
      src/main/java/org/waterproofingdata/wpdauth/WpdauthApplication.java
  2. 21
      src/main/resources/application.properties

45
src/main/java/org/waterproofingdata/wpdauth/WpdauthApplication.java

@ -1,13 +1,56 @@
package org.waterproofingdata.wpdauth;
import java.util.ArrayList;
import java.util.Arrays;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.waterproofingdata.wpdauth.model.Roles;
import org.waterproofingdata.wpdauth.model.Users;
import org.waterproofingdata.wpdauth.service.UsersService;
@SpringBootApplication
public class WpdauthApplication {
public class WpdauthApplication implements CommandLineRunner {
@Autowired
UsersService userService;
public static void main(String[] args) {
SpringApplication.run(WpdauthApplication.class, args);
}
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
@Override
public void run(String... params) throws Exception {
if (!userService.existsByUsername("admin")) {
Users admin = new Users();
admin.setUsername("admin");
admin.setPassword("admin");
admin.setEmail("admin@email.com");
admin.setActive(1);
admin.setRoles(new ArrayList<Roles>(Arrays.asList(Roles.ROLE_ADMIN)));
userService.signup(admin);
}
if (!userService.existsByUsername("client")) {
Users client = new Users();
client.setUsername("client");
client.setPassword("client");
client.setEmail("client@email.com");
client.setActive(1);
client.setRoles(new ArrayList<Roles>(Arrays.asList(Roles.ROLE_CLIENT)));
userService.signup(client);
}
}
}

21
src/main/resources/application.properties

@ -1 +1,22 @@
## default connection pool
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
## PostgreSQL
spring.datasource.url=jdbc:postgresql://localhost:5432/wpdauth
spring.datasource.username=uwpdauth
spring.datasource.password=<password>
spring.jpa.hibernate.ddl-auto=none
server.port=8080
security.jwt.token.secret-key=secret-key
##5 minutes duration by default: 5 minutes * 60 seconds * 1000 miliseconds
security.jwt.token.expire-length=300000
UsersController.signin=Authenticates user and returns its JWT token.
UsersController.signup=Creates user and returns its JWT token.
UsersController.delete=Deletes specific user by username.
UsersController.search=Returns specific user by username.
UsersController.me=Returns current user's data.
Loading…
Cancel
Save