From 906b85539c2777fe9800b36245dad836fcfa8e87 Mon Sep 17 00:00:00 2001 From: ddangelorb Date: Fri, 13 Aug 2021 16:26:04 -0300 Subject: [PATCH] Fixing app run --- .../wpdauth/WpdauthApplication.java | 45 ++++++++++++++++++- src/main/resources/application.properties | 21 +++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/waterproofingdata/wpdauth/WpdauthApplication.java b/src/main/java/org/waterproofingdata/wpdauth/WpdauthApplication.java index 0a5b059..1888da1 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/WpdauthApplication.java +++ b/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(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(Arrays.asList(Roles.ROLE_CLIENT))); + + userService.signup(client); + } + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..e495489 100644 --- a/src/main/resources/application.properties +++ b/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= + +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.