Task: Add CUBETIQ Fusion project with spring boot and vaadin fusion and updated the functions and classes

This commit is contained in:
Sambo Chea 2021-07-25 18:52:57 +07:00
parent 39035606c5
commit 64a6023b77
8 changed files with 30 additions and 40 deletions

View File

@ -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<User> getAuthenticatedUser() {
return authenticatedUser.get();

View File

@ -13,7 +13,6 @@ import javax.persistence.Lob;
@Entity
public class User extends AbstractEntity {
@Nonnull
private String username;
@Nonnull

View File

@ -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");

View File

@ -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, Integer> {
User findByUsername(String username);
}

View File

@ -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<User, Integer> {
private UserRepository repository;
private final UserRepository repository;
public UserService(@Autowired UserRepository repository) {
this.repository = repository;

View File

@ -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();

View File

@ -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<GrantedAuthority> getAuthorities(User user) {
return user.getRoles().stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName()))
.collect(Collectors.toList());
}
}

View File

@ -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