├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── src ├── test │ └── java │ │ └── com │ │ └── brightcoding │ │ └── app │ │ └── ws │ │ └── ApplicationTests.java └── main │ ├── java │ └── com │ │ └── brightcoding │ │ └── app │ │ └── ws │ │ ├── exceptions │ │ ├── UserException.java │ │ └── AppExceptionHandler.java │ │ ├── services │ │ ├── AddressService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── AddressServiceImpl.java │ │ │ └── UserSeviceImpl.java │ │ ├── security │ │ ├── SecurityConstants.java │ │ ├── WebSecurity.java │ │ ├── AuthorizationFilter.java │ │ └── AuthenticationFilter.java │ │ ├── requests │ │ ├── ContactRequest.java │ │ ├── UserLoginRequest.java │ │ ├── AddressRequest.java │ │ └── UserRequest.java │ │ ├── WebConfig.java │ │ ├── repositories │ │ ├── AddressRepository.java │ │ └── UserRepository.java │ │ ├── responses │ │ ├── ContactResponse.java │ │ ├── ErrorMessage.java │ │ ├── ErrorMessages.java │ │ ├── AddressResponse.java │ │ └── UserResponse.java │ │ ├── SpringApplicationContext.java │ │ ├── shared │ │ ├── Utils.java │ │ └── dto │ │ │ ├── ContactDto.java │ │ │ ├── AddressDto.java │ │ │ └── UserDto.java │ │ ├── entities │ │ ├── GroupEntity.java │ │ ├── ContactEntity.java │ │ ├── AddressEntity.java │ │ └── UserEntity.java │ │ ├── Application.java │ │ └── controllers │ │ ├── AddressController.java │ │ └── UserController.java │ └── resources │ └── application.properties ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDBRAHIMDEV/spring-boot-v1/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /src/test/java/com/brightcoding/app/ws/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/exceptions/UserException.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.exceptions; 2 | 3 | public class UserException extends RuntimeException { 4 | 5 | 6 | private static final long serialVersionUID = 847500838613349753L; 7 | 8 | public UserException(String message) 9 | { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password= 3 | spring.datasource.url=jdbc:mysql://localhost:3306/my_app_db 4 | spring.jpa.hibernate.ddl-auto=update 5 | 6 | 7 | 8 | logging.level.org.hibernate.SQL=DEBUG 9 | logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 10 | spring.jpa.properties.hibernate.format_sql=true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/services/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.services; 2 | 3 | import java.util.List; 4 | 5 | import com.brightcoding.app.ws.shared.dto.AddressDto; 6 | 7 | public interface AddressService { 8 | 9 | List getAllAddresses(String email); 10 | 11 | AddressDto createAddress(AddressDto address, String email); 12 | 13 | AddressDto getAddress(String addressId); 14 | 15 | void deleteAddress(String addressId); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/security/SecurityConstants.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.security; 2 | 3 | public class SecurityConstants { 4 | 5 | public static final long EXPIRATION_TIME = 864000000; // 10 Days 6 | public static final String TOKEN_PREFIX = "Bearer "; 7 | public static final String HEADER_STRING = "Authorization"; 8 | public static final String SIGN_UP_URL = "/users"; 9 | public static final String TOKEN_SECRET = "dfg893hdc475zwerop4tghg4ddfdfgdsdfeqaas?=-0ljznm0-9"; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/requests/ContactRequest.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.requests; 2 | 3 | public class ContactRequest { 4 | 5 | private String mobile; 6 | private String skype; 7 | 8 | public String getMobile() { 9 | return mobile; 10 | } 11 | public void setMobile(String mobile) { 12 | this.mobile = mobile; 13 | } 14 | public String getSkype() { 15 | return skype; 16 | } 17 | public void setSkype(String skype) { 18 | this.skype = skype; 19 | } 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/requests/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.requests; 2 | 3 | public class UserLoginRequest { 4 | 5 | private String email; 6 | 7 | private String password; 8 | 9 | public String getEmail() { 10 | return email; 11 | } 12 | 13 | public void setEmail(String email) { 14 | this.email = email; 15 | } 16 | 17 | public String getPassword() { 18 | return password; 19 | } 20 | 21 | public void setPassword(String password) { 22 | this.password = password; 23 | } 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | @Configuration 8 | public class WebConfig implements WebMvcConfigurer { 9 | 10 | public void addCorsMappings(CorsRegistry registry) { 11 | 12 | registry 13 | .addMapping("/**") 14 | .allowedMethods("*") 15 | .allowedOrigins("*"); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/repositories/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.repositories; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.brightcoding.app.ws.entities.AddressEntity; 9 | import com.brightcoding.app.ws.entities.UserEntity; 10 | 11 | @Repository 12 | public interface AddressRepository extends CrudRepository { 13 | 14 | List findByUser(UserEntity currentUser); 15 | 16 | AddressEntity findByAddressId(String addressId); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/services/UserService.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.services; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | 7 | import com.brightcoding.app.ws.shared.dto.UserDto; 8 | 9 | public interface UserService extends UserDetailsService { 10 | 11 | UserDto createUser(UserDto user); 12 | 13 | UserDto getUser(String email); 14 | 15 | UserDto getUserByUserId(String userId); 16 | 17 | UserDto updateUser(String id, UserDto userDto); 18 | 19 | void deleteUser(String userId); 20 | 21 | List getUsers(int page, int limit, String search, int status); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/responses/ContactResponse.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.responses; 2 | 3 | public class ContactResponse { 4 | 5 | private String contactId; 6 | private String mobile; 7 | private String skype; 8 | 9 | public String getContactId() { 10 | return contactId; 11 | } 12 | public void setContactId(String contactId) { 13 | this.contactId = contactId; 14 | } 15 | public String getMobile() { 16 | return mobile; 17 | } 18 | public void setMobile(String mobile) { 19 | this.mobile = mobile; 20 | } 21 | public String getSkype() { 22 | return skype; 23 | } 24 | public void setSkype(String skype) { 25 | this.skype = skype; 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/responses/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.responses; 2 | 3 | import java.util.Date; 4 | 5 | public class ErrorMessage { 6 | 7 | private Date timestamp; 8 | private String message; 9 | 10 | public ErrorMessage(Date timestamp, String message) { 11 | super(); 12 | this.timestamp = timestamp; 13 | this.message = message; 14 | } 15 | 16 | public Date getTimestamp() { 17 | return timestamp; 18 | } 19 | 20 | public void setTimestamp(Date timestamp) { 21 | this.timestamp = timestamp; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public void setMessage(String message) { 29 | this.message = message; 30 | } 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/SpringApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | public class SpringApplicationContext implements ApplicationContextAware { 8 | 9 | private static ApplicationContext CONTEXT; 10 | 11 | @Override 12 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 13 | // TODO Auto-generated method stub 14 | CONTEXT = applicationContext; 15 | } 16 | 17 | public static Object getBean(String beanName) { 18 | return CONTEXT.getBean(beanName); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/responses/ErrorMessages.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.responses; 2 | 3 | public enum ErrorMessages { 4 | 5 | MISSING_REQUIRED_FIELD("Missing required field."), 6 | RECORD_ALREADY_EXISTS("Record already exists."), 7 | INTERNAL_SERVER_ERROR("Internal Bright coding server error."), 8 | NO_RECORD_FOUND("Record with provided id is not found."); 9 | 10 | private String errorMessage; 11 | 12 | private ErrorMessages(String errorMessage) { 13 | this.errorMessage = errorMessage; 14 | } 15 | 16 | public String getErrorMessage() { 17 | return errorMessage; 18 | } 19 | 20 | public void setErrorMessage(String errorMessage) { 21 | this.errorMessage = errorMessage; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/shared/Utils.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.shared; 2 | 3 | import java.security.SecureRandom; 4 | import java.util.Random; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class Utils { 10 | 11 | private final Random RANDOM = new SecureRandom(); 12 | private final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 13 | 14 | 15 | public String generateStringId(int length) { 16 | StringBuilder returnValue = new StringBuilder(length); 17 | 18 | for (int i = 0; i < length; i++) { 19 | returnValue.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length()))); 20 | } 21 | 22 | return new String(returnValue); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/shared/dto/ContactDto.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.shared.dto; 2 | 3 | public class ContactDto { 4 | 5 | private long id; 6 | private String contactId; 7 | private String mobile; 8 | private String skype; 9 | private UserDto user; 10 | 11 | public long getId() { 12 | return id; 13 | } 14 | public void setId(long id) { 15 | this.id = id; 16 | } 17 | public String getContactId() { 18 | return contactId; 19 | } 20 | public void setContactId(String contactId) { 21 | this.contactId = contactId; 22 | } 23 | public String getMobile() { 24 | return mobile; 25 | } 26 | public void setMobile(String mobile) { 27 | this.mobile = mobile; 28 | } 29 | public String getSkype() { 30 | return skype; 31 | } 32 | public void setSkype(String skype) { 33 | this.skype = skype; 34 | } 35 | public UserDto getUser() { 36 | return user; 37 | } 38 | public void setUser(UserDto user) { 39 | this.user = user; 40 | } 41 | 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/requests/AddressRequest.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.requests; 2 | 3 | public class AddressRequest { 4 | 5 | private String city; 6 | private String country; 7 | private String street; 8 | private String postal; 9 | private String type; 10 | 11 | public String getCity() { 12 | return city; 13 | } 14 | public void setCity(String city) { 15 | this.city = city; 16 | } 17 | public String getCountry() { 18 | return country; 19 | } 20 | public void setCountry(String country) { 21 | this.country = country; 22 | } 23 | public String getStreet() { 24 | return street; 25 | } 26 | public void setStreet(String street) { 27 | this.street = street; 28 | } 29 | public String getPostal() { 30 | return postal; 31 | } 32 | public void setPostal(String postal) { 33 | this.postal = postal; 34 | } 35 | public String getType() { 36 | return type; 37 | } 38 | public void setType(String type) { 39 | this.type = type; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/entities/GroupEntity.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.entities; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import javax.persistence.CascadeType; 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.FetchType; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.JoinColumn; 14 | import javax.persistence.JoinTable; 15 | import javax.persistence.ManyToMany; 16 | 17 | @Entity(name="groups") 18 | public class GroupEntity implements Serializable { 19 | 20 | private static final long serialVersionUID = -691475206953815499L; 21 | 22 | @Id 23 | @GeneratedValue 24 | private long id; 25 | 26 | @Column(name="name", length=30) 27 | private String name; 28 | 29 | @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 30 | @JoinTable(name="groups_users", joinColumns = {@JoinColumn(name="groups_id")}, inverseJoinColumns = {@JoinColumn(name="users_id")}) 31 | private Set users = new HashSet<>(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/Application.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 9 | 10 | @SpringBootApplication 11 | public class Application extends SpringBootServletInitializer { 12 | 13 | 14 | @Override 15 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 16 | return application.sources(Application.class); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(Application.class, args); 21 | } 22 | 23 | @Bean 24 | public BCryptPasswordEncoder bCryptPasswordEncoder() { 25 | return new BCryptPasswordEncoder(); 26 | } 27 | 28 | @Bean 29 | public SpringApplicationContext springApplicationContext() { 30 | return new SpringApplicationContext(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/responses/AddressResponse.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.responses; 2 | 3 | public class AddressResponse { 4 | 5 | private String addressId; 6 | private String city; 7 | private String country; 8 | private String street; 9 | private String postal; 10 | private String type; 11 | 12 | public String getAddressId() { 13 | return addressId; 14 | } 15 | 16 | public void setAddressId(String addressId) { 17 | this.addressId = addressId; 18 | } 19 | 20 | public String getCity() { 21 | return city; 22 | } 23 | 24 | public void setCity(String city) { 25 | this.city = city; 26 | } 27 | 28 | public String getCountry() { 29 | return country; 30 | } 31 | 32 | public void setCountry(String country) { 33 | this.country = country; 34 | } 35 | 36 | public String getStreet() { 37 | return street; 38 | } 39 | 40 | public void setStreet(String street) { 41 | this.street = street; 42 | } 43 | 44 | public String getPostal() { 45 | return postal; 46 | } 47 | 48 | public void setPostal(String postal) { 49 | this.postal = postal; 50 | } 51 | 52 | public String getType() { 53 | return type; 54 | } 55 | 56 | public void setType(String type) { 57 | this.type = type; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/shared/dto/AddressDto.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.shared.dto; 2 | 3 | public class AddressDto { 4 | 5 | private long id; 6 | private String addressId; 7 | private String city; 8 | private String country; 9 | private String street; 10 | private String postal; 11 | private String type; 12 | private UserDto user; 13 | 14 | public long getId() { 15 | return id; 16 | } 17 | public void setId(long id) { 18 | this.id = id; 19 | } 20 | public String getCity() { 21 | return city; 22 | } 23 | public void setCity(String city) { 24 | this.city = city; 25 | } 26 | public String getCountry() { 27 | return country; 28 | } 29 | public void setCountry(String country) { 30 | this.country = country; 31 | } 32 | public String getStreet() { 33 | return street; 34 | } 35 | public void setStreet(String street) { 36 | this.street = street; 37 | } 38 | public String getPostal() { 39 | return postal; 40 | } 41 | public void setPostal(String postal) { 42 | this.postal = postal; 43 | } 44 | public String getType() { 45 | return type; 46 | } 47 | public void setType(String type) { 48 | this.type = type; 49 | } 50 | public UserDto getUser() { 51 | return user; 52 | } 53 | public void setUser(UserDto user) { 54 | this.user = user; 55 | } 56 | public String getAddressId() { 57 | return addressId; 58 | } 59 | public void setAddressId(String addressId) { 60 | this.addressId = addressId; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/responses/UserResponse.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.responses; 2 | 3 | import java.util.List; 4 | 5 | public class UserResponse { 6 | 7 | private String userId; 8 | private String firstName; 9 | private String lastName; 10 | private String email; 11 | private Boolean admin; 12 | private List addresses; 13 | private ContactResponse contact; 14 | 15 | 16 | public String getUserId() { 17 | return userId; 18 | } 19 | 20 | public void setUserId(String userId) { 21 | this.userId = userId; 22 | } 23 | 24 | public String getFirstName() { 25 | return firstName; 26 | } 27 | 28 | public void setFirstName(String firstName) { 29 | this.firstName = firstName; 30 | } 31 | 32 | public String getLastName() { 33 | return lastName; 34 | } 35 | 36 | public void setLastName(String lastName) { 37 | this.lastName = lastName; 38 | } 39 | 40 | public String getEmail() { 41 | return email; 42 | } 43 | 44 | public void setEmail(String email) { 45 | this.email = email; 46 | } 47 | 48 | public List getAddresses() { 49 | return addresses; 50 | } 51 | 52 | public void setAddresses(List addresses) { 53 | this.addresses = addresses; 54 | } 55 | 56 | public ContactResponse getContact() { 57 | return contact; 58 | } 59 | 60 | public void setContact(ContactResponse contact) { 61 | this.contact = contact; 62 | } 63 | 64 | public Boolean getAdmin() { 65 | return admin; 66 | } 67 | 68 | public void setAdmin(Boolean admin) { 69 | this.admin = admin; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/entities/ContactEntity.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.JoinColumn; 10 | import javax.persistence.OneToOne; 11 | import javax.validation.constraints.NotBlank; 12 | 13 | @Entity(name="contacts") 14 | public class ContactEntity implements Serializable { 15 | 16 | private static final long serialVersionUID = 5726502969573108819L; 17 | 18 | @Id 19 | @GeneratedValue 20 | private long id; 21 | 22 | @NotBlank 23 | @Column(length = 30) 24 | private String contactId; 25 | 26 | @NotBlank 27 | private String mobile; 28 | private String skype; 29 | 30 | @OneToOne 31 | @JoinColumn(name="users_id") 32 | private UserEntity user; 33 | 34 | public long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getContactId() { 43 | return contactId; 44 | } 45 | 46 | public void setContactId(String contactId) { 47 | this.contactId = contactId; 48 | } 49 | 50 | public String getMobile() { 51 | return mobile; 52 | } 53 | 54 | public void setMobile(String mobile) { 55 | this.mobile = mobile; 56 | } 57 | 58 | public String getSkype() { 59 | return skype; 60 | } 61 | 62 | public void setSkype(String skype) { 63 | this.skype = skype; 64 | } 65 | 66 | public UserEntity getUser() { 67 | return user; 68 | } 69 | 70 | public void setUser(UserEntity user) { 71 | this.user = user; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.repositories; 2 | 3 | 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.PagingAndSortingRepository; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.brightcoding.app.ws.entities.UserEntity; 12 | 13 | @Repository 14 | public interface UserRepository extends PagingAndSortingRepository { 15 | 16 | UserEntity findByEmail(String email); 17 | 18 | UserEntity findByUserId(String userId); 19 | 20 | // @Query(value="SELECT * FROM users", nativeQuery=true) 21 | // Page findAllUsers(Pageable pageableRequest); 22 | 23 | @Query("SELECT user FROM UserEntity user") 24 | Page findAllUsers(Pageable pageableRequest); 25 | 26 | // @Query(value="SELECT * FROM users u WHERE (u.first_name = ?1 OR u.last_name = ?1) AND u.email_verification_status = ?2", nativeQuery=true) 27 | // Page findAllUserByCriteria(Pageable pageableRequest, String search, int status); 28 | 29 | // @Query(value="SELECT * FROM users u WHERE (u.first_name = :search OR u.last_name = :search) AND u.email_verification_status = :status", nativeQuery=true) 30 | // Page findAllUserByCriteria(Pageable pageableRequest, @Param("search") String search, @Param("status") int status); 31 | 32 | @Query(value="SELECT * FROM users u WHERE (u.first_name LIKE %:search% OR u.last_name LIKE %:search%) AND u.email_verification_status = :status", nativeQuery=true) 33 | Page findAllUserByCriteria(Pageable pageableRequest, @Param("search") String search, @Param("status") int status); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/exceptions/AppExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.exceptions; 2 | 3 | import java.util.Date; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.springframework.http.HttpHeaders; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.MethodArgumentNotValidException; 11 | import org.springframework.web.bind.annotation.ControllerAdvice; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.context.request.WebRequest; 14 | 15 | import com.brightcoding.app.ws.responses.ErrorMessage; 16 | 17 | @ControllerAdvice 18 | public class AppExceptionHandler { 19 | 20 | @ExceptionHandler(value={UserException.class}) 21 | public ResponseEntity HandleUserException(UserException ex, WebRequest request) 22 | { 23 | ErrorMessage errorMessage = new ErrorMessage(new Date(), ex.getMessage()); 24 | 25 | return new ResponseEntity<>(errorMessage, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); 26 | } 27 | 28 | @ExceptionHandler(value=Exception.class) 29 | public ResponseEntity HandleOtherExceptions(Exception ex, WebRequest request) 30 | { 31 | ErrorMessage errorMessage = new ErrorMessage(new Date(), ex.getMessage()); 32 | 33 | return new ResponseEntity<>(errorMessage, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); 34 | } 35 | 36 | @ExceptionHandler(value=MethodArgumentNotValidException.class) 37 | public ResponseEntity HandleMethodArgumentNotValid(MethodArgumentNotValidException ex, WebRequest request) 38 | { 39 | Map errors = new HashMap<>(); 40 | 41 | ex.getBindingResult().getFieldErrors().forEach(error -> 42 | errors.put(error.getField(), error.getDefaultMessage())); 43 | 44 | return new ResponseEntity<>(errors, new HttpHeaders(), HttpStatus.BAD_REQUEST); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/security/WebSecurity.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.security; 2 | 3 | import org.springframework.http.HttpMethod; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.config.http.SessionCreationPolicy; 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 | 11 | import com.brightcoding.app.ws.services.UserService; 12 | 13 | @EnableWebSecurity 14 | public class WebSecurity extends WebSecurityConfigurerAdapter { 15 | 16 | private final UserService userDetailsService; 17 | private final BCryptPasswordEncoder bCryptPasswordEncoder; 18 | 19 | public WebSecurity(UserService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) { 20 | this.userDetailsService = userDetailsService; 21 | this.bCryptPasswordEncoder = bCryptPasswordEncoder; 22 | } 23 | 24 | @Override 25 | protected void configure(HttpSecurity http) throws Exception { 26 | 27 | 28 | http 29 | .cors().and() 30 | .csrf().disable() 31 | .authorizeRequests() 32 | .antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL) 33 | .permitAll() 34 | .anyRequest().authenticated() 35 | .and() 36 | .addFilter(getAuthenticationFilter()) 37 | .addFilter(new AuthorizationFilter(authenticationManager())) 38 | .sessionManagement() 39 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS); 40 | } 41 | 42 | 43 | 44 | protected AuthenticationFilter getAuthenticationFilter() throws Exception { 45 | final AuthenticationFilter filter = new AuthenticationFilter(authenticationManager()); 46 | filter.setFilterProcessesUrl("/users/login"); 47 | return filter; 48 | } 49 | 50 | 51 | @Override 52 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 53 | auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/entities/AddressEntity.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.JoinColumn; 10 | import javax.persistence.ManyToOne; 11 | 12 | @Entity(name="addresses") 13 | public class AddressEntity implements Serializable { 14 | 15 | private static final long serialVersionUID = 8106560824187969451L; 16 | 17 | @Id 18 | @GeneratedValue 19 | private long id; 20 | 21 | @Column(length=30, nullable=false) 22 | private String addressId; 23 | 24 | @Column(length=20, nullable=false) 25 | private String city; 26 | 27 | @Column(length=20, nullable=false) 28 | private String country; 29 | 30 | @Column(length=50, nullable=false) 31 | private String street; 32 | 33 | @Column(length=7, nullable=false) 34 | private String postal; 35 | 36 | @Column(length=20, nullable=false) 37 | private String type; 38 | 39 | @ManyToOne 40 | @JoinColumn(name="users_id") 41 | private UserEntity user; 42 | 43 | public long getId() { 44 | return id; 45 | } 46 | 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | public String getAddressId() { 52 | return addressId; 53 | } 54 | 55 | public void setAddressId(String addressId) { 56 | this.addressId = addressId; 57 | } 58 | 59 | public String getCity() { 60 | return city; 61 | } 62 | 63 | public void setCity(String city) { 64 | this.city = city; 65 | } 66 | 67 | public String getCountry() { 68 | return country; 69 | } 70 | 71 | public void setCountry(String country) { 72 | this.country = country; 73 | } 74 | 75 | public String getStreet() { 76 | return street; 77 | } 78 | 79 | public void setStreet(String street) { 80 | this.street = street; 81 | } 82 | 83 | public String getPostal() { 84 | return postal; 85 | } 86 | 87 | public void setPostal(String postal) { 88 | this.postal = postal; 89 | } 90 | 91 | public String getType() { 92 | return type; 93 | } 94 | 95 | public void setType(String type) { 96 | this.type = type; 97 | } 98 | 99 | public UserEntity getUser() { 100 | return user; 101 | } 102 | 103 | public void setUser(UserEntity user) { 104 | this.user = user; 105 | } 106 | 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/requests/UserRequest.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.requests; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.constraints.Email; 6 | import javax.validation.constraints.NotBlank; 7 | import javax.validation.constraints.NotNull; 8 | import javax.validation.constraints.Pattern; 9 | import javax.validation.constraints.Size; 10 | 11 | 12 | 13 | public class UserRequest { 14 | 15 | @NotBlank(message="Ce champ ne doit etre null !") 16 | private String firstName; 17 | 18 | @NotNull(message="Ce champ ne doit etre null !") 19 | @Size(min=3, message="Ce champ doit avoir au moins 3 Caracteres !") 20 | private String lastName; 21 | 22 | @NotNull(message="Ce champ ne doit etre null !") 23 | @Email(message="ce champ doit respecter le format email !") 24 | private String email; 25 | 26 | @NotNull(message="Ce champ ne doit etre null !") 27 | @Size(min=8, message="mot de passe doit avoir au moins 8 caracteres !") 28 | @Size(max=12, message="mot de passe doit avoir au max 12 caracteres !") 29 | @Pattern(regexp="(?=^.{8,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$", message="ce mot de passe doit avoir des lettres en Maj et Minsc et numero") 30 | private String password; 31 | 32 | private Boolean admin; 33 | 34 | private List addresses; 35 | 36 | private ContactRequest contact; 37 | 38 | 39 | public ContactRequest getContact() { 40 | return contact; 41 | } 42 | public void setContact(ContactRequest contact) { 43 | this.contact = contact; 44 | } 45 | public String getFirstName() { 46 | return firstName; 47 | } 48 | public void setFirstName(String firstName) { 49 | this.firstName = firstName; 50 | } 51 | public String getLastName() { 52 | return lastName; 53 | } 54 | public void setLastName(String lastName) { 55 | this.lastName = lastName; 56 | } 57 | public String getEmail() { 58 | return email; 59 | } 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | public String getPassword() { 64 | return password; 65 | } 66 | public void setPassword(String password) { 67 | this.password = password; 68 | } 69 | 70 | public List getAddresses() { 71 | return addresses; 72 | } 73 | public void setAddresses(List addresses) { 74 | this.addresses = addresses; 75 | } 76 | public Boolean getAdmin() { 77 | return admin; 78 | } 79 | public void setAdmin(Boolean admin) { 80 | this.admin = admin; 81 | } 82 | 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/security/AuthorizationFilter.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.security; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | import javax.servlet.FilterChain; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.springframework.security.authentication.AuthenticationManager; 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 13 | import org.springframework.security.core.context.SecurityContextHolder; 14 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; 15 | 16 | import io.jsonwebtoken.Jwts; 17 | 18 | public class AuthorizationFilter extends BasicAuthenticationFilter { 19 | 20 | public AuthorizationFilter(AuthenticationManager authManager) { 21 | super(authManager); 22 | } 23 | 24 | @Override 25 | protected void doFilterInternal(HttpServletRequest req, 26 | HttpServletResponse res, 27 | FilterChain chain) throws IOException, ServletException { 28 | 29 | String header = req.getHeader(SecurityConstants.HEADER_STRING); 30 | 31 | if (header == null || !header.startsWith(SecurityConstants.TOKEN_PREFIX)) { 32 | chain.doFilter(req, res); 33 | return; 34 | } 35 | 36 | UsernamePasswordAuthenticationToken authentication = getAuthentication(req); 37 | SecurityContextHolder.getContext().setAuthentication(authentication); 38 | chain.doFilter(req, res); 39 | } 40 | 41 | 42 | private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest request) { 43 | String token = request.getHeader(SecurityConstants.HEADER_STRING); 44 | 45 | if (token != null) { 46 | 47 | token = token.replace(SecurityConstants.TOKEN_PREFIX, ""); 48 | 49 | String user = Jwts.parser() 50 | .setSigningKey( SecurityConstants.TOKEN_SECRET ) 51 | .parseClaimsJws( token ) 52 | .getBody() 53 | .getSubject(); 54 | 55 | if (user != null) { 56 | return new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>()); 57 | } 58 | 59 | return null; 60 | } 61 | 62 | return null; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/shared/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.shared.dto; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class UserDto implements Serializable { 7 | 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = -2624881664878912922L; 12 | 13 | private long id; 14 | private String userId; 15 | private String firstName; 16 | private String lastName; 17 | private String email; 18 | private String password; 19 | private Boolean admin; 20 | private String encryptedPassword; 21 | private String emailVerificationToken; 22 | private Boolean emailVerificationStatus = false; 23 | private List addresses; 24 | private ContactDto contact; 25 | 26 | public long getId() { 27 | return id; 28 | } 29 | public void setId(long id) { 30 | this.id = id; 31 | } 32 | public String getUserId() { 33 | return userId; 34 | } 35 | public void setUserId(String userId) { 36 | this.userId = userId; 37 | } 38 | public String getFirstName() { 39 | return firstName; 40 | } 41 | public void setFirstName(String firstName) { 42 | this.firstName = firstName; 43 | } 44 | public String getLastName() { 45 | return lastName; 46 | } 47 | public void setLastName(String lastName) { 48 | this.lastName = lastName; 49 | } 50 | public String getEmail() { 51 | return email; 52 | } 53 | public void setEmail(String email) { 54 | this.email = email; 55 | } 56 | public String getPassword() { 57 | return password; 58 | } 59 | public void setPassword(String password) { 60 | this.password = password; 61 | } 62 | public String getEncryptedPassword() { 63 | return encryptedPassword; 64 | } 65 | public void setEncryptedPassword(String encryptedPassword) { 66 | this.encryptedPassword = encryptedPassword; 67 | } 68 | public String getEmailVerificationToken() { 69 | return emailVerificationToken; 70 | } 71 | public void setEmailVerificationToken(String emailVerificationToken) { 72 | this.emailVerificationToken = emailVerificationToken; 73 | } 74 | public Boolean isEmailVerficationStatus() { 75 | return emailVerificationStatus; 76 | } 77 | public void setEmailVerficationStatus(Boolean emailVerficationStatus) { 78 | this.emailVerificationStatus = emailVerficationStatus; 79 | } 80 | 81 | public List getAddresses() { 82 | return addresses; 83 | } 84 | public void setAddresses(List addresses) { 85 | this.addresses = addresses; 86 | } 87 | public ContactDto getContact() { 88 | return contact; 89 | } 90 | public void setContact(ContactDto contact) { 91 | this.contact = contact; 92 | } 93 | public Boolean getAdmin() { 94 | return admin; 95 | } 96 | public void setAdmin(Boolean admin) { 97 | this.admin = admin; 98 | } 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/services/impl/AddressServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.services.impl; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.List; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.modelmapper.TypeToken; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.brightcoding.app.ws.entities.AddressEntity; 12 | import com.brightcoding.app.ws.entities.UserEntity; 13 | import com.brightcoding.app.ws.repositories.AddressRepository; 14 | import com.brightcoding.app.ws.repositories.UserRepository; 15 | import com.brightcoding.app.ws.services.AddressService; 16 | import com.brightcoding.app.ws.shared.Utils; 17 | import com.brightcoding.app.ws.shared.dto.AddressDto; 18 | import com.brightcoding.app.ws.shared.dto.UserDto; 19 | 20 | @Service 21 | public class AddressServiceImpl implements AddressService { 22 | 23 | @Autowired 24 | AddressRepository addressRepository; 25 | 26 | @Autowired 27 | UserRepository userRepository; 28 | 29 | @Autowired 30 | Utils util; 31 | 32 | @Override 33 | public List getAllAddresses(String email) { 34 | 35 | UserEntity currentUser = userRepository.findByEmail(email); 36 | 37 | List addresses = currentUser.getAdmin() == true ? (List) addressRepository.findAll() : addressRepository.findByUser(currentUser); 38 | 39 | Type listType = new TypeToken>() {}.getType(); 40 | List addressesDto = new ModelMapper().map(addresses, listType); 41 | 42 | return addressesDto; 43 | } 44 | 45 | 46 | @Override 47 | public AddressDto createAddress(AddressDto address, String email) { 48 | 49 | UserEntity currentUser = userRepository.findByEmail(email); 50 | 51 | ModelMapper modelMapper = new ModelMapper(); 52 | UserDto userDto = modelMapper.map(currentUser, UserDto.class); 53 | 54 | address.setAddressId(util.generateStringId(30)); 55 | address.setUser(userDto); 56 | 57 | AddressEntity addressEntity = modelMapper.map(address, AddressEntity.class); 58 | 59 | AddressEntity newAddress = addressRepository.save(addressEntity); 60 | 61 | AddressDto addressDto = modelMapper.map(newAddress, AddressDto.class); 62 | 63 | return addressDto; 64 | } 65 | 66 | 67 | @Override 68 | public AddressDto getAddress(String addressId) { 69 | 70 | AddressEntity addressEntity = addressRepository.findByAddressId(addressId); 71 | 72 | ModelMapper modelMapper = new ModelMapper(); 73 | 74 | AddressDto addressDto = modelMapper.map(addressEntity, AddressDto.class); 75 | 76 | return addressDto; 77 | } 78 | 79 | @Override 80 | public void deleteAddress(String addressId) { 81 | 82 | AddressEntity address = addressRepository.findByAddressId(addressId); 83 | 84 | if(address == null) throw new RuntimeException("Address not found"); 85 | 86 | addressRepository.delete(address); 87 | 88 | } 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.2.7.RELEASE 10 | 11 | 12 | com.brightcoding.app.ws 13 | my.app.ws 14 | 0.0.1-SNAPSHOT 15 | my.app.ws 16 | war 17 | Demo project for Spring Boot 18 | 19 | 20 | 1.8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-jpa 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | 36 | 37 | com.fasterxml.jackson.dataformat 38 | jackson-dataformat-xml 39 | 40 | 41 | 42 | 43 | mysql 44 | mysql-connector-java 45 | runtime 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-security 52 | 53 | 54 | 55 | 56 | io.jsonwebtoken 57 | jjwt 58 | 0.9.1 59 | 60 | 61 | 62 | org.apache.tomcat.embed 63 | tomcat-embed-jasper 64 | provided 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter-tomcat 70 | provided 71 | 72 | 73 | 74 | org.modelmapper 75 | modelmapper 76 | 2.3.0 77 | 78 | 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-starter-test 83 | test 84 | 85 | 86 | org.junit.vintage 87 | junit-vintage-engine 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.springframework.boot 97 | spring-boot-maven-plugin 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/security/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.security; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | 7 | import javax.servlet.FilterChain; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import org.springframework.security.authentication.AuthenticationManager; 13 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.AuthenticationException; 16 | import org.springframework.security.core.userdetails.User; 17 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 18 | 19 | import com.brightcoding.app.ws.SpringApplicationContext; 20 | import com.brightcoding.app.ws.requests.UserLoginRequest; 21 | import com.brightcoding.app.ws.services.UserService; 22 | import com.brightcoding.app.ws.shared.dto.UserDto; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | import io.jsonwebtoken.Jwts; 26 | import io.jsonwebtoken.SignatureAlgorithm; 27 | 28 | public class AuthenticationFilter extends UsernamePasswordAuthenticationFilter { 29 | 30 | 31 | private final AuthenticationManager authenticationManager; 32 | 33 | public AuthenticationFilter(AuthenticationManager authenticationManager) { 34 | this.authenticationManager = authenticationManager; 35 | } 36 | 37 | @Override 38 | public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) 39 | throws AuthenticationException { 40 | try { 41 | 42 | UserLoginRequest creds = new ObjectMapper().readValue(req.getInputStream(), UserLoginRequest.class); 43 | 44 | return authenticationManager.authenticate( 45 | new UsernamePasswordAuthenticationToken(creds.getEmail(), creds.getPassword(), new ArrayList<>())); 46 | 47 | } catch (IOException e) { 48 | throw new RuntimeException(e); 49 | } 50 | } 51 | 52 | 53 | @Override 54 | protected void successfulAuthentication(HttpServletRequest req, 55 | HttpServletResponse res, 56 | FilterChain chain, 57 | Authentication auth) throws IOException, ServletException { 58 | 59 | String userName = ((User) auth.getPrincipal()).getUsername(); 60 | 61 | UserService userService = (UserService)SpringApplicationContext.getBean("userSeviceImpl"); 62 | 63 | UserDto userDto = userService.getUser(userName); 64 | 65 | String token = Jwts.builder() 66 | .setSubject(userName) 67 | .claim("id", userDto.getUserId()) 68 | .claim("name", userDto.getFirstName() + " " + userDto.getLastName()) 69 | .setExpiration(new Date(System.currentTimeMillis() + SecurityConstants.EXPIRATION_TIME)) 70 | .signWith(SignatureAlgorithm.HS512, SecurityConstants.TOKEN_SECRET ) 71 | .compact(); 72 | 73 | 74 | 75 | res.addHeader(SecurityConstants.HEADER_STRING, SecurityConstants.TOKEN_PREFIX + token); 76 | res.addHeader("user_id", userDto.getUserId()); 77 | 78 | res.getWriter().write("{\"token\": \"" + token + "\", \"id\": \""+ userDto.getUserId() + "\"}"); 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/controllers/AddressController.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.controllers; 2 | 3 | import java.lang.reflect.Type; 4 | import java.security.Principal; 5 | import java.util.List; 6 | 7 | import org.modelmapper.ModelMapper; 8 | import org.modelmapper.TypeToken; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.http.MediaType; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.DeleteMapping; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import com.brightcoding.app.ws.requests.AddressRequest; 23 | import com.brightcoding.app.ws.responses.AddressResponse; 24 | import com.brightcoding.app.ws.services.AddressService; 25 | import com.brightcoding.app.ws.shared.dto.AddressDto; 26 | 27 | @RestController 28 | @RequestMapping("/addresses") 29 | public class AddressController { 30 | 31 | @Autowired 32 | AddressService addressService; 33 | 34 | @GetMapping 35 | public ResponseEntity>getAddresses(Principal principal) { 36 | 37 | List addresses = addressService.getAllAddresses(principal.getName()); 38 | 39 | Type listType = new TypeToken>() {}.getType(); 40 | List addressesResponse = new ModelMapper().map(addresses, listType); 41 | 42 | return new ResponseEntity>(addressesResponse, HttpStatus.OK); 43 | 44 | } 45 | 46 | @PostMapping( 47 | consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}, 48 | produces={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE} 49 | ) 50 | public ResponseEntity StoreAddresse(@RequestBody AddressRequest addressRequest, Principal principal) { 51 | 52 | ModelMapper modelMapper = new ModelMapper(); 53 | 54 | AddressDto addressDto = modelMapper.map(addressRequest, AddressDto.class); 55 | AddressDto createAddress = addressService.createAddress(addressDto, principal.getName()); 56 | 57 | AddressResponse newAddress = modelMapper.map(createAddress, AddressResponse.class); 58 | 59 | return new ResponseEntity(newAddress, HttpStatus.CREATED); 60 | } 61 | 62 | @GetMapping("/{id}") 63 | public ResponseEntity getOneAddresse(@PathVariable(name="id") String addressId) { 64 | 65 | AddressDto addressDto = addressService.getAddress(addressId); 66 | 67 | ModelMapper modelMapper = new ModelMapper(); 68 | 69 | AddressResponse addressResponse = modelMapper.map(addressDto, AddressResponse.class); 70 | 71 | return new ResponseEntity(addressResponse, HttpStatus.OK); 72 | } 73 | 74 | @PutMapping("/{id}") 75 | public ResponseEntity updatreAddresse(@PathVariable(name="id") String addressId) { 76 | return new ResponseEntity<>("update addresses", HttpStatus.ACCEPTED); 77 | } 78 | 79 | @DeleteMapping("/{id}") 80 | public ResponseEntity deleteAddresse(@PathVariable(name="id") String addressId) { 81 | 82 | addressService.deleteAddress(addressId); 83 | 84 | return new ResponseEntity<>(HttpStatus.NO_CONTENT); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/entities/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.entities; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | 8 | import javax.persistence.CascadeType; 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.FetchType; 12 | import javax.persistence.GeneratedValue; 13 | import javax.persistence.Id; 14 | import javax.persistence.ManyToMany; 15 | import javax.persistence.OneToMany; 16 | import javax.persistence.OneToOne; 17 | import javax.persistence.Table; 18 | 19 | 20 | @Entity 21 | @Table(name="users") 22 | public class UserEntity implements Serializable { 23 | 24 | 25 | private static final long serialVersionUID = -5763827745308343856L; 26 | 27 | @Id 28 | @GeneratedValue 29 | private long id; 30 | 31 | @Column(nullable=false) 32 | private String userId; 33 | 34 | @Column(nullable=false, length=50) 35 | private String firstName; 36 | 37 | @Column(nullable=false, length=50) 38 | private String lastName; 39 | 40 | @Column(nullable=false, length=120, unique=true) 41 | private String email; 42 | 43 | @Column(nullable=true) 44 | private Boolean admin = false; 45 | 46 | @Column(nullable=false) 47 | private String encryptedPassword; 48 | 49 | @Column(nullable=true) 50 | private String emailVerificationToken; 51 | 52 | @Column(nullable=false) 53 | private Boolean emailVerificationStatus = false; 54 | 55 | 56 | @OneToMany(mappedBy="user", fetch = FetchType.EAGER, cascade=CascadeType.ALL) 57 | private List addresses; 58 | 59 | @OneToOne(mappedBy="user", fetch = FetchType.EAGER, cascade=CascadeType.ALL) 60 | private ContactEntity contact; 61 | 62 | @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="users") 63 | private Set groups = new HashSet<>(); 64 | 65 | 66 | public long getId() { 67 | return id; 68 | } 69 | 70 | public void setId(long id) { 71 | this.id = id; 72 | } 73 | 74 | public String getUserId() { 75 | return userId; 76 | } 77 | 78 | public void setUserId(String userId) { 79 | this.userId = userId; 80 | } 81 | 82 | public String getFirstName() { 83 | return firstName; 84 | } 85 | 86 | public void setFirstName(String firstName) { 87 | this.firstName = firstName; 88 | } 89 | 90 | public String getLastName() { 91 | return lastName; 92 | } 93 | 94 | public void setLastName(String lastName) { 95 | this.lastName = lastName; 96 | } 97 | 98 | public String getEmail() { 99 | return email; 100 | } 101 | 102 | public void setEmail(String email) { 103 | this.email = email; 104 | } 105 | 106 | public String getEncryptedPassword() { 107 | return encryptedPassword; 108 | } 109 | 110 | public void setEncryptedPassword(String encryptedPassword) { 111 | this.encryptedPassword = encryptedPassword; 112 | } 113 | 114 | public String getEmailVerificationToken() { 115 | return emailVerificationToken; 116 | } 117 | 118 | public void setEmailVerificationToken(String emailVerificationToken) { 119 | this.emailVerificationToken = emailVerificationToken; 120 | } 121 | 122 | public Boolean getEmailVerficationStatus() { 123 | return emailVerificationStatus; 124 | } 125 | 126 | public void setEmailVerficationStatus(Boolean emailVerficationStatus) { 127 | this.emailVerificationStatus = emailVerficationStatus; 128 | } 129 | 130 | public Boolean getEmailVerificationStatus() { 131 | return emailVerificationStatus; 132 | } 133 | 134 | public void setEmailVerificationStatus(Boolean emailVerificationStatus) { 135 | this.emailVerificationStatus = emailVerificationStatus; 136 | } 137 | 138 | public List getAddresses() { 139 | return addresses; 140 | } 141 | 142 | public void setAddresses(List addresses) { 143 | this.addresses = addresses; 144 | } 145 | 146 | public ContactEntity getContact() { 147 | return contact; 148 | } 149 | 150 | public void setContact(ContactEntity contact) { 151 | this.contact = contact; 152 | } 153 | 154 | public Boolean getAdmin() { 155 | return admin; 156 | } 157 | 158 | public void setAdmin(Boolean admin) { 159 | this.admin = admin; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/controllers/UserController.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.controllers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.validation.Valid; 7 | 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.beans.BeanUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.web.bind.annotation.CrossOrigin; 15 | import org.springframework.web.bind.annotation.DeleteMapping; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.PathVariable; 18 | import org.springframework.web.bind.annotation.PostMapping; 19 | import org.springframework.web.bind.annotation.PutMapping; 20 | import org.springframework.web.bind.annotation.RequestBody; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RequestParam; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import com.brightcoding.app.ws.exceptions.UserException; 26 | import com.brightcoding.app.ws.requests.UserRequest; 27 | import com.brightcoding.app.ws.responses.ErrorMessages; 28 | import com.brightcoding.app.ws.responses.UserResponse; 29 | import com.brightcoding.app.ws.services.UserService; 30 | import com.brightcoding.app.ws.shared.dto.UserDto; 31 | 32 | @CrossOrigin(origins="*") 33 | @RestController 34 | @RequestMapping("/users") 35 | public class UserController { 36 | 37 | @Autowired 38 | UserService userService; 39 | 40 | @GetMapping(path="/{id}", produces={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) 41 | public ResponseEntity getUser(@PathVariable String id) { 42 | 43 | UserDto userDto = userService.getUserByUserId(id); 44 | 45 | UserResponse userResponse = new UserResponse(); 46 | 47 | BeanUtils.copyProperties(userDto, userResponse); 48 | 49 | return new ResponseEntity(userResponse, HttpStatus.OK); 50 | } 51 | 52 | 53 | @GetMapping(produces={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) 54 | public ResponseEntity> getAllUsers(@RequestParam(value="page", defaultValue = "1") int page,@RequestParam(value="limit", defaultValue = "4") int limit ,@RequestParam(value="search", defaultValue = "") String search,@RequestParam(value="status", defaultValue = "1") int status) { 55 | 56 | List usersResponse = new ArrayList<>(); 57 | 58 | List users = userService.getUsers(page, limit, search, status); 59 | 60 | for(UserDto userDto: users) { 61 | 62 | ModelMapper modelMapper = new ModelMapper(); 63 | UserResponse userResponse = modelMapper.map(userDto, UserResponse.class); 64 | 65 | usersResponse.add(userResponse); 66 | } 67 | 68 | return new ResponseEntity>(usersResponse, HttpStatus.OK); 69 | } 70 | 71 | 72 | 73 | @PostMapping( 74 | consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}, 75 | produces={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE} 76 | ) 77 | public ResponseEntity createUser(@RequestBody @Valid UserRequest userRequest) throws Exception { 78 | 79 | if(userRequest.getFirstName().isEmpty()) throw new UserException(ErrorMessages.MISSING_REQUIRED_FIELD.getErrorMessage()); 80 | 81 | //UserDto userDto = new UserDto(); 82 | //BeanUtils.copyProperties(userRequest, userDto); 83 | ModelMapper modelMapper = new ModelMapper(); 84 | UserDto userDto = modelMapper.map(userRequest, UserDto.class); 85 | 86 | UserDto createUser = userService.createUser(userDto); 87 | 88 | UserResponse userResponse = modelMapper.map(createUser, UserResponse.class); 89 | 90 | return new ResponseEntity(userResponse, HttpStatus.CREATED); 91 | 92 | 93 | } 94 | 95 | @PutMapping( 96 | path="/{id}", 97 | consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}, 98 | produces={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE} 99 | ) 100 | public ResponseEntity updateUser(@PathVariable String id, @RequestBody UserRequest userRequest) { 101 | 102 | UserDto userDto = new UserDto(); 103 | 104 | BeanUtils.copyProperties(userRequest, userDto); 105 | 106 | UserDto updateUser = userService.updateUser(id, userDto); 107 | 108 | UserResponse userResponse = new UserResponse(); 109 | 110 | BeanUtils.copyProperties(updateUser, userResponse); 111 | 112 | return new ResponseEntity(userResponse, HttpStatus.ACCEPTED); 113 | } 114 | 115 | 116 | @DeleteMapping(path="/{id}") 117 | public ResponseEntity deleteUser(@PathVariable String id) { 118 | 119 | userService.deleteUser(id); 120 | 121 | return new ResponseEntity<>(HttpStatus.NO_CONTENT); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/brightcoding/app/ws/services/impl/UserSeviceImpl.java: -------------------------------------------------------------------------------- 1 | package com.brightcoding.app.ws.services.impl; 2 | 3 | 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.beans.BeanUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.data.domain.Page; 12 | import org.springframework.data.domain.PageRequest; 13 | import org.springframework.data.domain.Pageable; 14 | import org.springframework.security.core.userdetails.User; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 17 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 18 | import org.springframework.stereotype.Service; 19 | 20 | import com.brightcoding.app.ws.entities.UserEntity; 21 | import com.brightcoding.app.ws.repositories.UserRepository; 22 | import com.brightcoding.app.ws.services.UserService; 23 | import com.brightcoding.app.ws.shared.Utils; 24 | import com.brightcoding.app.ws.shared.dto.AddressDto; 25 | import com.brightcoding.app.ws.shared.dto.UserDto; 26 | 27 | 28 | 29 | @Service 30 | public class UserSeviceImpl implements UserService { 31 | 32 | @Autowired 33 | UserRepository userRepository; 34 | 35 | @Autowired 36 | BCryptPasswordEncoder bCryptPasswordEncoder; 37 | 38 | @Autowired 39 | Utils util; 40 | 41 | 42 | @Override 43 | public UserDto createUser(UserDto user) { 44 | 45 | UserEntity checkUser = userRepository.findByEmail(user.getEmail()); 46 | 47 | if(checkUser != null) throw new RuntimeException("User Alrady Exists !"); 48 | 49 | 50 | for(int i=0; i < user.getAddresses().size(); i++) { 51 | 52 | AddressDto address = user.getAddresses().get(i); 53 | address.setUser(user); 54 | address.setAddressId(util.generateStringId(30)); 55 | user.getAddresses().set(i, address); 56 | } 57 | 58 | user.getContact().setContactId(util.generateStringId(30)); 59 | user.getContact().setUser(user); 60 | 61 | ModelMapper modelMapper = new ModelMapper(); 62 | 63 | UserEntity userEntity = modelMapper.map(user, UserEntity.class); 64 | 65 | 66 | userEntity.setEncryptedPassword(bCryptPasswordEncoder.encode(user.getPassword())); 67 | 68 | userEntity.setUserId(util.generateStringId(32)); 69 | 70 | UserEntity newUser = userRepository.save(userEntity); 71 | 72 | UserDto userDto = modelMapper.map(newUser, UserDto.class); 73 | 74 | return userDto; 75 | } 76 | 77 | 78 | @Override 79 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 80 | 81 | UserEntity userEntity = userRepository.findByEmail(email); 82 | 83 | if(userEntity == null) throw new UsernameNotFoundException(email); 84 | 85 | return new User(userEntity.getEmail(), userEntity.getEncryptedPassword(), new ArrayList<>()); 86 | } 87 | 88 | 89 | @Override 90 | public UserDto getUser(String email) { 91 | 92 | UserEntity userEntity = userRepository.findByEmail(email); 93 | 94 | if(userEntity == null) throw new UsernameNotFoundException(email); 95 | 96 | UserDto userDto = new UserDto(); 97 | 98 | BeanUtils.copyProperties(userEntity, userDto); 99 | 100 | return userDto; 101 | } 102 | 103 | 104 | @Override 105 | public UserDto getUserByUserId(String userId) { 106 | 107 | UserEntity userEntity = userRepository.findByUserId(userId); 108 | 109 | if(userEntity == null) throw new UsernameNotFoundException(userId); 110 | 111 | UserDto userDto = new UserDto(); 112 | 113 | BeanUtils.copyProperties(userEntity, userDto); 114 | 115 | return userDto; 116 | } 117 | 118 | 119 | @Override 120 | public UserDto updateUser(String userId, UserDto userDto) { 121 | 122 | UserEntity userEntity = userRepository.findByUserId(userId); 123 | 124 | if(userEntity == null) throw new UsernameNotFoundException(userId); 125 | 126 | userEntity.setFirstName(userDto.getFirstName()); 127 | userEntity.setLastName(userDto.getLastName()); 128 | 129 | UserEntity userUpdated = userRepository.save(userEntity); 130 | 131 | UserDto user = new UserDto(); 132 | 133 | BeanUtils.copyProperties(userUpdated, user); 134 | 135 | return user; 136 | } 137 | 138 | 139 | @Override 140 | public void deleteUser(String userId) { 141 | 142 | UserEntity userEntity = userRepository.findByUserId(userId); 143 | 144 | if(userEntity == null) throw new UsernameNotFoundException(userId); 145 | 146 | userRepository.delete(userEntity); 147 | 148 | } 149 | 150 | 151 | @Override 152 | public List getUsers(int page, int limit, String search, int status) { 153 | 154 | if(page > 0) page = page - 1; 155 | 156 | List usersDto = new ArrayList<>(); 157 | 158 | Pageable pageableRequest = PageRequest.of(page, limit); 159 | 160 | Page userPage; 161 | 162 | if(search.isEmpty()) { 163 | userPage = userRepository.findAllUsers(pageableRequest); 164 | } 165 | else { 166 | 167 | userPage = userRepository.findAllUserByCriteria(pageableRequest, search, status); 168 | } 169 | 170 | 171 | List users = userPage.getContent(); 172 | 173 | for(UserEntity userEntity: users) { 174 | 175 | ModelMapper modelMapper = new ModelMapper(); 176 | UserDto user = modelMapper.map(userEntity, UserDto.class); 177 | 178 | usersDto.add(user); 179 | } 180 | 181 | return usersDto; 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | --------------------------------------------------------------------------------