From 64a6023b77894621415097a014ec4d540ba3cc24 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Sun, 25 Jul 2021 18:52:57 +0700 Subject: [PATCH] Task: Add CUBETIQ Fusion project with spring boot and vaadin fusion and updated the functions and classes --- .../fusion/data/endpoint/UserEndpoint.java | 5 ++++- .../com/cubetiqs/fusion/data/entity/User.java | 1 - .../fusion/data/generator/DataGenerator.java | 18 ++++++------------ .../fusion/data/service/UserRepository.java | 9 --------- .../fusion/data/service/UserService.java | 11 +---------- .../fusion/security/AuthenticatedUser.java | 5 ++++- .../security/UserDetailsServiceImpl.java | 6 ++++-- ...{application.properties => application.yml} | 15 +++++++++++---- 8 files changed, 30 insertions(+), 40 deletions(-) rename src/main/resources/{application.properties => application.yml} (50%) diff --git a/src/main/java/com/cubetiqs/fusion/data/endpoint/UserEndpoint.java b/src/main/java/com/cubetiqs/fusion/data/endpoint/UserEndpoint.java index ecef5f4..b02b23d 100644 --- a/src/main/java/com/cubetiqs/fusion/data/endpoint/UserEndpoint.java +++ b/src/main/java/com/cubetiqs/fusion/data/endpoint/UserEndpoint.java @@ -12,9 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired; @Endpoint @AnonymousAllowed public class UserEndpoint { + private final AuthenticatedUser authenticatedUser; @Autowired - private AuthenticatedUser authenticatedUser; + public UserEndpoint(AuthenticatedUser authenticatedUser) { + this.authenticatedUser = authenticatedUser; + } public Optional getAuthenticatedUser() { return authenticatedUser.get(); diff --git a/src/main/java/com/cubetiqs/fusion/data/entity/User.java b/src/main/java/com/cubetiqs/fusion/data/entity/User.java index f8461c3..19f949f 100644 --- a/src/main/java/com/cubetiqs/fusion/data/entity/User.java +++ b/src/main/java/com/cubetiqs/fusion/data/entity/User.java @@ -13,7 +13,6 @@ import javax.persistence.Lob; @Entity public class User extends AbstractEntity { - @Nonnull private String username; @Nonnull diff --git a/src/main/java/com/cubetiqs/fusion/data/generator/DataGenerator.java b/src/main/java/com/cubetiqs/fusion/data/generator/DataGenerator.java index 764c535..9b2c60b 100644 --- a/src/main/java/com/cubetiqs/fusion/data/generator/DataGenerator.java +++ b/src/main/java/com/cubetiqs/fusion/data/generator/DataGenerator.java @@ -1,21 +1,16 @@ package com.cubetiqs.fusion.data.generator; -import com.vaadin.flow.spring.annotation.SpringComponent; - -import com.cubetiqs.fusion.data.service.UserRepository; -import com.cubetiqs.fusion.data.entity.User; -import java.util.Collections; -import org.springframework.security.crypto.password.PasswordEncoder; import com.cubetiqs.fusion.data.Role; - -import java.time.LocalDateTime; - +import com.cubetiqs.fusion.data.entity.User; +import com.cubetiqs.fusion.data.service.UserRepository; +import com.vaadin.flow.spring.annotation.SpringComponent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.context.annotation.Bean; -import org.vaadin.artur.exampledata.DataType; -import org.vaadin.artur.exampledata.ExampleDataGenerator; +import org.springframework.security.crypto.password.PasswordEncoder; + +import java.util.Collections; @SpringComponent public class DataGenerator { @@ -28,7 +23,6 @@ public class DataGenerator { logger.info("Using existing database"); return; } - int seed = 123; logger.info("Generating demo data"); diff --git a/src/main/java/com/cubetiqs/fusion/data/service/UserRepository.java b/src/main/java/com/cubetiqs/fusion/data/service/UserRepository.java index 32cb7fd..7125106 100644 --- a/src/main/java/com/cubetiqs/fusion/data/service/UserRepository.java +++ b/src/main/java/com/cubetiqs/fusion/data/service/UserRepository.java @@ -1,17 +1,8 @@ package com.cubetiqs.fusion.data.service; import com.cubetiqs.fusion.data.entity.User; - import org.springframework.data.jpa.repository.JpaRepository; -import com.vaadin.fusion.Nonnull; -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.Set; -import javax.persistence.ElementCollection; -import javax.persistence.FetchType; -import com.cubetiqs.fusion.data.Role; -import javax.persistence.Lob; public interface UserRepository extends JpaRepository { - User findByUsername(String username); } \ No newline at end of file diff --git a/src/main/java/com/cubetiqs/fusion/data/service/UserService.java b/src/main/java/com/cubetiqs/fusion/data/service/UserService.java index cabb4e2..129ede8 100644 --- a/src/main/java/com/cubetiqs/fusion/data/service/UserService.java +++ b/src/main/java/com/cubetiqs/fusion/data/service/UserService.java @@ -1,22 +1,13 @@ package com.cubetiqs.fusion.data.service; import com.cubetiqs.fusion.data.entity.User; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.vaadin.artur.helpers.CrudService; -import com.vaadin.fusion.Nonnull; -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.Set; -import javax.persistence.ElementCollection; -import javax.persistence.FetchType; -import com.cubetiqs.fusion.data.Role; -import javax.persistence.Lob; @Service public class UserService extends CrudService { - - private UserRepository repository; + private final UserRepository repository; public UserService(@Autowired UserRepository repository) { this.repository = repository; diff --git a/src/main/java/com/cubetiqs/fusion/security/AuthenticatedUser.java b/src/main/java/com/cubetiqs/fusion/security/AuthenticatedUser.java index d940bf2..a31d27e 100644 --- a/src/main/java/com/cubetiqs/fusion/security/AuthenticatedUser.java +++ b/src/main/java/com/cubetiqs/fusion/security/AuthenticatedUser.java @@ -16,9 +16,12 @@ import org.springframework.stereotype.Component; @Component public class AuthenticatedUser { + private final UserRepository userRepository; @Autowired - private UserRepository userRepository; + public AuthenticatedUser(UserRepository userRepository) { + this.userRepository = userRepository; + } private UserDetails getAuthenticatedUser() { SecurityContext context = SecurityContextHolder.getContext(); diff --git a/src/main/java/com/cubetiqs/fusion/security/UserDetailsServiceImpl.java b/src/main/java/com/cubetiqs/fusion/security/UserDetailsServiceImpl.java index 0f5534e..7d0bc18 100644 --- a/src/main/java/com/cubetiqs/fusion/security/UserDetailsServiceImpl.java +++ b/src/main/java/com/cubetiqs/fusion/security/UserDetailsServiceImpl.java @@ -16,9 +16,12 @@ import org.springframework.stereotype.Service; @Service public class UserDetailsServiceImpl implements UserDetailsService { + private final UserRepository userRepository; @Autowired - private UserRepository userRepository; + public UserDetailsServiceImpl(UserRepository userRepository) { + this.userRepository = userRepository; + } @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { @@ -34,7 +37,6 @@ public class UserDetailsServiceImpl implements UserDetailsService { private static List getAuthorities(User user) { return user.getRoles().stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName())) .collect(Collectors.toList()); - } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml similarity index 50% rename from src/main/resources/application.properties rename to src/main/resources/application.yml index d579d9e..f1a65e2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.yml @@ -1,7 +1,14 @@ -server.port=${PORT:8080} -logging.level.org.atmosphere = warn -spring.mustache.check-template-location = false +server: + port: ${PORT:8080} + +logging: + level: + org.atmosphere: warn + +spring: + mustache: + check-template-location: false # To improve the performance during development. # For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters -# vaadin.whitelisted-packages= org/vaadin/example +# vaadin.whitelisted-packages= org/vaadin/example \ No newline at end of file