├── .dockerignore ├── .env ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── config.yml ├── stale.yml └── workflows │ └── hooks.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitlab ├── issue_templates │ ├── bug_report.md │ └── feature_request.md └── merge_request_templates │ └── merge_request_template.md ├── .gitpod.yml ├── .theia ├── launch.json └── settings.json ├── .travis.yml ├── CONTRIBUTING.md ├── Dockerfile.alpine ├── Dockerfile.develop ├── Dockerfile.gitpod ├── Jenkinsfile ├── LICENSE ├── README.md ├── build.gradle ├── docker-compose.h2.test.yml ├── docker-compose.mariadb.test_.yml ├── docker-compose.mysql.test_.yml ├── docker-compose.postgres.test.yml ├── docker-compose.yml ├── docker-entrypoint.sh ├── docker ├── README.md ├── maven │ └── settings-docker.xml └── test │ ├── Dockerfile │ └── docker_test.sh ├── docs ├── README.md └── _config.yml ├── gradlew ├── gradlew.bat ├── hooks ├── README.md ├── build ├── post_push ├── post_test ├── pre_push ├── pre_test ├── push ├── run └── test ├── jitpack.yml ├── manage.sh ├── mvnw ├── mvnw.cmd ├── pmdruleset.xml ├── pom.xml └── src ├── integration-test ├── java │ └── com │ │ └── monogramm │ │ ├── ApplicationIT.java │ │ └── starter │ │ ├── SmtpServerRule.java │ │ ├── api │ │ ├── AbstractControllerFullIT.java │ │ ├── AbstractControllerIT.java │ │ ├── AbstractControllerMockIT.java │ │ ├── media │ │ │ └── controller │ │ │ │ ├── MediaControllerFullIT.java │ │ │ │ └── MediaControllerMockIT.java │ │ ├── oauth │ │ │ └── controller │ │ │ │ ├── OAuthControllerFullIT.java │ │ │ │ └── OAuthControllerMockIT.java │ │ ├── parameter │ │ │ └── controller │ │ │ │ ├── ParameterControllerFullIT.java │ │ │ │ └── ParameterControllerMockIT.java │ │ ├── permission │ │ │ └── controller │ │ │ │ ├── PermissionControllerFullIT.java │ │ │ │ └── PermissionControllerMockIT.java │ │ ├── role │ │ │ └── controller │ │ │ │ ├── RoleControllerFullIT.java │ │ │ │ └── RoleControllerMockIT.java │ │ ├── type │ │ │ └── controller │ │ │ │ ├── TypeControllerFullIT.java │ │ │ │ └── TypeControllerMockIT.java │ │ └── user │ │ │ └── controller │ │ │ ├── UserControllerFullIT.java │ │ │ └── UserControllerMockIT.java │ │ └── persistence │ │ ├── AbstractGenericRepositoryIT.java │ │ ├── media │ │ └── dao │ │ │ └── MediaRepositoryIT.java │ │ ├── parameter │ │ └── dao │ │ │ └── ParameterRepositoryIT.java │ │ ├── permission │ │ └── dao │ │ │ └── PermissionRepositoryIT.java │ │ ├── role │ │ └── dao │ │ │ └── RoleRepositoryIT.java │ │ ├── type │ │ └── dao │ │ │ └── TypeRepositoryIT.java │ │ └── user │ │ └── dao │ │ ├── PasswordResetTokenRepositoryIT.java │ │ ├── UserRepositoryIT.java │ │ └── VerificationTokenRepositoryIT.java └── resources │ ├── application.properties │ └── log4j2-spring.xml ├── main ├── java │ └── com │ │ └── monogramm │ │ ├── Application.java │ │ ├── package-info.java │ │ └── starter │ │ ├── api │ │ ├── AbstractGenericController.java │ │ ├── AbstractMailSendingEvent.java │ │ ├── AbstractMailSendingListener.java │ │ ├── RestResponseEntityExceptionHandler.java │ │ ├── discoverability │ │ │ ├── event │ │ │ │ ├── AbstractResourceEvent.java │ │ │ │ ├── PaginatedResultsRetrievedEvent.java │ │ │ │ ├── ResourceCreatedEvent.java │ │ │ │ ├── SingleResourceRetrievedEvent.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── PageNotFoundException.java │ │ │ │ └── package-info.java │ │ │ ├── listener │ │ │ │ ├── PaginatedResultsRetrievedDiscoverabilityListener.java │ │ │ │ ├── ResourceCreatedDiscoverabilityListener.java │ │ │ │ ├── SingleResourceRetrievedDiscoverabilityListener.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── utils │ │ │ │ ├── LinkUtils.java │ │ │ │ └── package-info.java │ │ ├── media │ │ │ ├── controller │ │ │ │ ├── MediaController.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── oauth │ │ │ ├── controller │ │ │ │ ├── OAuthController.java │ │ │ │ ├── RevokeTokenEndpoint.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── parameter │ │ │ ├── controller │ │ │ │ ├── ParameterController.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── permission │ │ │ ├── controller │ │ │ │ ├── PermissionController.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── role │ │ │ ├── controller │ │ │ │ ├── RoleController.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── type │ │ │ ├── controller │ │ │ │ ├── TypeController.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ └── user │ │ │ ├── controller │ │ │ ├── UserController.java │ │ │ └── package-info.java │ │ │ ├── event │ │ │ ├── OnPasswordResetEvent.java │ │ │ ├── OnRegistrationCompleteEvent.java │ │ │ └── package-info.java │ │ │ ├── listener │ │ │ ├── PasswordResetListener.java │ │ │ ├── RegistrationListener.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── config │ │ ├── OAuth2AuthorizationServerConfig.java │ │ ├── OAuth2GlobalSecurityConfig.java │ │ ├── OAuth2ResourceServerConfig.java │ │ ├── OAuth2WebSecurityConfig.java │ │ ├── SpringFoxConfig.java │ │ ├── component │ │ │ ├── CustomPasswordEncoder.java │ │ │ ├── CustomServletRequestWrapper.java │ │ │ ├── CustomTokenEnhancer.java │ │ │ ├── CustomUserDetails.java │ │ │ ├── CustomUserDetailsService.java │ │ │ └── package-info.java │ │ ├── data │ │ │ ├── AbstractDataLoader.java │ │ │ ├── GenericOperation.java │ │ │ ├── InitialDataLoader.java │ │ │ └── package-info.java │ │ ├── filter │ │ │ ├── JsonToUrlEncodedAuthenticationFilter.java │ │ │ ├── SimpleCorsFilter.java │ │ │ └── package-info.java │ │ ├── i8n │ │ │ ├── ApplicationMessage.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── properties │ │ │ ├── ApplicationProperties.java │ │ │ ├── ApplicationSecurityProperties.java │ │ │ ├── DataProperties.java │ │ │ ├── EmailProperties.java │ │ │ ├── WelcomeProperties.java │ │ │ └── package-info.java │ │ └── security │ │ │ ├── AuthenticationFacade.java │ │ │ ├── CustomMethodSecurityExpressionHandler.java │ │ │ ├── CustomMethodSecurityExpressionRoot.java │ │ │ ├── CustomPermissionEvaluator.java │ │ │ ├── IAuthenticationFacade.java │ │ │ └── package-info.java │ │ ├── dto │ │ ├── AbstractGenericDto.java │ │ ├── AbstractGenericDtoComparator.java │ │ ├── AbstractParameterDto.java │ │ ├── AbstractTokenDto.java │ │ ├── media │ │ │ ├── MediaDto.java │ │ │ └── package-info.java │ │ ├── oauth │ │ │ ├── OAuthRequest.java │ │ │ ├── OAuthResponse.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── parameter │ │ │ ├── ParameterDto.java │ │ │ └── package-info.java │ │ ├── permission │ │ │ ├── PermissionDto.java │ │ │ └── package-info.java │ │ ├── role │ │ │ ├── RoleDto.java │ │ │ └── package-info.java │ │ ├── type │ │ │ ├── TypeDto.java │ │ │ └── package-info.java │ │ └── user │ │ │ ├── PasswordResetDto.java │ │ │ ├── PasswordResetTokenDto.java │ │ │ ├── RegistrationDto.java │ │ │ ├── UserDto.java │ │ │ ├── VerificationTokenDto.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── persistence │ │ ├── AbstractGenericBridge.java │ │ ├── AbstractGenericEntity.java │ │ ├── AbstractGenericService.java │ │ ├── AbstractParameter.java │ │ ├── AbstractParameterBridge.java │ │ ├── AbstractToken.java │ │ ├── AbstractTokenBridge.java │ │ ├── EntityNotFoundException.java │ │ ├── GenericRepository.java │ │ ├── GenericService.java │ │ ├── ParameterType.java │ │ ├── media │ │ │ ├── dao │ │ │ │ ├── MediaRepository.java │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ ├── Media.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── MediaNotFoundException.java │ │ │ │ ├── MediaStorageException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── properties │ │ │ │ ├── FileStorageProperties.java │ │ │ │ └── package-info.java │ │ │ └── service │ │ │ │ ├── MediaBridge.java │ │ │ │ ├── MediaService.java │ │ │ │ ├── MediaServiceImpl.java │ │ │ │ ├── StorageUtils.java │ │ │ │ └── package-info.java │ │ ├── oauth │ │ │ ├── dao │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── parameter │ │ │ ├── dao │ │ │ │ ├── ParameterRepository.java │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ ├── Parameter.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── ParameterNotFoundException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ ├── ParameterBridge.java │ │ │ │ ├── ParameterService.java │ │ │ │ ├── ParameterServiceImpl.java │ │ │ │ └── package-info.java │ │ ├── permission │ │ │ ├── dao │ │ │ │ ├── PermissionRepository.java │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ ├── Permission.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── PermissionNotFoundException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ ├── PermissionBridge.java │ │ │ │ ├── PermissionService.java │ │ │ │ ├── PermissionServiceImpl.java │ │ │ │ └── package-info.java │ │ ├── role │ │ │ ├── dao │ │ │ │ ├── RoleRepository.java │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ ├── Role.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── RoleNotFoundException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ ├── RoleBridge.java │ │ │ │ ├── RoleService.java │ │ │ │ ├── RoleServiceImpl.java │ │ │ │ └── package-info.java │ │ ├── type │ │ │ ├── dao │ │ │ │ ├── TypeRepository.java │ │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ │ ├── Type.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ │ ├── TypeNotFoundException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ ├── TypeBridge.java │ │ │ │ ├── TypeService.java │ │ │ │ ├── TypeServiceImpl.java │ │ │ │ └── package-info.java │ │ └── user │ │ │ ├── dao │ │ │ ├── PasswordResetTokenRepository.java │ │ │ ├── UserRepository.java │ │ │ ├── VerificationTokenRepository.java │ │ │ └── package-info.java │ │ │ ├── entity │ │ │ ├── PasswordResetToken.java │ │ │ ├── User.java │ │ │ ├── VerificationToken.java │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── PasswordResetTokenNotFoundException.java │ │ │ ├── UserNotFoundException.java │ │ │ ├── VerificationTokenNotFoundException.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ ├── PasswordResetTokenBridge.java │ │ │ ├── PasswordResetTokenService.java │ │ │ ├── PasswordResetTokenServiceImpl.java │ │ │ ├── UserBridge.java │ │ │ ├── UserService.java │ │ │ ├── UserServiceImpl.java │ │ │ ├── VerificationTokenBridge.java │ │ │ ├── VerificationTokenService.java │ │ │ ├── VerificationTokenServiceImpl.java │ │ │ └── package-info.java │ │ └── utils │ │ ├── JsonUtils.java │ │ ├── Jsonable.java │ │ ├── JwtUtils.java │ │ ├── ZipUtils.java │ │ ├── converter │ │ ├── AnyConverter.java │ │ ├── BooleanConverter.java │ │ ├── ColorConverter.java │ │ ├── DateConverter.java │ │ ├── DateTimeConverter.java │ │ ├── DoubleConverter.java │ │ ├── IntegerConverter.java │ │ ├── ParameterExporter.java │ │ ├── ParameterImporter.java │ │ ├── PathConverter.java │ │ ├── StringConverter.java │ │ ├── TimeConverter.java │ │ ├── UrlConverter.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── validation │ │ ├── EmailValidator.java │ │ ├── PasswordConfirmationDto.java │ │ ├── PasswordMatches.java │ │ ├── PasswordMatchesValidator.java │ │ ├── UuidValidator.java │ │ ├── ValidEmail.java │ │ ├── ValidUuid.java │ │ └── package-info.java └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ ├── app-banner.txt │ ├── application.properties │ ├── data.sql │ ├── i18n │ ├── messages.properties │ └── messages_fr.properties │ ├── log4j2-spring.xml │ ├── schema-h2.sql │ ├── schema-mariadb.sql │ ├── schema-mysql.sql │ └── schema-postgresql.sql └── test └── java └── com └── monogramm └── starter ├── api ├── AbstractGenericControllerTest.java ├── AbstractMailSendingEventTest.java ├── discoverability │ ├── event │ │ ├── AbstractResourceEventTest.java │ │ └── PaginatedResultsRetrievedEventTest.java │ ├── exception │ │ └── PageNotFoundExceptionTest.java │ └── listener │ │ ├── PaginatedResultsRetrievedDiscoverabilityListenerTest.java │ │ ├── ResourceCreatedDiscoverabilityListenerTest.java │ │ └── SingleResourceRetrievedDiscoverabilityListenerTest.java ├── media │ └── controller │ │ └── MediaControllerTest.java ├── parameter │ └── controller │ │ └── ParameterControllerTest.java ├── permission │ └── controller │ │ └── PermissionControllerTest.java ├── role │ └── controller │ │ └── RoleControllerTest.java ├── type │ └── controller │ │ └── TypeControllerTest.java └── user │ ├── controller │ └── UserControllerTest.java │ ├── event │ ├── OnPasswordResetEventTest.java │ └── OnRegistrationCompleteEventTest.java │ └── listener │ ├── PasswordResetListenerTest.java │ └── RegistrationListenerTest.java ├── config ├── component │ ├── CustomPasswordEncoderTest.java │ ├── CustomServletRequestWrapperTest.java │ └── CustomTokenEnhancerTest.java ├── data │ └── InitialDataLoaderTest.java ├── filter │ ├── JsonToUrlEncodedAuthenticationFilterTest.java │ └── SimpleCorsFilterTest.java └── i8n │ └── ApplicationMessageTest.java ├── dto ├── AbstractGenericDtoTest.java ├── AbstractParameterDtoTest.java ├── AbstractTokenDtoTest.java ├── media │ └── MediaDtoTest.java ├── oauth │ ├── OAuthRequestTest.java │ └── OAuthResponseTest.java ├── parameter │ └── ParameterDtoTest.java ├── permission │ └── PermissionDtoTest.java ├── role │ └── RoleDtoTest.java ├── type │ └── TypeDtoTest.java └── user │ ├── PasswordResetDtoTest.java │ ├── PasswordResetTokenDtoTest.java │ ├── RegistrationDtoTest.java │ ├── UserDtoTest.java │ └── VerificationTokenDtoTest.java ├── persistence ├── AbstractGenericBridgeTest.java ├── AbstractGenericEntityBuilderTest.java ├── AbstractGenericEntityTest.java ├── AbstractGenericServiceTest.java ├── AbstractParameterBridgeTest.java ├── AbstractParameterBuilderTest.java ├── AbstractParameterTest.java ├── AbstractTokenBridgeTest.java ├── AbstractTokenBuilderTest.java ├── AbstractTokenTest.java ├── GenericServiceTest.java ├── media │ ├── entity │ │ ├── MediaBuilderTest.java │ │ └── MediaTest.java │ ├── exception │ │ ├── MediaNotFoundExceptionTest.java │ │ └── MediaStorageExceptionTest.java │ └── service │ │ ├── MediaBridgeTest.java │ │ └── MediaServiceImplTest.java ├── parameter │ ├── entity │ │ ├── ParameterBuilderTest.java │ │ └── ParameterTest.java │ ├── exception │ │ └── ParameterNotFoundExceptionTest.java │ └── service │ │ ├── ParameterBridgeTest.java │ │ └── ParameterServiceImplTest.java ├── permission │ ├── entity │ │ ├── PermissionBuilderTest.java │ │ └── PermissionTest.java │ ├── exception │ │ └── PermissionNotFoundExceptionTest.java │ └── service │ │ ├── PermissionBridgeTest.java │ │ └── PermissionServiceImplTest.java ├── role │ ├── entity │ │ ├── RoleBuilderTest.java │ │ └── RoleTest.java │ ├── exception │ │ └── RoleNotFoundExceptionTest.java │ └── service │ │ ├── RoleBridgeTest.java │ │ └── RoleServiceImplTest.java ├── type │ ├── entity │ │ ├── TypeBuilderTest.java │ │ └── TypeTest.java │ ├── exception │ │ └── TypeNotFoundExceptionTest.java │ └── service │ │ ├── TypeBridgeTest.java │ │ └── TypeServiceImplTest.java └── user │ ├── entity │ ├── PasswordResetTokenBuilderTest.java │ ├── PasswordResetTokenTest.java │ ├── UserBuilderTest.java │ ├── UserTest.java │ ├── VerificationTokenBuilderTest.java │ └── VerificationTokenTest.java │ ├── exception │ ├── PasswordResetTokenNotFoundExceptionTest.java │ ├── UserNotFoundExceptionTest.java │ └── VerificationTokenNotFoundExceptionTest.java │ └── service │ ├── PasswordResetTokenBridgeTest.java │ ├── PasswordResetTokenServiceImplTest.java │ ├── UserBridgeTest.java │ ├── UserServiceImplTest.java │ ├── VerificationTokenBridgeTest.java │ └── VerificationTokenServiceImplTest.java └── utils ├── ZipUtilsTest.java └── validation ├── EmailValidatorTest.java ├── PasswordConfirmationDtoTest.java ├── PasswordMatchesValidatorTest.java └── UuidValidatorTest.java /.dockerignore: -------------------------------------------------------------------------------- 1 | # Ignore SCM and IDE items 2 | .git 3 | .idea 4 | .project 5 | .eclipse 6 | .vscode 7 | 8 | # maven 9 | target/ 10 | .mvn 11 | 12 | # gradle 13 | gradle/ 14 | .gradle/ 15 | bin/ 16 | 17 | # eclipse 18 | .project 19 | .classpath 20 | .settings 21 | 22 | #ant specific 23 | dist/ 24 | build/ 25 | 26 | #netbeans specific 27 | #core 28 | nbproject/* 29 | !nbproject/project.properties 30 | !nbproject/project.xml 31 | 32 | #spring specific 33 | .springBeans 34 | 35 | #project specific 36 | h2 37 | data 38 | 39 | #general swap/backup files 40 | *.so 41 | *.log 42 | *.out 43 | *~ 44 | *.swp 45 | *.DS_Store 46 | *.lock 47 | 48 | # Docker files 49 | docker-compose*.yml 50 | 51 | # CI 52 | Jenkinsfile 53 | .travis.yml 54 | 55 | # Custom files 56 | .docker/ 57 | .docker-build-date 58 | .docker-build 59 | manage.sh 60 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | 2 | ######################################## 3 | # App Docker configuration 4 | ######################################## 5 | 6 | APP_HOME=.docker/app 7 | 8 | # Application Configuration 9 | APP_TITLE=My App 10 | APP_DOMAIN_NAME=example.com 11 | APP_ADMIN_PASSWORD=youshouldoverwritethiswithsomethingelse 12 | APP_SIGNING_KEYPAIR_PASS=youshouldoverwritethiswithsomethingelse 13 | 14 | # Tomcat Configuration 15 | APP_SERVER_PORT=8080 16 | APP_SERVER_CONTEXT_PATH=api 17 | APP_MAX_FILE_SIZE=20MB 18 | APP_MAX_REQUEST_SIZE=20MB 19 | 20 | # Database configuration 21 | APP_DB_NAME=app 22 | APP_DB_USER=app 23 | APP_DB_PASSWORD=somethingverySecure 24 | 25 | # Mail configuration 26 | APP_SMTP_USER= 27 | APP_SMTP_PASSWD= 28 | APP_MAILER_FROM=test@example.com 29 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Autodetect text files 2 | * text=auto 3 | 4 | # ...Unless the name matches the following 5 | # overriding patterns 6 | 7 | # Definitely text files 8 | *.txt text 9 | *.svg text 10 | *.md text 11 | *.bat text eol=crlf 12 | *.cmd text eol=crlf 13 | *.sh text eol=lf 14 | *.yml text eol=lf 15 | *.xml text eol=lf 16 | Dockerfile text eol=lf 17 | Dockerfile.* text eol=lf 18 | /hooks/* text eol=lf 19 | 20 | *.java text 21 | *.properties text eol=lf 22 | /gradlew text eol=lf 23 | /mvnw text eol=lf 24 | 25 | # Ensure those won't be messed up with 26 | *.jpg binary 27 | *.jpeg binary 28 | *.png binary 29 | *.data binary 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Bug report 4 | about: Create a report to help us improve 5 | title: '' 6 | labels: bug 7 | assignees: 8 | 9 | --- 10 | 11 | **Describe the bug** 12 | A clear and concise description of what the bug is. 13 | 14 | **To Reproduce** 15 | Steps to reproduce the behavior: 16 | 1. Go to '...' 17 | 2. Click on '....' 18 | 3. Scroll down to '....' 19 | 4. See error 20 | 21 | **Expected behavior** 22 | A clear and concise description of what you expected to happen. 23 | 24 | **Screenshots** 25 | If applicable, add screenshots to help explain your problem. 26 | 27 | **Desktop (please complete the following information):** 28 | 29 | - OS: (e.g. iOS) 30 | - Browser (e.g. chrome, safari) 31 | - Version (e.g. 22) 32 | 33 | **Smartphone (please complete the following information):** 34 | 35 | - Device: (e.g. iPhone6) 36 | - OS: (e.g. iOS8.1) 37 | - Browser (e.g. stock browser, safari) 38 | - Version (e.g. 22) 39 | 40 | **Additional context** 41 | Add any other context about the problem here. 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Feature request 4 | about: Suggest an idea for this project 5 | title: '' 6 | labels: enhancement 7 | assignees: 8 | 9 | --- 10 | 11 | **Is your feature request related to a problem? Please describe.** 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when (...) 13 | 14 | **Describe the solution you'd like** 15 | A clear and concise description of what you want to happen. 16 | 17 | **Describe alternatives you've considered** 18 | A clear and concise description of any alternative solutions or features you've considered. 19 | 20 | **Additional context** 21 | Add any other context or screenshots about the feature request here. 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 18 | 19 | > Please provide enough information so that others can review your pull request: 20 | 21 | 22 | 23 | > Explain the **details** for making this change. What existing problem does the pull request solve? 24 | 25 | 26 | 27 | > Screenshots/GIFs 28 | 29 | 30 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 2 | 3 | # Comment to be posted to on first time issues 4 | newIssueWelcomeComment: > 5 | Thanks for opening your first issue here! Be sure to follow the issue template! 6 | 7 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 8 | 9 | # Comment to be posted to on PRs from first time contributors in your repository 10 | newPRWelcomeComment: > 11 | Thanks for opening this pull request! Please check out our contributing guidelines. 12 | 13 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 14 | 15 | # Comment to be posted to on pull requests merged by a first time user 16 | firstPRMergeComment: > 17 | :tada: Congrats on merging your first pull request! We here at behaviorbot are proud of you! 18 | 19 | # It is recommend to include as many gifs and emojis as possible 20 | 21 | # Configuration for request-info - https://github.com/behaviorbot/request-info 22 | 23 | # *Required* Comment to reply with 24 | requestInfoReplyComment: > 25 | We would appreciate it if you could provide us with more info about this issue/pr! 26 | 27 | # *OPTIONAL* default titles to check against for lack of descriptiveness 28 | # MUST BE ALL LOWERCASE 29 | requestInfoDefaultTitles: 30 | - update readme.md 31 | - updates 32 | 33 | 34 | # *OPTIONAL* Label to be added to Issues and Pull Requests with insufficient information given 35 | requestInfoLabelToAdd: needs-more-info 36 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Number of days of inactivity before an issue becomes stale 4 | daysUntilStale: 60 5 | # Number of days of inactivity before a stale issue is closed 6 | daysUntilClose: 30 7 | 8 | # Issues with these labels will never be considered stale 9 | exemptLabels: 10 | - pinned 11 | - security 12 | 13 | # Label to use when marking an issue as stale 14 | staleLabel: wontfix 15 | 16 | # Comment to post when marking an issue as stale. Set to `false` to disable 17 | markComment: > 18 | This issue has been automatically marked as stale because it has not had 19 | recent activity. It will be closed if no further activity occurs. Thank you 20 | for your contributions. 21 | 22 | # Comment to post when closing a stale issue. Set to `false` to disable 23 | closeComment: false 24 | -------------------------------------------------------------------------------- /.github/workflows/hooks.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Docker Image CI 3 | 4 | on: 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | - master 10 | - develop 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | variant: ['alpine'] 18 | 19 | steps: 20 | - name: Check Out Repo 21 | uses: actions/checkout@v2 22 | 23 | - name: Execute CI build hooks 24 | id: docker_build 25 | run: | 26 | # Export variables to tag against GitHub Container Registry 27 | #export DOCKER_REGISTRY=ghcr.io 28 | #export DOCKER_REPO=${{ github.repository }} 29 | ./hooks/run build ${{ matrix.variant }} 30 | 31 | - name: Display docker images 32 | run: docker images 33 | 34 | - name: Execute CI test hooks 35 | id: docker_test 36 | run: | 37 | ./hooks/run test ${{ matrix.variant }} 38 | 39 | #- name: Codacy Coverage Reporter 40 | # uses: codacy/codacy-coverage-reporter-action@0.2.0 41 | # with: 42 | # project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} 43 | # coverage-reports: ./coverage/coverage-phpunit-cobertura.xml 44 | 45 | #- name: Execute CI push hooks 46 | # id: docker_push 47 | # run: | 48 | # # Export variables to login and push to GitHub Container Registry 49 | # #export DOCKER_REGISTRY=ghcr.io 50 | # #export DOCKER_LOGIN=${{ github.repository_owner }} 51 | # #export DOCKER_PASSWORD=${{ secrets.GITHUB_REGISTRY_TOKEN }} 52 | # ./hooks/run push ${{ matrix.variant }} 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.vscode 2 | target/* 3 | target 4 | 5 | 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | 9 | # Package Files # 10 | *.jar 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | 17 | # Intellij Files 18 | *.iml 19 | /lib 20 | 21 | # maven 22 | target/ 23 | .mvn 24 | 25 | # gradle 26 | gradle/ 27 | .gradle/ 28 | bin/ 29 | 30 | # eclipse 31 | .project 32 | .classpath 33 | .settings 34 | .checkstyle 35 | 36 | #ant specific 37 | dist/ 38 | build/ 39 | 40 | #netbeans specific 41 | #core 42 | nbproject/* 43 | !nbproject/project.properties 44 | !nbproject/project.xml 45 | 46 | #java specific 47 | *.class 48 | 49 | #general swap/backup files 50 | *.so 51 | *.log 52 | *.out 53 | *~ 54 | *.swp 55 | *.DS_Store 56 | *.lock 57 | 58 | #spring specific 59 | .springBeans 60 | 61 | #project specific 62 | .docker/ 63 | data 64 | logs 65 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/bug_report.md: -------------------------------------------------------------------------------- 1 | # Bug report 2 | 3 | Create a report to help us improve. 4 | 5 | /label ~bug 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | 25 | - OS: (e.g. iOS) 26 | - Browser (e.g. chrome, safari) 27 | - Version (e.g. 22) 28 | 29 | **Smartphone (please complete the following information):** 30 | 31 | - Device: (e.g. iPhone6) 32 | - OS: (e.g. iOS8.1) 33 | - Browser (e.g. stock browser, safari) 34 | - Version (e.g. 22) 35 | 36 | **Additional context** 37 | Add any other context about the problem here. 38 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/feature_request.md: -------------------------------------------------------------------------------- 1 | # Feature request 2 | 3 | Suggest an idea for this project. 4 | 5 | /label ~enhancement 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | 9 | A clear and concise description of what the problem is. Ex. I'm always frustrated when (...) 10 | 11 | **Describe the solution you'd like** 12 | 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | 21 | Add any other context or screenshots about the feature request here. 22 | -------------------------------------------------------------------------------- /.gitlab/merge_request_templates/merge_request_template.md: -------------------------------------------------------------------------------- 1 | 18 | 19 | > Please provide enough information so that others can review your pull request: 20 | 21 | 22 | 23 | > Explain the **details** for making this change. What existing problem does the pull request solve? 24 | 25 | 26 | 27 | > Screenshots/GIFs 28 | 29 | 30 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: Dockerfile.gitpod 3 | 4 | ports: 5 | - port: 8080 6 | 7 | tasks: 8 | - init: ./manage.sh build 9 | command: ./manage.sh run 10 | 11 | github: 12 | prebuilds: 13 | # enable for the master/default branch (defaults to true) 14 | master: true 15 | # enable for all branches in this repo (defaults to false) 16 | branches: false 17 | # enable for pull requests coming from this repo (defaults to true) 18 | pullRequests: true 19 | # enable for pull requests coming from forks (defaults to false) 20 | pullRequestsFromForks: false 21 | # add a check to pull requests (defaults to true) 22 | addCheck: true 23 | # add a "Review in Gitpod" button as a comment to pull requests (defaults to false) 24 | addComment: true 25 | # add a "Review in Gitpod" button to the pull request's description (defaults to false) 26 | addBadge: false 27 | # add a label once the prebuild is ready to pull requests (defaults to false) 28 | addLabel: true 29 | -------------------------------------------------------------------------------- /.theia/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | "version": "0.2.0", 5 | "configurations": [ 6 | { 7 | "type": "java", 8 | "name": "Debug (Launch) - Current File", 9 | "request": "launch", 10 | "mainClass": "${file}" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.theia/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.classpath": true, 4 | "**/.project": true, 5 | "**/.settings": true, 6 | "**/.factorypath": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | dist: trusty 3 | 4 | services: docker 5 | 6 | language: java 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | jdk: 13 | - oraclejdk11 14 | 15 | before_install: 16 | - env | sort 17 | - export DOCKER_REPO="monogramm/spring-rest-api-starter" 18 | 19 | install: 20 | # Execute CI build hooks 21 | # TODO Mount local dir as volume to retrieve test results (-v "$(pwd)":/usr/src/app) 22 | - ./hooks/run build "${VARIANT}" 23 | 24 | before_script: 25 | # Display docker images 26 | - docker images 27 | 28 | script: 29 | # Execute CI test hooks 30 | - ./hooks/run test "${VARIANT}" 31 | 32 | after_success: 33 | # TODO Send test coverage report to CodeCov 34 | - bash <(curl -s https://codecov.io/bash) 35 | 36 | #jobs: 37 | # allow_failures: 38 | # - env: DATABASE=h2 39 | 40 | env: # Environments 41 | - VARIANT=alpine 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | First of all, **thank you** for contributing, **you are awesome**! 5 | 6 | Here are a few rules to follow in order to ease code reviews, and discussions before maintainers accept and merge your work. 7 | 8 | You MUST follow the [Java Coding Standards](https://google.github.io/styleguide/javaguide.html). If you don't know about any of them, you should really read the recommendations. Can't wait? Use [Sonar Qube](http://www.sonarqube.org/). 9 | 10 | You MUST run the test suite. 11 | 12 | You MUST write (or update) unit tests. 13 | 14 | You SHOULD write documentation. 15 | 16 | Please, write [commit messages that make sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), and [rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing) 17 | before submitting your Pull Request. 18 | 19 | One may ask you to [squash your commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) too.This is used to "clean" your Pull Request before merging it (we don't want commits such as `fix tests`, `fix 2`, `fix 3`, etc.). 20 | 21 | Also, while creating your Pull Request on GitHub, you MUST write a description which gives the context and/or explains why you are creating it. 22 | 23 | Thank you! 24 | -------------------------------------------------------------------------------- /Dockerfile.develop: -------------------------------------------------------------------------------- 1 | FROM maven:3-jdk-8-slim AS builder 2 | 3 | RUN set -ex; \ 4 | apt-get update; \ 5 | apt-get install -y --allow-unauthenticated \ 6 | git \ 7 | graphviz \ 8 | ; \ 9 | dot -V; \ 10 | rm -rf /var/lib/apt/lists/* 11 | 12 | WORKDIR /usr/src/app 13 | 14 | EXPOSE 8080 8443 35729 15 | 16 | # Application configuration 17 | # Database configuration 18 | # Mail configuration 19 | ENV \ 20 | APP_TITLE=App \ 21 | APP_CONFIG=/srv/app/config/application.properties \ 22 | APP_SERVER_CONTEXT_PATH=/api \ 23 | APP_SERVER_PORT=8080 \ 24 | APP_MAX_FILE_SIZE=20MB \ 25 | APP_MAX_REQUEST_SIZE=20MB \ 26 | APP_DOMAIN_NAME=example.com \ 27 | APP_ADMIN_PASSWORD=youshouldoverwritethiswithsomethingelse \ 28 | APP_SIGNING_KEY=youshouldoverwritethiswithsomethingelse \ 29 | APP_SIGNING_KEYPAIR_PASS='' \ 30 | APP_SIGNING_KEYPAIR_ALIAS=spring_rest_api_starter_key \ 31 | APP_DEMO_DATA=false \ 32 | DB_DIALECT='' \ 33 | DB_STORAGE='' \ 34 | DB_DRIVER='' \ 35 | DB_PLATFORM='h2' \ 36 | DB_HOST='' \ 37 | DB_PORT='' \ 38 | DB_NAME='spring_rest_api_starter' \ 39 | DB_USER='spring_rest_api_starter' \ 40 | DB_PASSWORD='spring_rest_api_starter_password' \ 41 | MAIL_HOST= \ 42 | MAIL_PORT= \ 43 | MAIL_PROTOCOL= \ 44 | MAIL_USER= \ 45 | MAIL_PASSWORD= \ 46 | MAIL_SSL=false \ 47 | MAIL_STARTTLS=false 48 | 49 | COPY docker/maven/settings-docker.xml /usr/share/maven/ref/settings-docker.xml 50 | COPY . . 51 | 52 | # Credentials to private Package Repository 53 | ARG PACKAGE_REPO_LOGIN 54 | ARG PACKAGE_REPO_PASSWORD 55 | 56 | RUN set -ex; \ 57 | mvn \ 58 | clean \ 59 | install \ 60 | -DskipTests=true \ 61 | -Dmaven.javadoc.skip=true \ 62 | -B \ 63 | -V \ 64 | -s /usr/share/maven/ref/settings-docker.xml \ 65 | -P "${MAVEN_PROFILE}" \ 66 | ; 67 | 68 | CMD [ "mvn", "spring-boot:run" ] 69 | -------------------------------------------------------------------------------- /Dockerfile.gitpod: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | # Install custom tools, runtimes, etc. 4 | # For example "bastet", a command-line tetris clone: 5 | # RUN brew install bastet 6 | # 7 | # More information: https://www.gitpod.io/docs/config-docker/ 8 | 9 | #RUN set -ex; \ 10 | # bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh \ 11 | # && sdk install java 8.0.275.open" 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE") 7 | } 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'eclipse' 12 | apply plugin: 'idea' 13 | apply plugin: 'org.springframework.boot' 14 | 15 | jar { 16 | baseName = 'gs-accessing-data-mysql' 17 | version = '0.1.0' 18 | } 19 | 20 | repositories { 21 | mavenCentral() 22 | } 23 | 24 | sourceCompatibility = 1.8 25 | targetCompatibility = 1.8 26 | 27 | dependencies { 28 | compile("org.springframework.boot:spring-boot-starter-web") 29 | 30 | // JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) 31 | compile 'org.springframework.boot:spring-boot-starter-data-jpa' 32 | 33 | // Use H2 connector 34 | compile 'com.h2database:h2' 35 | 36 | testCompile('org.springframework.boot:spring-boot-starter-test') 37 | } 38 | 39 | configurations.all { 40 | exclude module: 'spring-boot-starter-logging' 41 | } 42 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | 2 | Docker build related files. 3 | -------------------------------------------------------------------------------- /docker/maven/settings-docker.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 25 | 26 | 27 | 28 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /docker/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:alpine 2 | 3 | COPY docker_test.sh /docker_test.sh 4 | 5 | RUN set -ex; \ 6 | chmod 755 /docker_test.sh; \ 7 | apk add --update \ 8 | curl \ 9 | git \ 10 | ; \ 11 | \ 12 | rm -rf /var/cache/apk/* 13 | 14 | CMD ["/docker_test.sh"] 15 | -------------------------------------------------------------------------------- /docker/test/docker_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | log() { 6 | echo "[$0] [$(date +%Y-%m-%dT%H:%M:%S)] $*" 7 | } 8 | 9 | ################################################################################ 10 | # Testing docker containers 11 | 12 | log "Waiting to ensure everything is fully ready for the tests..." 13 | sleep 60 14 | 15 | log "Checking main containers are reachable..." 16 | if ! ping -c 10 -q "${DOCKER_TEST_CONTAINER}" ; then 17 | log 'Main container is not responding!' 18 | # TODO Display logs to help bug fixing 19 | #log 'Check the following logs for details:' 20 | #tail -n 100 logs/*.log 21 | exit 2 22 | fi 23 | 24 | 25 | ################################################################################ 26 | # Success 27 | log 'Docker tests successful' 28 | 29 | 30 | ################################################################################ 31 | # Automated Service Unit tests 32 | # https://docs.docker.com/docker-hub/builds/automated-testing/ 33 | ################################################################################ 34 | 35 | if [ -n "${DOCKER_WEB_CONTAINER}" ]; then 36 | 37 | if ! ping -c 10 -q "${DOCKER_WEB_CONTAINER}" ; then 38 | log 'Web container is not responding!' 39 | # TODO Display logs to help bug fixing 40 | #log 'Check the following logs for details:' 41 | #tail -n 100 logs/*.log 42 | exit 2 43 | fi 44 | 45 | DOCKER_WEB_HEALTH_URL="http://${DOCKER_WEB_CONTAINER}:${DOCKER_WEB_PORT-:80}/${DOCKER_WEB_HEALTH_API:-health}" 46 | log "TODO Checking Health API: ${DOCKER_WEB_HEALTH_URL}" 47 | curl "${DOCKER_WEB_HEALTH_URL}" 48 | #curl --fail "${DOCKER_WEB_HEALTH_URL}" | grep -q -e 'UP' || exit 1 49 | fi 50 | 51 | ################################################################################ 52 | # Success 53 | echo "Docker app '${DOCKER_TEST_CONTAINER}' tests finished" 54 | echo 'Check the CI reports and logs for details.' 55 | exit 0 56 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # **LDAP All-For-One Manager** Documentation site 2 | 3 | **Spring REST API Starter**: A 'simple' starter project custom RESTful API. 4 | 5 | The objective of the project is to provide a user-friendly REST API. 6 | 7 | It comes with full build / tests / deploy automation while providing as much "_standard_" features as usually found in recent REST APIs. 8 | 9 | ## How to use 10 | 11 | Check repository on GitHub for details: 12 | 13 | ## Contributing 14 | 15 | For information about contributing, see the [Contributing page](https://github.com/Monogramm/spring-rest-api-starter/blob/main/CONTRIBUTING.md). 16 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /hooks/README.md: -------------------------------------------------------------------------------- 1 | # DockerHub automated tests hooks 2 | 3 | See documentation for details: 4 | -------------------------------------------------------------------------------- /hooks/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | # https://microbadger.com/labels 6 | 7 | docker build \ 8 | --build-arg "VCS_REF=${SOURCE_COMMIT}" \ 9 | --build-arg "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ 10 | --build-arg "TAG=${DOCKER_TAG}" \ 11 | --build-arg "MAVEN_PROFILE=${MAVEN_PROFILE}" \ 12 | --build-arg "PACKAGE_REPO_LOGIN=${PACKAGE_REPO_LOGIN}" \ 13 | --build-arg "PACKAGE_REPO_PASSWORD=${PACKAGE_REPO_PASSWORD}" \ 14 | -f "$DOCKERFILE_PATH" \ 15 | -t "$IMAGE_NAME" . 16 | -------------------------------------------------------------------------------- /hooks/post_push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | if [ -n "${DOCKER_REGISTRY}" ]; then 7 | export DOCKER_BASE_IMAGE=${DOCKER_REGISTRY}/${DOCKER_REPO} 8 | else 9 | export DOCKER_BASE_IMAGE=${DOCKER_REPO} 10 | fi 11 | 12 | if [ -f ./.dockertags ]; then 13 | for tag in $(cat ./.dockertags); do 14 | if [ ! "${tag}" = "${DOCKER_TAG}" ]; then 15 | docker tag "$IMAGE_NAME" "$DOCKER_BASE_IMAGE:$tag" 16 | docker push "$DOCKER_BASE_IMAGE:$tag" 17 | fi 18 | done 19 | fi 20 | 21 | # Push image with tag set to commit hash 22 | docker tag "$IMAGE_NAME" "$DOCKER_BASE_IMAGE:$SOURCE_COMMIT" 23 | docker push "$DOCKER_BASE_IMAGE:$SOURCE_COMMIT" 24 | 25 | if [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_LOGIN}" ]; then 26 | if [ -n "${DOCKER_REGISTRY}" ]; then 27 | echo "Logout of Docker Registry ${DOCKER_REGISTRY}..." 28 | docker logout "${DOCKER_REGISTRY}" 29 | else 30 | echo "Logout of Docker default Registry..." 31 | docker logout 32 | fi 33 | fi 34 | -------------------------------------------------------------------------------- /hooks/post_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | if [ ! -d ./coverage ]; then 7 | mkdir -p ./coverage 8 | fi 9 | 10 | # Update Code Coverage Reports container path with local path 11 | for f in cobertura.xml clover.xml; do 12 | if [ -f "${APP_HOME:-.docker/app}/html/.docker/coverage-phpunit-$f" ]; then 13 | sed -e "s|/usr/src/symfony/src|$(pwd)/app/src|g" "${APP_HOME:-.docker/app}/html/.docker/coverage-phpunit-$f" > "./coverage/coverage-phpunit-$f" 14 | fi 15 | done 16 | 17 | if [ -d "${APP_HOME:-.docker/app}/html/.docker/coverage-phpunit-html" ]; then 18 | cp -r "${APP_HOME:-.docker/app}/html/.docker/coverage-phpunit-html" ./coverage/coverage-phpunit-html 19 | fi 20 | 21 | #echo 'Removing persisted data...' 22 | #rm -rf "${APP_HOME:-.docker/app}" 23 | -------------------------------------------------------------------------------- /hooks/pre_push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | if [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_LOGIN}" ]; then 7 | if [ -n "${DOCKER_REGISTRY}" ]; then 8 | echo "Login to Docker Registry ${DOCKER_REGISTRY}..." 9 | docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" "${DOCKER_REGISTRY}" 10 | else 11 | echo "Login to Docker default Registry..." 12 | docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" 13 | fi 14 | fi 15 | -------------------------------------------------------------------------------- /hooks/pre_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | if [ ! -f '.env' ]; then 7 | echo 'Init docker compose environment variables...' 8 | cp .env_template .env.tmp 9 | 10 | sed -i \ 11 | -e "s|APP_PACKAGE_REPO_LOGIN=.*|APP_PACKAGE_REPO_LOGIN=${PACKAGE_REPO_LOGIN}|" \ 12 | -e "s|APP_PACKAGE_REPO_PASSWORD=.*|APP_PACKAGE_REPO_PASSWORD=${PACKAGE_REPO_PASSWORD}|" \ 13 | .env.tmp 14 | 15 | mv .env.tmp .env 16 | fi 17 | 18 | #echo 'Preparing persisted data...' 19 | #mkdir -p "${APP_HOME:-.docker/app}" 20 | #chmod 777 "${APP_HOME:-.docker/app}" 21 | -------------------------------------------------------------------------------- /hooks/push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | docker push "$IMAGE_NAME" 7 | -------------------------------------------------------------------------------- /hooks/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Custom script to run locally DockerHub hooks 4 | # See documentation for details: 5 | # https://docs.docker.com/docker-hub/builds/advanced/ 6 | 7 | echo "Custom script to run locally DockerHub hooks..." 8 | set -e 9 | 10 | export SOURCE_BRANCH 11 | SOURCE_BRANCH=$(git rev-parse --abbrev-ref HEAD) 12 | export SOURCE_COMMIT 13 | SOURCE_COMMIT=$(git rev-parse --short HEAD) 14 | export COMMIT_MSG 15 | COMMIT_MSG=$(git log -1 --format=%s) 16 | 17 | export VARIANT=${2:-alpine} 18 | 19 | export DOCKER_REPO=${DOCKER_REPO:-monogramm/spring-rest-api-starter} 20 | export DOCKERFILE_PATH=Dockerfile.${VARIANT} 21 | export DOCKER_TAG=${VARIANT} 22 | export DOCKER_TAG=${DOCKER_TAG:-${VARIANT}} 23 | 24 | if [ -n "${DOCKER_REGISTRY}" ]; then 25 | export IMAGE_NAME=${DOCKER_REGISTRY}/${DOCKER_REPO}:${DOCKER_TAG} 26 | else 27 | export IMAGE_NAME=${DOCKER_REPO}:${DOCKER_TAG} 28 | fi 29 | 30 | # Execute hooks in given order 31 | IFS=',' read -ra STEPS <<< "${1:-build,test}" 32 | for step in "${STEPS[@]}" 33 | do 34 | for hook in "pre_${step}" "${step}" "post_${step}"; do 35 | if [ -f "./hooks/${hook}" ]; then 36 | echo "Executing ${hook} hook..." 37 | "./hooks/${hook}" 38 | fi 39 | done 40 | done 41 | 42 | echo "DockerHub hooks finished" 43 | -------------------------------------------------------------------------------- /hooks/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # See documentation for details: 4 | # https://docs.docker.com/docker-hub/builds/advanced/ 5 | 6 | if [ "${DOCKERFILE_PATH}" = "Dockerfile.develop" ] || [ "${DOCKERFILE_PATH}" = "Dockerfile.gitpod" ]; then 7 | echo "No tests (yet) for ${DOCKERFILE_PATH} images." 8 | exit 0 9 | fi 10 | 11 | for file in docker-compose.*.test.yml; do 12 | 13 | echo "Starting Test in ${file}..." 14 | 15 | # Build test container 16 | docker-compose --no-ansi -f "${file}" build sut 17 | # Test container run 18 | docker-compose --no-ansi -f "${file}" up -d && sleep 60 19 | docker-compose --no-ansi -f "${file}" logs -f "sut" 20 | docker-compose --no-ansi -f "${file}" ps 21 | #docker-compose --no-ansi -f "${file}" logs --no-color "app_db" 22 | docker-compose --no-ansi -f "${file}" logs --no-color "app_backend" 23 | docker-compose --no-ansi -f "${file}" ps "sut" | grep "Exit 0" || exit 1 24 | docker-compose --no-ansi -f "${file}" down 25 | 26 | # Test container restart 27 | docker-compose --no-ansi -f "${file}" up -d && sleep 60 28 | docker-compose --no-ansi -f "${file}" logs -f "sut" 29 | docker-compose --no-ansi -f "${file}" ps 30 | #docker-compose --no-ansi -f "${file}" logs --no-color "app_db" 31 | docker-compose --no-ansi -f "${file}" logs --no-color "app_backend" 32 | docker-compose --no-ansi -f "${file}" ps "sut" | grep "Exit 0" || exit 1 33 | docker-compose --no-ansi -f "${file}" down -v 34 | 35 | done 36 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /pmdruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | This ruleset checks my code for bad stuff 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/integration-test/java/com/monogramm/ApplicationIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-08. 3 | */ 4 | 5 | package com.monogramm; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | /** 14 | * {@link Application} Integration Test. 15 | * 16 | *

17 | * Spring boot test is searching @SpringBootConfiguration or @SpringBootApplication. In this case it 18 | * will automatically find {@link Application} boot main class. 19 | *

20 | * 21 | * @author madmath03 22 | */ 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) 25 | @AutoConfigureMockMvc 26 | public class ApplicationIT { 27 | 28 | @Test 29 | public void testContextLoads() throws Exception { 30 | // sanity check 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/integration-test/java/com/monogramm/starter/SmtpServerRule.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter; 2 | 3 | import com.icegreen.greenmail.util.GreenMail; 4 | import com.icegreen.greenmail.util.ServerSetup; 5 | 6 | import javax.mail.internet.MimeMessage; 7 | 8 | import org.junit.rules.ExternalResource; 9 | 10 | public class SmtpServerRule extends ExternalResource { 11 | 12 | private GreenMail smtpServer; 13 | private int port; 14 | 15 | public SmtpServerRule(int port) { 16 | this.port = port; 17 | } 18 | 19 | @Override 20 | protected void before() throws Throwable { 21 | super.before(); 22 | smtpServer = new GreenMail(new ServerSetup(port, null, "smtp")); 23 | smtpServer.start(); 24 | 25 | smtpServer.setUser("username", "secret"); 26 | } 27 | 28 | public MimeMessage[] getMessages() { 29 | return smtpServer.getReceivedMessages(); 30 | } 31 | 32 | @Override 33 | protected void after() { 34 | super.after(); 35 | smtpServer.stop(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/integration-test/resources/log4j2-spring.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The root package of the whole application and all its modules. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/AbstractMailSendingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-22. 3 | */ 4 | 5 | package com.monogramm.starter.api; 6 | 7 | import java.util.Locale; 8 | 9 | import org.springframework.context.ApplicationEvent; 10 | 11 | /** 12 | * AbstractMailSendingEvent. 13 | * 14 | * @author madmath03 15 | */ 16 | public class AbstractMailSendingEvent extends ApplicationEvent { 17 | 18 | /** 19 | * The {@code serialVersionUID}. 20 | */ 21 | private static final long serialVersionUID = 4695942224351346356L; 22 | 23 | private final Locale locale; 24 | private final String appUrl; 25 | 26 | /** 27 | * Create a {@link AbstractMailSendingEvent}. 28 | * 29 | * @param source the source which generated the event. 30 | * @param locale the locale of the registration request. Usually used to define the locale of the 31 | * registration verification. 32 | * @param appUrl the application URL. 33 | */ 34 | protected AbstractMailSendingEvent(T source, Locale locale, String appUrl) { 35 | super(source); 36 | 37 | this.locale = locale; 38 | this.appUrl = appUrl; 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | @Override 43 | public T getSource() { 44 | return (T) super.getSource(); 45 | } 46 | 47 | /** 48 | * Get the {@link #locale}. 49 | * 50 | * @return the {@link #locale}. 51 | */ 52 | public Locale getLocale() { 53 | return locale; 54 | } 55 | 56 | /** 57 | * Get the {@link #appUrl}. 58 | * 59 | * @return the {@link #appUrl}. 60 | */ 61 | public String getAppUrl() { 62 | return appUrl; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/event/AbstractResourceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | package com.monogramm.starter.api.discoverability.event; 6 | 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import org.springframework.context.ApplicationEvent; 10 | 11 | /** 12 | * Abstract resource event. 13 | * 14 | * @see HATEOAS for a Spring 15 | * REST Service 16 | * 17 | * @param Type of the result that is being handled (commonly Entities). 18 | * 19 | * @author madmath03 20 | */ 21 | public class AbstractResourceEvent extends ApplicationEvent { 22 | 23 | /** 24 | * The {@code serialVersionUID}. 25 | */ 26 | private static final long serialVersionUID = 7259844597009552604L; 27 | 28 | private final transient HttpServletResponse response; 29 | 30 | /** 31 | * Create a {@link AbstractResourceEvent}. 32 | * 33 | * @param source source object 34 | * @param response HTTP response 35 | */ 36 | public AbstractResourceEvent(T source, HttpServletResponse response) { 37 | super(source); 38 | 39 | this.response = response; 40 | } 41 | 42 | /** 43 | * Get HTTP response linked to event. 44 | * 45 | * @return HTTP response 46 | */ 47 | public HttpServletResponse getResponse() { 48 | return response; 49 | } 50 | 51 | @Override 52 | public T getSource() { 53 | return (T) super.getSource(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/event/ResourceCreatedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | package com.monogramm.starter.api.discoverability.event; 6 | 7 | import com.monogramm.starter.api.AbstractGenericController; 8 | import com.monogramm.starter.persistence.AbstractGenericEntity; 9 | 10 | import java.util.UUID; 11 | 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * Event that is fired when a resource is created. 16 | * 17 | *

18 | * This event object contains all the information needed to create the URL for the created result. 19 | *

20 | * 21 | * @see AbstractGenericController#addData(org.springframework.security.core.Authentication, 22 | * com.monogramm.starter.dto.AbstractGenericDto, 23 | * org.springframework.web.util.UriComponentsBuilder, HttpServletResponse) 24 | * 25 | * @see HATEOAS for a Spring 26 | * REST Service 27 | * 28 | * @author madmath03 29 | */ 30 | public class ResourceCreatedEvent extends AbstractResourceEvent { 31 | 32 | /** 33 | * The {@code serialVersionUID}. 34 | */ 35 | private static final long serialVersionUID = -5171021604193349716L; 36 | 37 | private final UUID idOfNewResource; 38 | 39 | /** 40 | * Create a {@link ResourceCreatedEvent}. 41 | * 42 | * @param source source object 43 | * @param response HTTP response 44 | * 45 | * @throws NullPointerException if the source is {@code null} 46 | */ 47 | public ResourceCreatedEvent(AbstractGenericEntity source, HttpServletResponse response) { 48 | super(source, response); 49 | 50 | this.idOfNewResource = source.getId(); 51 | } 52 | 53 | /** 54 | * Get the {@link #idOfNewResource}. 55 | * 56 | * @return the {@link #idOfNewResource}. 57 | */ 58 | public final UUID getIdOfNewResource() { 59 | return idOfNewResource; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/event/SingleResourceRetrievedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | package com.monogramm.starter.api.discoverability.event; 6 | 7 | import com.monogramm.starter.api.AbstractGenericController; 8 | import com.monogramm.starter.persistence.AbstractGenericEntity; 9 | 10 | import java.util.UUID; 11 | 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * Event that is fired when a single result is retrieved. 16 | * 17 | *

18 | * This event object contains all the information needed to create the URL for the created result. 19 | *

20 | * 21 | * @see AbstractGenericController#getDataById(String, 22 | * org.springframework.web.context.request.WebRequest, HttpServletResponse) 23 | * 24 | * @see HATEOAS for a Spring 25 | * REST Service 26 | * 27 | * @author madmath03 28 | */ 29 | public class SingleResourceRetrievedEvent extends AbstractResourceEvent { 30 | 31 | /** 32 | * The {@code serialVersionUID}. 33 | */ 34 | private static final long serialVersionUID = 6664275562706082268L; 35 | 36 | private final UUID idOfNewResource; 37 | 38 | /** 39 | * Create a {@link SingleResourceRetrievedEvent}. 40 | * 41 | * @param source source object 42 | * @param response HTTP response 43 | * 44 | * @throws NullPointerException if the source is {@code null} 45 | */ 46 | public SingleResourceRetrievedEvent(AbstractGenericEntity source, HttpServletResponse response) { 47 | super(source, response); 48 | 49 | this.idOfNewResource = source.getId(); 50 | } 51 | 52 | /** 53 | * Get the {@link #idOfNewResource}. 54 | * 55 | * @return the {@link #idOfNewResource}. 56 | */ 57 | public final UUID getIdOfNewResource() { 58 | return idOfNewResource; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/event/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application API discoverability events. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.discoverability.event; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application API discoverability exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.discoverability.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/listener/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application API discoverability listeners. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.discoverability.listener; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application API discoverability functions for satisfying the 7 | * HATEOAS constraint. 8 | * 9 | * @see HATEOAS for a Spring 10 | * REST Service 11 | * 12 | * @author madmath03 13 | */ 14 | package com.monogramm.starter.api.discoverability; 15 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/discoverability/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application API discoverability utilities. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.discoverability.utils; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/media/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias controller. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.media.controller; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/media/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias API. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.media; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/oauth/controller/RevokeTokenEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-23. 3 | */ 4 | 5 | package com.monogramm.starter.api.oauth.controller; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint; 11 | import org.springframework.web.bind.annotation.DeleteMapping; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | /** 15 | * Logout functionality for an OAuth2 Spring Security application. 16 | * 17 | * @see OAuthController 18 | * 19 | * @see Baeldung - Logout in a OAuth 20 | * Secured Application 21 | * 22 | * @author madmath03 23 | */ 24 | @FrameworkEndpoint 25 | public class RevokeTokenEndpoint { 26 | 27 | private static final String TOKEN_HEADER = "Authorization"; 28 | private static final String TOKEN_BEARER = "Bearer"; 29 | 30 | @Autowired 31 | private OAuthController oauthController; 32 | 33 | 34 | /** 35 | * Revoke self access token. 36 | * 37 | *

38 | * Logging out in an OAuth-secured environment involves rendering the user’s Access Token 39 | * invalid – so it can no longer be used. 40 | *

41 | * 42 | *

43 | * In a JdbcTokenStore-based implementation, this means removing the token from the 44 | * TokenStore. 45 | *

46 | * 47 | * @param request Required Parameter: the HTTP request. 48 | */ 49 | @DeleteMapping(value = OAuthController.TOKEN_PATH) 50 | @ResponseBody 51 | public void revokeSelfToken(final HttpServletRequest request) { 52 | final String authorization = request.getHeader(TOKEN_HEADER); 53 | 54 | if (authorization != null && authorization.startsWith(TOKEN_BEARER)) { 55 | final String tmpTokenId = authorization.substring(TOKEN_BEARER.length() + 1); 56 | oauthController.revokeToken(tmpTokenId); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/oauth/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The OAuth controller. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.oauth.controller; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/oauth/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The OAuth API. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.oauth; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The main package of the starter application API. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/parameter/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters controller. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.parameter.controller; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/parameter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters API. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.parameter; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/permission/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions controller. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.permission.controller; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/permission/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions API. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.permission; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/role/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Roles controller. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.role.controller; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/role/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Roles API. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.role; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/type/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Types controller. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.type.controller; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/type/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Types API. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.type; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Users controller. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.user.controller; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/event/OnPasswordResetEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.api.user.event; 6 | 7 | import com.monogramm.starter.api.AbstractMailSendingEvent; 8 | import com.monogramm.starter.api.user.listener.PasswordResetListener; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | 11 | import java.util.Locale; 12 | 13 | /** 14 | * OnPasswordResetEvent. 15 | * 16 | * @see PasswordResetListener 17 | * 18 | * @see Spring 19 | * Security – Reset Your Password 20 | * 21 | * @author madmath03 22 | */ 23 | public class OnPasswordResetEvent extends AbstractMailSendingEvent { 24 | /** 25 | * The {@code serialVersionUID}. 26 | */ 27 | private static final long serialVersionUID = -7114614486625625481L; 28 | 29 | /** 30 | * Create a {@link OnPasswordResetEvent}. 31 | * 32 | * @param user the user which requested a password reset. 33 | * @param locale the locale of the request. Usually used to define the locale of the email. 34 | * @param appUrl the application URL. 35 | */ 36 | public OnPasswordResetEvent(User user, Locale locale, String appUrl) { 37 | super(user, locale, appUrl); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/event/OnRegistrationCompleteEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | package com.monogramm.starter.api.user.event; 6 | 7 | import com.monogramm.starter.api.AbstractMailSendingEvent; 8 | import com.monogramm.starter.api.user.listener.RegistrationListener; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | 11 | import java.util.Locale; 12 | 13 | /** 14 | * OnRegistrationCompleteEvent. 15 | * 16 | * @see RegistrationListener 17 | * 18 | * @see Registration – Activate 19 | * a New User by Email 20 | * 21 | * @author madmath03 22 | */ 23 | public class OnRegistrationCompleteEvent extends AbstractMailSendingEvent { 24 | /** 25 | * The {@code serialVersionUID}. 26 | */ 27 | private static final long serialVersionUID = -7114614486625625481L; 28 | 29 | /** 30 | * Create a {@link OnRegistrationCompleteEvent}. 31 | * 32 | * @param user the user registered. 33 | * @param locale the locale of the registration request. Usually used to define the locale of the 34 | * registration verification. 35 | * @param appUrl the application URL. 36 | */ 37 | public OnRegistrationCompleteEvent(User user, Locale locale, String appUrl) { 38 | super(user, locale, appUrl); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/event/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | /** 6 | * The Users API events. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.user.event; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/listener/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | /** 6 | * The Users API event listeners. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.api.user.listener; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/api/user/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Users API. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.api.user; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/SpringFoxConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by mathieu.brunot the 2018-07-28. 3 | */ 4 | 5 | package com.monogramm.starter.config; 6 | 7 | import java.util.Collections; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.env.Environment; 13 | 14 | import springfox.documentation.builders.PathSelectors; 15 | import springfox.documentation.builders.RequestHandlerSelectors; 16 | import springfox.documentation.service.ApiInfo; 17 | import springfox.documentation.service.Contact; 18 | import springfox.documentation.spi.DocumentationType; 19 | import springfox.documentation.spring.web.plugins.Docket; 20 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 21 | 22 | /** 23 | * SpringFoxConfig. 24 | * 25 | * @author mathieu.brunot 26 | */ 27 | @Configuration 28 | @EnableSwagger2 29 | public class SpringFoxConfig { 30 | 31 | @Autowired 32 | private Environment env; 33 | 34 | @Bean 35 | public Docket apiDocket() { 36 | return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()) 37 | .paths(PathSelectors.any()).build().apiInfo(getApiInfo()); 38 | } 39 | 40 | private ApiInfo getApiInfo() { 41 | final String appName = env.getProperty("info.app.name"); 42 | final String appDescription = env.getProperty("info.app.description"); 43 | final String appVersion = env.getProperty("info.app.version"); 44 | 45 | final String tosUrl = env.getProperty("info.tos.url"); 46 | 47 | final String licenseName = env.getProperty("info.license.name"); 48 | final String licenseUrl = env.getProperty("info.license.url"); 49 | 50 | final String contactName = env.getProperty("info.contact.name"); 51 | final String contactUrl = env.getProperty("info.contact.url"); 52 | final String contactEmail = env.getProperty("info.contact.email"); 53 | 54 | return new ApiInfo(appName + " Documentation", appDescription, appVersion, tosUrl, 55 | new Contact(contactName, contactUrl, contactEmail), licenseName, licenseUrl, 56 | Collections.emptyList()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/component/CustomPasswordEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-23. 3 | */ 4 | 5 | package com.monogramm.starter.config.component; 6 | 7 | import com.github.madmath03.password.Passwords; 8 | 9 | import org.springframework.security.crypto.password.PasswordEncoder; 10 | 11 | /** 12 | * CustomPasswordEncoder. 13 | * 14 | * @author madmath03 15 | */ 16 | public class CustomPasswordEncoder implements PasswordEncoder { 17 | 18 | @Override 19 | public boolean matches(final CharSequence rawPassword, final String encodedPassword) { 20 | return Passwords.isExpectedPassword(rawPassword, encodedPassword); 21 | } 22 | 23 | @Override 24 | public String encode(final CharSequence rawPassword) { 25 | return Passwords.getHash(this.convert(rawPassword)); 26 | } 27 | 28 | /** 29 | * Convert a char sequence to a char array. 30 | * 31 | * @param rawPassword a char sequence to convert. 32 | * 33 | * @return a char array. 34 | */ 35 | private char[] convert(final CharSequence rawPassword) { 36 | final char[] password = new char[rawPassword.length()]; 37 | 38 | for (int i = 0, n = rawPassword.length(); i < n; i++) { 39 | password[i] = rawPassword.charAt(i); 40 | } 41 | 42 | return password; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/component/CustomServletRequestWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-23. 3 | */ 4 | 5 | package com.monogramm.starter.config.component; 6 | 7 | import java.util.Enumeration; 8 | import java.util.Map; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletRequestWrapper; 12 | 13 | import org.springframework.security.web.savedrequest.Enumerator; 14 | 15 | /** 16 | * CustomServletRequestWrapper. 17 | * 18 | * @author madmath03 19 | */ 20 | public class CustomServletRequestWrapper extends HttpServletRequestWrapper { 21 | 22 | private final Map params; 23 | 24 | /** 25 | * Create a {@link CustomServletRequestWrapper}. 26 | * 27 | * @param request The request to wrap. 28 | * @param params The request parameters. 29 | */ 30 | public CustomServletRequestWrapper(final HttpServletRequest request, 31 | final Map params) { 32 | super(request); 33 | 34 | if (params == null) { 35 | this.params = request.getParameterMap(); 36 | } else { 37 | this.params = params; 38 | } 39 | } 40 | 41 | @Override 42 | public String getParameter(String name) { 43 | final String param; 44 | 45 | final String[] value = this.params.get(name); 46 | if (value != null && value.length > 0) { 47 | param = value[0]; 48 | } else { 49 | param = ""; 50 | } 51 | 52 | return param; 53 | } 54 | 55 | @Override 56 | public Map getParameterMap() { 57 | return this.params; 58 | } 59 | 60 | @Override 61 | public Enumeration getParameterNames() { 62 | return new Enumerator<>(params.keySet()); 63 | } 64 | 65 | @Override 66 | public String[] getParameterValues(String name) { 67 | return params.get(name); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/component/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application configuration related components. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.component; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/data/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application initial data. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.data; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/filter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application configuration related filters. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.filter; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/i8n/ApplicationMessage.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.config.i8n; 2 | 3 | import org.springframework.context.MessageSource; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.support.ResourceBundleMessageSource; 7 | 8 | /** 9 | * Application Message configuration. 10 | * 11 | * @author madmath03 12 | * 13 | * @see spring-data-jpa-examples 15 | */ 16 | @Configuration 17 | public class ApplicationMessage { 18 | 19 | private static final String MESSAGE_SOURCE_BASE_NAME = "i18n/messages"; 20 | 21 | /** 22 | * Message source. 23 | * 24 | * @return message source. 25 | */ 26 | @Bean 27 | public MessageSource messageSource() { 28 | final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); 29 | 30 | messageSource.setBasename(MESSAGE_SOURCE_BASE_NAME); 31 | messageSource.setUseCodeAsDefaultMessage(true); 32 | messageSource.setAlwaysUseMessageFormat(true); 33 | 34 | return messageSource; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/i8n/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application internationalization configuration. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.i8n; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The main package of the Spring application configuration. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.config; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/properties/DataProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-29. 3 | */ 4 | 5 | package com.monogramm.starter.config.properties; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | import org.hibernate.validator.constraints.NotBlank; 10 | import org.springframework.boot.context.properties.ConfigurationProperties; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.validation.annotation.Validated; 13 | 14 | /** 15 | * Data Properties. 16 | * 17 | * @see ApplicationProperties 18 | * 19 | * @author madmath03 20 | */ 21 | @Configuration 22 | @ConfigurationProperties(prefix = "application.data") 23 | @Validated 24 | public class DataProperties { 25 | 26 | /** 27 | * {@code application.data.domain_name} property. 28 | */ 29 | @NotBlank 30 | private String domainName = "monogramm.io"; 31 | /** 32 | * {@code application.data.admin_password} property. 33 | */ 34 | private String adminPassword; 35 | 36 | /** 37 | * {@code application.data.demo} property. 38 | */ 39 | @NotNull 40 | private boolean demo = true; 41 | 42 | /** 43 | * Get the {@link #domainName}. 44 | * 45 | * @return the {@link #domainName}. 46 | */ 47 | public String getDomainName() { 48 | return domainName; 49 | } 50 | 51 | /** 52 | * Set the {@link #domainName}. 53 | * 54 | * @param domainName the {@link #domainName} to set. 55 | */ 56 | public void setDomainName(String domainName) { 57 | this.domainName = domainName; 58 | } 59 | 60 | /** 61 | * Get the {@link #adminPassword}. 62 | * 63 | * @return the {@link #adminPassword}. 64 | */ 65 | public String getAdminPassword() { 66 | return adminPassword; 67 | } 68 | 69 | /** 70 | * Set the {@link #adminPassword}. 71 | * 72 | * @param adminPassword the {@link #adminPassword} to set. 73 | */ 74 | public void setAdminPassword(String adminPassword) { 75 | this.adminPassword = adminPassword; 76 | } 77 | 78 | /** 79 | * Get the {@link #demo}. 80 | * 81 | * @return the {@link #demo}. 82 | */ 83 | public boolean isDemo() { 84 | return demo; 85 | } 86 | 87 | /** 88 | * Set the {@link #demo}. 89 | * 90 | * @param demo the {@link #demo} to set. 91 | */ 92 | public void setDemo(boolean demo) { 93 | this.demo = demo; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/properties/EmailProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-30. 3 | */ 4 | 5 | package com.monogramm.starter.config.properties; 6 | 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.validation.annotation.Validated; 10 | 11 | /** 12 | * Email Properties. 13 | * 14 | * @see ApplicationProperties 15 | * 16 | * @author madmath03 17 | */ 18 | @Configuration 19 | @ConfigurationProperties(prefix = "application.email") 20 | @Validated 21 | public class EmailProperties { 22 | 23 | /** 24 | * {@code application.email.no_reply} property. 25 | */ 26 | private String noReply = "no_reply@company.com"; 27 | 28 | /** 29 | * {@code application.email.app_title} property. 30 | */ 31 | private String appTitle = "Application"; 32 | 33 | /** 34 | * Get the {@link #noReply}. 35 | * 36 | * @return the {@link #noReply}. 37 | */ 38 | public String getNoReply() { 39 | return noReply; 40 | } 41 | 42 | /** 43 | * Set the {@link #noReply}. 44 | * 45 | * @param noReply the {@link #noReply} to set. 46 | */ 47 | public void setNoReply(String noReply) { 48 | this.noReply = noReply; 49 | } 50 | 51 | /** 52 | * Get the {@link #appTitle}. 53 | * 54 | * @return the {@link #appTitle}. 55 | */ 56 | public String getAppTitle() { 57 | return appTitle; 58 | } 59 | 60 | /** 61 | * Set the {@link #appTitle}. 62 | * 63 | * @param appTitle the {@link #appTitle} to set. 64 | */ 65 | public void setAppTitle(String appTitle) { 66 | this.appTitle = appTitle; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/properties/WelcomeProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-30. 3 | */ 4 | 5 | package com.monogramm.starter.config.properties; 6 | 7 | import java.nio.file.Path; 8 | 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.validation.annotation.Validated; 12 | 13 | /** 14 | * Welcome Properties. 15 | * 16 | * @see ApplicationProperties 17 | * 18 | * @author madmath03 19 | */ 20 | @Configuration 21 | @ConfigurationProperties(prefix = "application.welcome") 22 | @Validated 23 | public class WelcomeProperties { 24 | 25 | /** 26 | * {@code application.welcome.app_banner} property. 27 | */ 28 | private Path appBanner; 29 | /** 30 | * {@code application.welcome.ascii_art} property. 31 | */ 32 | private String asciiArt; 33 | 34 | /** 35 | * Get the {@link #appBanner}. 36 | * 37 | * @return the {@link #appBanner}. 38 | */ 39 | public Path getAppBanner() { 40 | return appBanner; 41 | } 42 | 43 | /** 44 | * Set the {@link #appBanner}. 45 | * 46 | * @param appBanner the {@link #appBanner} to set. 47 | */ 48 | public void setAppBanner(Path appBanner) { 49 | this.appBanner = appBanner; 50 | } 51 | 52 | /** 53 | * Get the {@link #asciiArt}. 54 | * 55 | * @return the {@link #asciiArt}. 56 | */ 57 | public String getAsciiArt() { 58 | return asciiArt; 59 | } 60 | 61 | /** 62 | * Set the {@link #asciiArt}. 63 | * 64 | * @param asciiArt the {@link #asciiArt} to set. 65 | */ 66 | public void setAsciiArt(String asciiArt) { 67 | this.asciiArt = asciiArt; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/properties/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-29. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application configuration properties. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.properties; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/security/AuthenticationFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-12-29. 3 | */ 4 | 5 | package com.monogramm.starter.config.security; 6 | 7 | import java.util.Set; 8 | 9 | import org.springframework.security.core.Authentication; 10 | import org.springframework.security.core.context.SecurityContextHolder; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * AuthenticationFacade. 15 | * 16 | * @see Retrieve User Information in 17 | * Spring Security 18 | * 19 | * @author madmath03 20 | */ 21 | @Component 22 | public class AuthenticationFacade implements IAuthenticationFacade { 23 | 24 | private Set roles; 25 | private String defaultRolePrefix = DEFAULT_ROLE_PREFIX; 26 | 27 | @Override 28 | public Authentication getAuthentication() { 29 | return SecurityContextHolder.getContext().getAuthentication(); 30 | } 31 | 32 | @Override 33 | public final boolean hasAnyAuthority(String... authorities) { 34 | return hasAnyAuthorityName(null, authorities); 35 | } 36 | 37 | @Override 38 | public final boolean hasAnyRole(String... roles) { 39 | return hasAnyAuthorityName(defaultRolePrefix, roles); 40 | } 41 | 42 | private boolean hasAnyAuthorityName(String prefix, String... roles) { 43 | final Set roleSet = getAuthoritySet(); 44 | 45 | return IAuthenticationFacade.hasAnyAuthorityName(roleSet, prefix, roles); 46 | } 47 | 48 | private Set getAuthoritySet() { 49 | if (roles == null) { 50 | final Authentication authentication = this.getAuthentication(); 51 | 52 | roles = IAuthenticationFacade.getAuthoritySet(authentication); 53 | } 54 | 55 | return roles; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/security/CustomMethodSecurityExpressionHandler.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.config.security; 2 | 3 | import org.aopalliance.intercept.MethodInvocation; 4 | import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; 5 | import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; 6 | import org.springframework.security.authentication.AuthenticationTrustResolver; 7 | import org.springframework.security.authentication.AuthenticationTrustResolverImpl; 8 | import org.springframework.security.core.Authentication; 9 | 10 | /** 11 | * CustomMethodSecurityExpressionHandler. 12 | * 13 | * @see CustomMethodSecurityExpressionRoot 14 | * 15 | * @see A 16 | * Custom Security Expression with Spring Security 17 | * 18 | * @author madmath03 19 | */ 20 | public class CustomMethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler { 21 | 22 | private final AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl(); 23 | 24 | @Override 25 | protected MethodSecurityExpressionOperations createSecurityExpressionRoot( 26 | final Authentication authentication, final MethodInvocation invocation) { 27 | final CustomMethodSecurityExpressionRoot root = 28 | new CustomMethodSecurityExpressionRoot(authentication); 29 | 30 | root.setPermissionEvaluator(getPermissionEvaluator()); 31 | root.setTrustResolver(this.trustResolver); 32 | root.setRoleHierarchy(getRoleHierarchy()); 33 | 34 | return root; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/config/security/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | /** 6 | * The main package of the Spring application security related components. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.config.security; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/media/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.media; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/oauth/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The OAuth related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.oauth; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application Data Transfer Objects. 7 | * 8 | *

9 | * The main purpose of this package is to centralize all the objects needed to interact with the 10 | * API, making it easy to export to a separate project and importing it independently in a Client 11 | * application project. 12 | *

13 | * 14 | * @author madmath03 15 | */ 16 | package com.monogramm.starter.dto; 17 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/parameter/ParameterDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.dto.parameter; 6 | 7 | import com.monogramm.starter.dto.AbstractParameterDto; 8 | 9 | /** 10 | * ParameterDto. 11 | * 12 | * @author madmath03 13 | */ 14 | public class ParameterDto extends AbstractParameterDto { 15 | 16 | /** 17 | * The {@code serialVersionUID}. 18 | */ 19 | private static final long serialVersionUID = 5239222855579699591L; 20 | 21 | /** 22 | * Create a {@link ParameterDto}. 23 | * 24 | */ 25 | public ParameterDto() { 26 | super(); 27 | } 28 | 29 | /** 30 | * Create a copy of a {@link ParameterDto}. 31 | * 32 | * @param other the other DTO to copy. 33 | * 34 | * @throws NullPointerException if the other DTO is {@code null}. 35 | */ 36 | public ParameterDto(ParameterDto other) { 37 | super(other); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/parameter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.parameter; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/permission/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.permission; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/role/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Roles related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.role; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/type/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Types related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.type; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/user/PasswordResetDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.dto.user; 6 | 7 | import com.monogramm.starter.utils.validation.PasswordConfirmationDto; 8 | import com.monogramm.starter.utils.validation.ValidEmail; 9 | 10 | import javax.validation.constraints.NotNull; 11 | 12 | import org.hibernate.validator.constraints.NotEmpty; 13 | 14 | /** 15 | * A password reset Data Transfer Object. 16 | * 17 | *

18 | * This should be used as a base class for a password reset request. 19 | *

20 | * 21 | * @author madmath03 22 | */ 23 | public class PasswordResetDto extends PasswordConfirmationDto { 24 | @ValidEmail 25 | @NotNull 26 | @NotEmpty 27 | private String email = null; 28 | 29 | @NotNull 30 | @NotEmpty 31 | private String token = null; 32 | 33 | /** 34 | * Create a {@link PasswordResetDto}. 35 | * 36 | */ 37 | public PasswordResetDto() { 38 | super(); 39 | } 40 | 41 | /** 42 | * Create a {@link PasswordResetDto}. 43 | * 44 | * @param email the user email. 45 | * @param token the password reset token. 46 | * @param password the password. 47 | * @param matchingPassword the matching password. 48 | */ 49 | public PasswordResetDto(String email, String token, char[] password, char[] matchingPassword) { 50 | super(password, matchingPassword); 51 | 52 | this.email = email; 53 | this.token = token; 54 | } 55 | 56 | /** 57 | * Get the {@link #email}. 58 | * 59 | * @return the {@link #email}. 60 | */ 61 | public final String getEmail() { 62 | return email; 63 | } 64 | 65 | /** 66 | * Set the {@link #email}. 67 | * 68 | * @param email the {@link #email} to set. 69 | */ 70 | public final void setEmail(String email) { 71 | this.email = email; 72 | } 73 | 74 | /** 75 | * Get the {@link #token}. 76 | * 77 | * @return the {@link #token}. 78 | */ 79 | public final String getToken() { 80 | return token; 81 | } 82 | 83 | /** 84 | * Set the {@link #token}. 85 | * 86 | * @param token the {@link #token} to set. 87 | */ 88 | public final void setToken(String token) { 89 | this.token = token; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/user/PasswordResetTokenDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.dto.user; 6 | 7 | import com.monogramm.starter.dto.AbstractTokenDto; 8 | 9 | /** 10 | * PasswordResetTokenDto. 11 | * 12 | * @author madmath03 13 | */ 14 | public class PasswordResetTokenDto extends AbstractTokenDto { 15 | /** 16 | * The {@code serialVersionUID}. 17 | */ 18 | private static final long serialVersionUID = 2662064376632153095L; 19 | 20 | /** 21 | * Create a {@link PasswordResetTokenDto}. 22 | * 23 | */ 24 | public PasswordResetTokenDto() { 25 | super(); 26 | } 27 | 28 | /** 29 | * Create a copy of a {@link PasswordResetTokenDto}. 30 | * 31 | * @param other the other {@link PasswordResetTokenDto} to copy. 32 | */ 33 | public PasswordResetTokenDto(PasswordResetTokenDto other) { 34 | super(other); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/user/RegistrationDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-09. 3 | */ 4 | 5 | package com.monogramm.starter.dto.user; 6 | 7 | import com.monogramm.starter.utils.validation.PasswordConfirmationDto; 8 | import com.monogramm.starter.utils.validation.ValidEmail; 9 | 10 | import javax.validation.constraints.NotNull; 11 | 12 | import org.hibernate.validator.constraints.NotEmpty; 13 | 14 | /** 15 | * A registration Data Transfer Object. 16 | * 17 | *

18 | * This should be used as a base class for a registration request. 19 | *

20 | * 21 | * @author madmath03 22 | */ 23 | public class RegistrationDto extends PasswordConfirmationDto { 24 | @NotNull 25 | @NotEmpty 26 | private String username = null; 27 | 28 | @ValidEmail 29 | @NotNull 30 | @NotEmpty 31 | private String email = null; 32 | 33 | /** 34 | * Create a {@link RegistrationDto}. 35 | */ 36 | public RegistrationDto() { 37 | super(); 38 | } 39 | 40 | /** 41 | * Create a {@link RegistrationDto}. 42 | * 43 | * @param username the registration username. 44 | * @param email the registration email. 45 | * @param password the password. 46 | * @param matchingPassword the matching password. 47 | * 48 | * @throws NullPointerException if {@code password} or {@code matchingPassword} is {@code null}. 49 | */ 50 | public RegistrationDto(final String username, final String email, final char[] password, 51 | final char[] matchingPassword) { 52 | super(password, matchingPassword); 53 | this.username = username; 54 | this.email = email; 55 | } 56 | 57 | /** 58 | * Get the {@link #username}. 59 | * 60 | * @return the {@link #username}. 61 | */ 62 | public final String getUsername() { 63 | return username; 64 | } 65 | 66 | /** 67 | * Set the {@link username}. 68 | * 69 | * @param username the {@link #username} to set. 70 | */ 71 | public final void setUsername(final String username) { 72 | this.username = username; 73 | } 74 | 75 | /** 76 | * Get the {@link #email}. 77 | * 78 | * @return the {@link #email}. 79 | */ 80 | public final String getEmail() { 81 | return email; 82 | } 83 | 84 | /** 85 | * Set the {@link email}. 86 | * 87 | * @param email the {@link #email} to set. 88 | */ 89 | public final void setEmail(final String email) { 90 | this.email = email; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/dto/user/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Users related DTOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.dto.user; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The root package of the starter application. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/AbstractParameterBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence; 6 | 7 | import com.monogramm.starter.dto.AbstractParameterDto; 8 | import com.monogramm.starter.persistence.user.dao.UserRepository; 9 | 10 | /** 11 | * AbstractParameterBridge. 12 | * 13 | * @author madmath03 14 | */ 15 | public abstract class AbstractParameterBridge extends AbstractGenericBridge { 17 | 18 | /** 19 | * Create a {@link AbstractParameterBridge}. 20 | * 21 | */ 22 | protected AbstractParameterBridge() { 23 | super(); 24 | } 25 | 26 | /** 27 | * Create a {@link AbstractParameterBridge}. 28 | * 29 | * @param userRepository repository to lookup users. 30 | */ 31 | public AbstractParameterBridge(UserRepository userRepository) { 32 | super(userRepository); 33 | } 34 | 35 | @Override 36 | public T toEntity(final D dto) { 37 | final T entity = super.toEntity(dto); 38 | 39 | entity.setName(dto.getName()); 40 | entity.setDescription(dto.getDescription()); 41 | if (dto.getType() != null) { 42 | entity.setType(ParameterType.valueOf(dto.getType().toUpperCase())); 43 | } 44 | entity.setValue(dto.getValue()); 45 | 46 | return entity; 47 | } 48 | 49 | @Override 50 | public D toDto(final T entity) { 51 | final D dto = super.toDto(entity); 52 | 53 | dto.setName(entity.getName()); 54 | dto.setDescription(entity.getDescription()); 55 | if (entity.getType() != null) { 56 | dto.setType(entity.getType().toString()); 57 | } 58 | dto.setValue(entity.getValue()); 59 | 60 | return dto; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/AbstractTokenBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence; 6 | 7 | import com.monogramm.starter.dto.AbstractTokenDto; 8 | import com.monogramm.starter.persistence.user.dao.UserRepository; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | 11 | /** 12 | * AbstractTokenBridge. 13 | * 14 | * @author madmath03 15 | */ 16 | public abstract class AbstractTokenBridge extends AbstractGenericBridge { 18 | 19 | /** 20 | * Create a {@link AbstractTokenBridge}. 21 | * 22 | */ 23 | protected AbstractTokenBridge() { 24 | super(); 25 | } 26 | 27 | /** 28 | * Create a {@link AbstractTokenBridge}. 29 | * 30 | * @param userRepository repository to lookup users. 31 | */ 32 | public AbstractTokenBridge(UserRepository userRepository) { 33 | super(userRepository); 34 | } 35 | 36 | @Override 37 | public T toEntity(final D dto) { 38 | final T entity = super.toEntity(dto); 39 | 40 | entity.setCode(dto.getCode()); 41 | entity.setExpiryDate(dto.getExpiryDate()); 42 | 43 | if (dto.getUser() != null) { 44 | final User user; 45 | if (getUserRepository() == null) { 46 | user = User.builder().id(dto.getUser()).build(); 47 | } else { 48 | user = this.getUserRepository().findById(dto.getUser()); 49 | } 50 | entity.setUser(user); 51 | } 52 | 53 | return entity; 54 | } 55 | 56 | @Override 57 | public D toDto(final T entity) { 58 | final D dto = super.toDto(entity); 59 | 60 | dto.setCode(entity.getCode()); 61 | dto.setExpiryDate(entity.getExpiryDate()); 62 | 63 | if (entity.getUser() != null) { 64 | dto.setUser(entity.getUser().getId()); 65 | } 66 | 67 | return dto; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/EntityNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | package com.monogramm.starter.persistence; 6 | 7 | /** 8 | * "{@link AbstractGenericEntity} not found" Exception. 9 | * 10 | * @author madmath03 11 | */ 12 | public abstract class EntityNotFoundException extends RuntimeException { 13 | 14 | /** 15 | * The {@code serialVersionUID}. 16 | */ 17 | private static final long serialVersionUID = 2016265732131475104L; 18 | 19 | /** 20 | * Create a {@link EntityNotFoundException}. 21 | * 22 | */ 23 | public EntityNotFoundException() { 24 | super(); 25 | } 26 | 27 | /** 28 | * Create a {@link EntityNotFoundException}. 29 | * 30 | * @param message the detail message. 31 | */ 32 | public EntityNotFoundException(String message) { 33 | super(message); 34 | } 35 | 36 | /** 37 | * Create a {@link EntityNotFoundException}. 38 | * 39 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 40 | * nonexistent or unknown.) 41 | */ 42 | public EntityNotFoundException(Throwable cause) { 43 | super(cause); 44 | } 45 | 46 | /** 47 | * Create a {@link EntityNotFoundException}. 48 | * 49 | * @param message the detail message. 50 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 51 | * nonexistent or unknown.) 52 | */ 53 | public EntityNotFoundException(String message, Throwable cause) { 54 | super(message, cause); 55 | } 56 | 57 | /** 58 | * Create a {@link EntityNotFoundException}. 59 | * 60 | * @param message the detail message. 61 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 62 | * nonexistent or unknown.) 63 | * @param enableSuppression whether or not suppression is enabled or disabled 64 | * @param writableStackTrace whether or not the stack trace should be writable 65 | */ 66 | public EntityNotFoundException(String message, Throwable cause, boolean enableSuppression, 67 | boolean writableStackTrace) { 68 | super(message, cause, enableSuppression, writableStackTrace); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/dao/MediaRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.media.dao; 6 | 7 | import com.monogramm.starter.persistence.GenericRepository; 8 | import com.monogramm.starter.persistence.media.entity.Media; 9 | 10 | import java.util.List; 11 | import java.util.UUID; 12 | 13 | import javax.persistence.NoResultException; 14 | import javax.persistence.NonUniqueResultException; 15 | 16 | import org.springframework.data.jpa.repository.Query; 17 | import org.springframework.data.repository.query.Param; 18 | import org.springframework.stereotype.Repository; 19 | 20 | /** 21 | * The {@link Media} Data Access Object (DAO) interface. 22 | * 23 | * @author madmath03 24 | */ 25 | @Repository 26 | public interface MediaRepository extends GenericRepository { 27 | 28 | /** 29 | * Find all Medias from the repository containing the name while ignoring case. 30 | * 31 | * @param name the name content to search. 32 | * 33 | * @return the list of all the Medias matching the search through the repository. 34 | */ 35 | @Query("FROM Media AS m " + "WHERE LOWER(m.name) LIKE concat('%', LOWER(:name), '%')") 36 | List findAllContainingNameIgnoreCase(@Param("name") final String name); 37 | 38 | /** 39 | * Find an Media through its name while ignoring case. 40 | * 41 | * @param name the name to search. 42 | * 43 | * @return the Media matching the name. 44 | * 45 | * @throws NoResultException if no Media matches the name in the repository. 46 | * @throws NonUniqueResultException if several Medias match the name in the repository. 47 | */ 48 | Media findByNameIgnoreCase(final String name); 49 | 50 | /** 51 | * Tests if an entity exists in the repository for the given primary key or the name. 52 | * 53 | * @param mediaId the identifier of the Media to check existence. 54 | * @param name the name of the Media to check existence. 55 | * 56 | * @return {@code true} if Media exists, {@code false} otherwise. 57 | */ 58 | @Query("SELECT count(m) > 0 FROM Media AS m " 59 | + "WHERE m.id = :MediaId OR LOWER(m.name) = LOWER(:name)") 60 | boolean exists(@Param("MediaId") final UUID mediaId, @Param("name") final String name); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias Data Access Objects. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media.dao; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias entity. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media.entity; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/exception/MediaNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.media.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.media.entity.Media; 9 | 10 | /** 11 | * "{@link Media} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class MediaNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = -856246176128256794L; 21 | 22 | /** 23 | * Create a {@link MediaNotFoundException}. 24 | * 25 | */ 26 | public MediaNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link MediaNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public MediaNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link MediaNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public MediaNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link MediaNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public MediaNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link MediaNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public MediaNotFoundException(String message, Throwable cause, boolean enableSuppression, 70 | boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/properties/FileStorageProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.media.properties; 6 | 7 | import com.monogramm.starter.config.properties.ApplicationProperties; 8 | 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | 12 | import org.springframework.boot.context.properties.ConfigurationProperties; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.validation.annotation.Validated; 15 | 16 | /** 17 | * File Storage Properties. 18 | * 19 | * @see ApplicationProperties 20 | * 21 | * @see Spring Boot 23 | * File Upload / Download Rest API Example 24 | * 25 | * @author madmath03 26 | */ 27 | @Configuration 28 | @ConfigurationProperties(prefix = "application.file") 29 | @Validated 30 | public class FileStorageProperties { 31 | 32 | /** 33 | * {@code application.file.upload_dir} property. 34 | */ 35 | private Path uploadDir; 36 | 37 | /** 38 | * Create a {@link FileStorageProperties}. 39 | * 40 | */ 41 | public FileStorageProperties() { 42 | super(); 43 | } 44 | 45 | /** 46 | * Create a {@link FileStorageProperties}. 47 | * 48 | * @param uploadDir the upload directory 49 | */ 50 | public FileStorageProperties(Path uploadDir) { 51 | super(); 52 | 53 | this.uploadDir = uploadDir; 54 | } 55 | 56 | /** 57 | * Create a {@link FileStorageProperties}. 58 | * 59 | * @param uploadDir the upload directory 60 | */ 61 | public FileStorageProperties(String uploadDir) { 62 | this(Paths.get(uploadDir)); 63 | } 64 | 65 | /** 66 | * Get the media upload directory. 67 | * 68 | * @return the upload directory. 69 | */ 70 | public Path getUploadDir() { 71 | return uploadDir; 72 | } 73 | 74 | /** 75 | * Set the upload directory. 76 | * 77 | * @param uploadDir the {@link #uploadDir} to set. 78 | */ 79 | public void setUploadDir(Path uploadDir) { 80 | this.uploadDir = uploadDir; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/properties/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias related configuration properties. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media.properties; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/media/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-24. 3 | */ 4 | 5 | /** 6 | * The Medias service. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.media.service; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/oauth/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-20. 3 | */ 4 | 5 | /** 6 | * The OAuth related DAOs. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.oauth.dao; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/oauth/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-20. 3 | */ 4 | 5 | /** 6 | * The OAuth related entities. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.oauth.entity; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/oauth/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The OAuth Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.oauth; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/oauth/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-09. 3 | */ 4 | 5 | /** 6 | * The OAuth related services. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.oauth.service; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application Persistence mechanisms. 7 | * 8 | *

9 | * The main purpose of this package is to centralize all the objects needed to interact with a 10 | * Persistence Storage, making it easy to export to a separate project and importing it 11 | * independently in a Batch project. 12 | *

13 | * 14 | * @author madmath03 15 | */ 16 | package com.monogramm.starter.persistence; 17 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/dao/ParameterRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.dao; 6 | 7 | import com.monogramm.starter.persistence.GenericRepository; 8 | import com.monogramm.starter.persistence.parameter.entity.Parameter; 9 | 10 | import java.util.UUID; 11 | 12 | import javax.persistence.NoResultException; 13 | import javax.persistence.NonUniqueResultException; 14 | 15 | import org.springframework.data.jpa.repository.Query; 16 | import org.springframework.data.repository.query.Param; 17 | import org.springframework.stereotype.Repository; 18 | 19 | /** 20 | * The {@link Parameter} Data Access Object (DAO) interface. 21 | * 22 | * @author madmath03 23 | */ 24 | @Repository 25 | public interface ParameterRepository extends GenericRepository { 26 | 27 | /** 28 | * Find a parameter through its name while ignoring case. 29 | * 30 | * @param name the name to search. 31 | * 32 | * @return the parameter matching the name. 33 | * 34 | * @throws NoResultException if no parameter matches the name in the repository. 35 | * @throws NonUniqueResultException if several parameters match the name in the repository. 36 | */ 37 | Parameter findByNameIgnoreCase(final String name); 38 | 39 | /** 40 | * Tests if an entity exists in the repository for the given primary key or the name. 41 | * 42 | * @param id the identifier of the parameter to check existence. 43 | * @param name the name of the parameter to check existence. 44 | * 45 | * @return {@code true} if parameter exists, {@code false} otherwise. 46 | */ 47 | @Query("SELECT count(p) > 0 FROM Parameter AS p " 48 | + "WHERE p.id = :id OR LOWER(p.name) = LOWER(:name)") 49 | boolean exists(@Param("id") final UUID id, @Param("name") final String name); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters Data Access Objects. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.parameter.dao; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters entity. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.parameter.entity; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/exception/ParameterNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.parameter.entity.Parameter; 9 | 10 | /** 11 | * "{@link Parameter} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class ParameterNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = 5143585822244266125L; 21 | 22 | /** 23 | * Create a {@link ParameterNotFoundException}. 24 | * 25 | */ 26 | public ParameterNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link ParameterNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public ParameterNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link ParameterNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public ParameterNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link ParameterNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public ParameterNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link ParameterNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public ParameterNotFoundException(String message, Throwable cause, boolean enableSuppression, 70 | boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.parameter.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.parameter; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/service/ParameterBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.service; 6 | 7 | import com.monogramm.starter.dto.parameter.ParameterDto; 8 | import com.monogramm.starter.persistence.AbstractParameterBridge; 9 | import com.monogramm.starter.persistence.parameter.entity.Parameter; 10 | import com.monogramm.starter.persistence.user.dao.UserRepository; 11 | 12 | /** 13 | * ParameterBridge. 14 | * 15 | * @author madmath03 16 | */ 17 | public class ParameterBridge extends AbstractParameterBridge { 18 | 19 | /** 20 | * Create a {@link ParameterBridge}. 21 | * 22 | */ 23 | public ParameterBridge() { 24 | super(); 25 | } 26 | 27 | /** 28 | * Create a {@link ParameterBridge}. 29 | * 30 | * @param userRepository repository to lookup users. 31 | */ 32 | public ParameterBridge(UserRepository userRepository) { 33 | super(userRepository); 34 | } 35 | 36 | @Override 37 | protected Parameter buildEntity() { 38 | return new Parameter(); 39 | } 40 | 41 | @Override 42 | protected ParameterDto buildDto() { 43 | return new ParameterDto(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/service/ParameterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.service; 6 | 7 | import com.monogramm.starter.dto.parameter.ParameterDto; 8 | import com.monogramm.starter.persistence.GenericService; 9 | import com.monogramm.starter.persistence.parameter.entity.Parameter; 10 | import com.monogramm.starter.persistence.parameter.exception.ParameterNotFoundException; 11 | 12 | /** 13 | * {@link Parameter} service interface. 14 | * 15 | * @author madmath03 16 | */ 17 | public interface ParameterService extends GenericService { 18 | 19 | @Override 20 | ParameterBridge getBridge(); 21 | 22 | /** 23 | * Find an parameter through its name while ignoring case. 24 | * 25 | * @param name the name to search. 26 | * 27 | * @return the parameter matching the name. 28 | * 29 | * @throws ParameterNotFoundException if no parameter matches the name in the repository. 30 | */ 31 | Parameter findByName(final String name); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/parameter/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | /** 6 | * The Parameters service. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.parameter.service; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions Data Access Objects. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.permission.dao; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions entity. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.permission.entity; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/exception/PermissionNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | package com.monogramm.starter.persistence.permission.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.permission.entity.Permission; 9 | 10 | /** 11 | * "{@link Permission} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class PermissionNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = 4331389591826563678L; 21 | 22 | /** 23 | * Create a {@link PermissionNotFoundException}. 24 | * 25 | */ 26 | public PermissionNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link PermissionNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public PermissionNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link PermissionNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public PermissionNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link PermissionNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public PermissionNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link PermissionNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public PermissionNotFoundException(String message, Throwable cause, 70 | boolean enableSuppression, boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.permission.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | /** 6 | * The Permissions Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.permission; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/service/PermissionBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | package com.monogramm.starter.persistence.permission.service; 6 | 7 | import com.monogramm.starter.dto.permission.PermissionDto; 8 | import com.monogramm.starter.persistence.AbstractGenericBridge; 9 | import com.monogramm.starter.persistence.permission.entity.Permission; 10 | import com.monogramm.starter.persistence.user.dao.UserRepository; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | 14 | /** 15 | * Bridge to convert a {@link PermissionDto} to a {@link Permission} and vice versa. 16 | * 17 | * @author madmath03 18 | */ 19 | public class PermissionBridge extends AbstractGenericBridge { 20 | 21 | /** 22 | * Create a {@link PermissionBridge}. 23 | * 24 | *

25 | * Use with caution: this constructor will not set the @{code userRepository}, 26 | * preventing any search in the Persistence Storage for the relations objects. This might be 27 | * dangerous when converting {@link #toEntity(PermissionDto)} as no consistency check will be done 28 | * but it will definitely improve performance. 29 | *

30 | * 31 | */ 32 | public PermissionBridge() { 33 | super(); 34 | } 35 | 36 | /** 37 | * Create a {@link PermissionBridge}. 38 | * 39 | * @param userRepository repository to lookup users. 40 | */ 41 | @Autowired 42 | public PermissionBridge(UserRepository userRepository) { 43 | super(userRepository); 44 | } 45 | 46 | @Override 47 | protected Permission buildEntity() { 48 | return new Permission(); 49 | } 50 | 51 | @Override 52 | protected PermissionDto buildDto() { 53 | return new PermissionDto(); 54 | } 55 | 56 | @Override 57 | public Permission toEntity(final PermissionDto dto) { 58 | final Permission entity = super.toEntity(dto); 59 | 60 | entity.setName(dto.getName()); 61 | 62 | return entity; 63 | } 64 | 65 | @Override 66 | public PermissionDto toDto(final Permission entity) { 67 | final PermissionDto dto = super.toDto(entity); 68 | 69 | dto.setName(entity.getName()); 70 | 71 | return dto; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/service/PermissionService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | package com.monogramm.starter.persistence.permission.service; 6 | 7 | import com.monogramm.starter.dto.permission.PermissionDto; 8 | import com.monogramm.starter.persistence.GenericService; 9 | import com.monogramm.starter.persistence.permission.entity.Permission; 10 | import com.monogramm.starter.persistence.permission.exception.PermissionNotFoundException; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * {@link Permission} service interface. 16 | * 17 | * @author madmath03 18 | */ 19 | public interface PermissionService extends GenericService { 20 | 21 | @Override 22 | PermissionBridge getBridge(); 23 | 24 | /** 25 | * Find all permissions by their name while ignoring case. 26 | * 27 | * @param name the name content to search. 28 | * 29 | * @return the list of all the permissions matching the search. 30 | */ 31 | List findAllByName(final String name); 32 | 33 | /** 34 | * Find an permission through its name while ignoring case. 35 | * 36 | * @param name the name to search. 37 | * 38 | * @return the permission matching the name. 39 | * 40 | * @throws PermissionNotFoundException if no permission matches the name in the repository. 41 | */ 42 | Permission findByName(final String name); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/permission/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Permissions service. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.permission.service; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/dao/RoleRepository.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.persistence.role.dao; 2 | 3 | import com.monogramm.starter.persistence.GenericRepository; 4 | import com.monogramm.starter.persistence.role.entity.Role; 5 | 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | import javax.persistence.NoResultException; 10 | import javax.persistence.NonUniqueResultException; 11 | 12 | import org.springframework.data.jpa.repository.Query; 13 | import org.springframework.data.repository.query.Param; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * The {@link Role} Data Access Object (DAO) interface. 18 | * 19 | * @author madmath03 20 | */ 21 | @Repository 22 | public interface RoleRepository extends GenericRepository { 23 | 24 | /** 25 | * Find all roles from the repository containing the name while ignoring case. 26 | * 27 | * @param name the name content to search. 28 | * 29 | * @return the list of all the roles matching the search through the repository. 30 | */ 31 | @Query("FROM Role AS r " + "WHERE LOWER(r.name) LIKE concat('%', LOWER(:name), '%')") 32 | List findAllContainingNameIgnoreCase(@Param("name") final String name); 33 | 34 | /** 35 | * Find an role through its name while ignoring case. 36 | * 37 | * @param name the name to search. 38 | * 39 | * @return the role matching the name. 40 | * 41 | * @throws NoResultException if no role matches the name in the repository. 42 | * @throws NonUniqueResultException if several roles match the name in the repository. 43 | */ 44 | Role findByNameIgnoreCase(final String name); 45 | 46 | /** 47 | * Tests if an entity exists in the repository for the given primary key or the name. 48 | * 49 | * @param roleId the identifier of the role to check existence. 50 | * @param name the name of the role to check existence. 51 | * 52 | * @return {@code true} if role exists, {@code false} otherwise. 53 | */ 54 | @Query("SELECT count(r) > 0 FROM Role AS r " 55 | + "WHERE r.id = :roleId OR LOWER(r.name) = LOWER(:name)") 56 | boolean exists(@Param("roleId") final UUID roleId, @Param("name") final String name); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Roles Data Access Objects. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.role.dao; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Roles entity. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.role.entity; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/exception/RoleNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.role.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.role.entity.Role; 9 | 10 | /** 11 | * "{@link Role} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class RoleNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = 4331389591826563678L; 21 | 22 | /** 23 | * Create a {@link RoleNotFoundException}. 24 | * 25 | */ 26 | public RoleNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link RoleNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public RoleNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link RoleNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public RoleNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link RoleNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public RoleNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link RoleNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public RoleNotFoundException(String message, Throwable cause, 70 | boolean enableSuppression, boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | /** 6 | * The Roles exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.role.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Roles Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.role; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.persistence.role.service; 2 | 3 | import com.monogramm.starter.dto.role.RoleDto; 4 | import com.monogramm.starter.persistence.GenericService; 5 | import com.monogramm.starter.persistence.role.entity.Role; 6 | import com.monogramm.starter.persistence.role.exception.RoleNotFoundException; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * {@link Role} service interface. 12 | * 13 | * @author madmath03 14 | */ 15 | public interface RoleService extends GenericService { 16 | 17 | @Override 18 | RoleBridge getBridge(); 19 | 20 | /** 21 | * Find all roles by their name while ignoring case. 22 | * 23 | * @param name the name content to search. 24 | * 25 | * @return the list of all the roles matching the search. 26 | */ 27 | List findAllByName(final String name); 28 | 29 | /** 30 | * Find an role through its name while ignoring case. 31 | * 32 | * @param name the name to search. 33 | * 34 | * @return the role matching the name. 35 | * 36 | * @throws RoleNotFoundException if no role matches the name in the repository. 37 | */ 38 | Role findByName(final String name); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/role/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Roles service. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.role.service; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/dao/TypeRepository.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.persistence.type.dao; 2 | 3 | import com.monogramm.starter.persistence.GenericRepository; 4 | import com.monogramm.starter.persistence.type.entity.Type; 5 | 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | import javax.persistence.NoResultException; 10 | import javax.persistence.NonUniqueResultException; 11 | 12 | import org.springframework.data.jpa.repository.Query; 13 | import org.springframework.data.repository.query.Param; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * The {@link Type} Data Access Object (DAO) interface. 18 | * 19 | * @author madmath03 20 | */ 21 | @Repository 22 | public interface TypeRepository extends GenericRepository { 23 | 24 | /** 25 | * Find all types from the repository containing the name while ignoring case. 26 | * 27 | * @param name the name content to search. 28 | * 29 | * @return the list of all the types matching the search through the repository. 30 | */ 31 | @Query("FROM Type AS t " + "WHERE LOWER(t.name) LIKE concat('%', LOWER(:name), '%')") 32 | List findAllContainingNameIgnoreCase(@Param("name") final String name); 33 | 34 | /** 35 | * Find an type through its name while ignoring case. 36 | * 37 | * @param name the name to search. 38 | * 39 | * @return the type matching the name. 40 | * 41 | * @throws NoResultException if no type matches the name in the repository. 42 | * @throws NonUniqueResultException if several types match the name in the repository. 43 | */ 44 | Type findByNameIgnoreCase(final String name); 45 | 46 | /** 47 | * Tests if an entity exists in the repository for the given primary key or the name. 48 | * 49 | * @param typeId the identifier of the type to check existence. 50 | * @param name the name of the type to check existence. 51 | * 52 | * @return {@code true} if type exists, {@code false} otherwise. 53 | */ 54 | @Query("SELECT count(t) > 0 FROM Type AS t " 55 | + "WHERE t.id = :typeId OR LOWER(t.name) = LOWER(:name)") 56 | boolean exists(@Param("typeId") final UUID typeId, @Param("name") final String name); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Types Data Access Objects. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.type.dao; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Types entity. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.type.entity; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/exception/TypeNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.type.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.type.entity.Type; 9 | 10 | /** 11 | * "{@link Type} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class TypeNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = 4331389591826563678L; 21 | 22 | /** 23 | * Create a {@link TypeNotFoundException}. 24 | * 25 | */ 26 | public TypeNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link TypeNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public TypeNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link TypeNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public TypeNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link TypeNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public TypeNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link TypeNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public TypeNotFoundException(String message, Throwable cause, 70 | boolean enableSuppression, boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | /** 6 | * The Types exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.type.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Types Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.type; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/service/TypeBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.type.service; 6 | 7 | import com.monogramm.starter.dto.type.TypeDto; 8 | import com.monogramm.starter.persistence.AbstractGenericBridge; 9 | import com.monogramm.starter.persistence.type.entity.Type; 10 | import com.monogramm.starter.persistence.user.dao.UserRepository; 11 | 12 | /** 13 | * Bridge to convert a {@link TypeDto} to a {@link Type} and vice versa. 14 | * 15 | * @author madmath03 16 | */ 17 | public class TypeBridge extends AbstractGenericBridge { 18 | 19 | /** 20 | * Create a {@link TypeBridge}. 21 | * 22 | *

23 | * Use with caution: this constructor will not set the @{code userRepository}, 24 | * preventing any search in the Persistence Storage for the relations objects. This might be 25 | * dangerous when converting {@link #toEntity(TypeDto)} as no consistency check will be done but 26 | * it will definitely improve performance. 27 | *

28 | * 29 | */ 30 | public TypeBridge() { 31 | super(); 32 | } 33 | 34 | /** 35 | * Create a {@link TypeBridge}. 36 | * 37 | * @param userRepository repository to lookup users. 38 | */ 39 | public TypeBridge(UserRepository userRepository) { 40 | super(userRepository); 41 | } 42 | 43 | @Override 44 | protected Type buildEntity() { 45 | return new Type(); 46 | } 47 | 48 | @Override 49 | protected TypeDto buildDto() { 50 | return new TypeDto(); 51 | } 52 | 53 | @Override 54 | public Type toEntity(final TypeDto dto) { 55 | final Type entity = super.toEntity(dto); 56 | 57 | entity.setName(dto.getName()); 58 | 59 | return entity; 60 | } 61 | 62 | @Override 63 | public TypeDto toDto(final Type entity) { 64 | final TypeDto dto = super.toDto(entity); 65 | 66 | dto.setName(entity.getName()); 67 | 68 | return dto; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/service/TypeService.java: -------------------------------------------------------------------------------- 1 | package com.monogramm.starter.persistence.type.service; 2 | 3 | import com.monogramm.starter.dto.type.TypeDto; 4 | import com.monogramm.starter.persistence.GenericService; 5 | import com.monogramm.starter.persistence.type.entity.Type; 6 | import com.monogramm.starter.persistence.type.exception.TypeNotFoundException; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * {@link Type} service interface. 12 | * 13 | * @author madmath03 14 | */ 15 | public interface TypeService extends GenericService { 16 | 17 | @Override 18 | TypeBridge getBridge(); 19 | 20 | /** 21 | * Find all types by their name while ignoring case. 22 | * 23 | * @param name the name content to search. 24 | * 25 | * @return the list of all the types matching the search. 26 | */ 27 | List findAllByName(final String name); 28 | 29 | /** 30 | * Find an type through its name while ignoring case. 31 | * 32 | * @param name the name to search. 33 | * 34 | * @return the type matching the name. 35 | * 36 | * @throws TypeNotFoundException if no type matches the name in the repository. 37 | */ 38 | Type findByName(final String name); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/type/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Types service. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.type.service; -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/dao/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Users Data Access Objects. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.user.dao; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Users entity. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.user.entity; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/exception/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.exception; 6 | 7 | import com.monogramm.starter.persistence.EntityNotFoundException; 8 | import com.monogramm.starter.persistence.user.entity.User; 9 | 10 | /** 11 | * "{@link User} not found" Exception. 12 | * 13 | * @author madmath03 14 | */ 15 | public class UserNotFoundException extends EntityNotFoundException { 16 | 17 | /** 18 | * The {@code serialVersionUID}. 19 | */ 20 | private static final long serialVersionUID = -5718978633699801683L; 21 | 22 | /** 23 | * Create a {@link UserNotFoundException}. 24 | * 25 | */ 26 | public UserNotFoundException() { 27 | super(); 28 | } 29 | 30 | /** 31 | * Create a {@link UserNotFoundException}. 32 | * 33 | * @param message the detail message. 34 | */ 35 | public UserNotFoundException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Create a {@link UserNotFoundException}. 41 | * 42 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 43 | * nonexistent or unknown.) 44 | */ 45 | public UserNotFoundException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | /** 50 | * Create a {@link UserNotFoundException}. 51 | * 52 | * @param message the detail message. 53 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 54 | * nonexistent or unknown.) 55 | */ 56 | public UserNotFoundException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Create a {@link UserNotFoundException}. 62 | * 63 | * @param message the detail message. 64 | * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is 65 | * nonexistent or unknown.) 66 | * @param enableSuppression whether or not suppression is enabled or disabled 67 | * @param writableStackTrace whether or not the stack trace should be writable 68 | */ 69 | public UserNotFoundException(String message, Throwable cause, 70 | boolean enableSuppression, boolean writableStackTrace) { 71 | super(message, cause, enableSuppression, writableStackTrace); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-09-03. 3 | */ 4 | 5 | /** 6 | * The Users exceptions. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.user.exception; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-18. 3 | */ 4 | 5 | /** 6 | * The Users Persistence. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.persistence.user; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/service/PasswordResetTokenBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.PasswordResetTokenDto; 8 | import com.monogramm.starter.persistence.AbstractTokenBridge; 9 | import com.monogramm.starter.persistence.user.dao.UserRepository; 10 | import com.monogramm.starter.persistence.user.entity.PasswordResetToken; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | 14 | /** 15 | * Bridge to convert a {@link PasswordResetTokenDto} to a {@link PasswordResetToken} and vice versa. 16 | * 17 | * @author madmath03 18 | */ 19 | public class PasswordResetTokenBridge 20 | extends AbstractTokenBridge { 21 | 22 | /** 23 | * Create a {@link PasswordResetTokenBridge}. 24 | * 25 | *

26 | * Use with caution: this constructor will not set the @{code userRepository}, 27 | * preventing any search in the Persistence Storage for the relations objects. This might be 28 | * dangerous when converting 29 | * {@link AbstractTokenBridge#toEntity(com.monogramm.starter.dto.AbstractTokenDto)} 30 | * as no consistency check will be done but it will definitely improve performance. 31 | *

32 | * 33 | */ 34 | public PasswordResetTokenBridge() { 35 | super(); 36 | } 37 | 38 | /** 39 | * Create a {@link PasswordResetTokenBridge}. 40 | * 41 | * @param userRepository repository to lookup users. 42 | */ 43 | @Autowired 44 | public PasswordResetTokenBridge(UserRepository userRepository) { 45 | super(userRepository); 46 | } 47 | 48 | @Override 49 | protected PasswordResetToken buildEntity() { 50 | return new PasswordResetToken(); 51 | } 52 | 53 | @Override 54 | protected PasswordResetTokenDto buildDto() { 55 | return new PasswordResetTokenDto(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/service/PasswordResetTokenService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.PasswordResetTokenDto; 8 | import com.monogramm.starter.persistence.GenericService; 9 | import com.monogramm.starter.persistence.user.entity.PasswordResetToken; 10 | import com.monogramm.starter.persistence.user.entity.User; 11 | import com.monogramm.starter.persistence.user.exception.PasswordResetTokenNotFoundException; 12 | 13 | import java.util.UUID; 14 | 15 | /** 16 | * {@link PasswordResetToken} service interface. 17 | * 18 | * @author madmath03 19 | */ 20 | public interface PasswordResetTokenService 21 | extends GenericService { 22 | 23 | @Override 24 | PasswordResetTokenBridge getBridge(); 25 | 26 | /** 27 | * Find a token through its token code and user. 28 | * 29 | * @param user the user to search. 30 | * @param code the token code to search. 31 | * 32 | * @return the token matching the token code. 33 | * 34 | * @throws PasswordResetTokenNotFoundException if no token matches the code in the repository. 35 | */ 36 | PasswordResetToken findByUserAndCode(final User user, final String code); 37 | 38 | /** 39 | * Find a token through its token code and user id. 40 | * 41 | * @param userId the user id to search. 42 | * @param code the token code to search. 43 | * 44 | * @return the token matching the token code. 45 | * 46 | * @throws PasswordResetTokenNotFoundException if no token matches the code in the repository. 47 | */ 48 | PasswordResetToken findByUserAndCode(final UUID userId, final String code); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/service/VerificationTokenBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.VerificationTokenDto; 8 | import com.monogramm.starter.persistence.AbstractTokenBridge; 9 | import com.monogramm.starter.persistence.user.dao.UserRepository; 10 | import com.monogramm.starter.persistence.user.entity.VerificationToken; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | 14 | /** 15 | * Bridge to convert a {@link VerificationTokenDto} to a {@link VerificationToken} and vice versa. 16 | * 17 | * @author madmath03 18 | */ 19 | public class VerificationTokenBridge 20 | extends AbstractTokenBridge { 21 | 22 | /** 23 | * Create a {@link VerificationTokenBridge}. 24 | * 25 | *

26 | * Use with caution: this constructor will not set the @{code userRepository}, 27 | * preventing any search in the Persistence Storage for the relations objects. This might be 28 | * dangerous when converting 29 | * {@link AbstractTokenBridge#toEntity(com.monogramm.starter.dto.AbstractTokenDto)} 30 | * as no consistency check will be done but it will definitely improve performance. 31 | *

32 | * 33 | */ 34 | public VerificationTokenBridge() { 35 | super(); 36 | } 37 | 38 | /** 39 | * Create a {@link VerificationTokenBridge}. 40 | * 41 | * @param userRepository repository to lookup users. 42 | */ 43 | @Autowired 44 | public VerificationTokenBridge(UserRepository userRepository) { 45 | super(userRepository); 46 | } 47 | 48 | @Override 49 | protected VerificationToken buildEntity() { 50 | return new VerificationToken(); 51 | } 52 | 53 | @Override 54 | protected VerificationTokenDto buildDto() { 55 | return new VerificationTokenDto(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/service/VerificationTokenService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.VerificationTokenDto; 8 | import com.monogramm.starter.persistence.GenericService; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | import com.monogramm.starter.persistence.user.entity.VerificationToken; 11 | import com.monogramm.starter.persistence.user.exception.VerificationTokenNotFoundException; 12 | 13 | import java.util.UUID; 14 | 15 | /** 16 | * {@link VerificationToken} service interface. 17 | * 18 | * @author madmath03 19 | */ 20 | public interface VerificationTokenService 21 | extends GenericService { 22 | 23 | @Override 24 | VerificationTokenBridge getBridge(); 25 | 26 | /** 27 | * Find a token through its token code and user. 28 | * 29 | * @param user the user to search. 30 | * @param code the token code to search. 31 | * 32 | * @return the token matching the token code. 33 | * 34 | * @throws VerificationTokenNotFoundException if no token matches the code in the repository. 35 | */ 36 | VerificationToken findByUserAndCode(final User user, final String code); 37 | 38 | /** 39 | * Find an token through its token code and user id. 40 | * 41 | * @param userId the user id to search. 42 | * @param code the token code to search. 43 | * 44 | * @return the token matching the token code. 45 | * 46 | * @throws VerificationTokenNotFoundException if no token matches the code in the repository. 47 | */ 48 | VerificationToken findByUserAndCode(final UUID userId, final String code); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/persistence/user/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Users service. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.persistence.user.service; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/Jsonable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-13. 3 | */ 4 | 5 | package com.monogramm.starter.utils; 6 | 7 | import com.fasterxml.jackson.core.JsonProcessingException; 8 | 9 | /** 10 | * A JSON compatible object. 11 | * 12 | * @author madmath03 13 | */ 14 | public interface Jsonable { 15 | 16 | /** 17 | * Returns a JSON string representation of this object. 18 | * 19 | *

20 | * This method is generally intended to serialize objects during JSON serialization. 21 | *

22 | * 23 | * @return a JSON string representation of this. 24 | * 25 | * @throws JsonProcessingException if the object could not be serialized to JSON. 26 | */ 27 | public default String toJson() throws JsonProcessingException { 28 | return JsonUtils.toJson(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/AnyConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import com.monogramm.starter.utils.JsonUtils; 8 | 9 | import javax.persistence.AttributeConverter; 10 | 11 | /** 12 | * Any Converter. 13 | * 14 | * @author madmath03 15 | */ 16 | public class AnyConverter implements AttributeConverter { 17 | 18 | public static class AnyExporter implements ParameterExporter { 19 | 20 | @Override 21 | public String apply(Object object) { 22 | return object != null ? JsonUtils.json(object) : null; 23 | } 24 | 25 | } 26 | 27 | public static class AnyImporter implements ParameterImporter { 28 | 29 | @Override 30 | public Object apply(String value) { 31 | throw new UnsupportedOperationException("Cannot import to unknown class: " + value); 32 | } 33 | 34 | } 35 | 36 | private final AnyExporter exporter; 37 | 38 | private final AnyImporter importer; 39 | 40 | /** 41 | * Create a {@link AnyConverter}. 42 | * 43 | */ 44 | public AnyConverter() { 45 | this.exporter = new AnyExporter(); 46 | this.importer = new AnyImporter(); 47 | } 48 | 49 | @Override 50 | public String convertToDatabaseColumn(Object attribute) { 51 | return this.exporter.apply(attribute); 52 | } 53 | 54 | @Override 55 | public Object convertToEntityAttribute(String dbData) { 56 | return this.importer.apply(dbData); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/BooleanConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import javax.persistence.AttributeConverter; 8 | 9 | /** 10 | * Boolean Converter. 11 | * 12 | * @author madmath03 13 | */ 14 | public class BooleanConverter implements AttributeConverter { 15 | 16 | public static class BooleanExporter implements ParameterExporter { 17 | 18 | @Override 19 | public String apply(Object object) { 20 | return object instanceof Boolean ? ((Boolean) object).toString() : null; 21 | } 22 | 23 | } 24 | 25 | public static class BooleanImporter implements ParameterImporter { 26 | 27 | @Override 28 | public Boolean apply(String value) { 29 | return value != null ? Boolean.valueOf(value) : null; 30 | } 31 | 32 | } 33 | 34 | private final BooleanExporter exporter; 35 | 36 | private final BooleanImporter importer; 37 | 38 | /** 39 | * Create a {@link BooleanConverter}. 40 | * 41 | */ 42 | public BooleanConverter() { 43 | this.exporter = new BooleanExporter(); 44 | this.importer = new BooleanImporter(); 45 | } 46 | 47 | @Override 48 | public String convertToDatabaseColumn(Boolean attribute) { 49 | return this.exporter.apply(attribute); 50 | } 51 | 52 | @Override 53 | public Boolean convertToEntityAttribute(String dbData) { 54 | return this.importer.apply(dbData); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/ColorConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.awt.Color; 8 | import java.awt.Transparency; 9 | 10 | import javax.persistence.AttributeConverter; 11 | 12 | /** 13 | * Color Converter. 14 | * 15 | * @author madmath03 16 | */ 17 | public class ColorConverter implements AttributeConverter { 18 | 19 | public static class ColorExporter implements ParameterExporter { 20 | 21 | @Override 22 | public String apply(Object object) { 23 | final String value; 24 | 25 | if (object instanceof Color) { 26 | final Color color = ((Color) object); 27 | 28 | final StringBuilder colorBuilder = new StringBuilder("#"); 29 | 30 | componentToString(colorBuilder, color.getRed()); 31 | componentToString(colorBuilder, color.getBlue()); 32 | componentToString(colorBuilder, color.getGreen()); 33 | 34 | if (color.getTransparency() != Transparency.OPAQUE) { 35 | componentToString(colorBuilder, color.getAlpha()); 36 | } 37 | 38 | value = colorBuilder.toString(); 39 | } else { 40 | value = null; 41 | } 42 | 43 | return value; 44 | } 45 | 46 | private void componentToString(final StringBuilder builder, int component) { 47 | final String comp = Integer.toHexString(component); 48 | 49 | if (comp.length() == 1) { 50 | builder.append("0"); 51 | } 52 | builder.append(comp); 53 | } 54 | 55 | } 56 | 57 | public static class ColorImporter implements ParameterImporter { 58 | 59 | @Override 60 | public Color apply(String value) { 61 | return value != null ? Color.decode(value) : null; 62 | } 63 | 64 | } 65 | 66 | private final ColorExporter exporter; 67 | 68 | private final ColorImporter importer; 69 | 70 | /** 71 | * Create a {@link ColorConverter}. 72 | * 73 | */ 74 | public ColorConverter() { 75 | this.exporter = new ColorExporter(); 76 | this.importer = new ColorImporter(); 77 | } 78 | 79 | @Override 80 | public String convertToDatabaseColumn(Color attribute) { 81 | return this.exporter.apply(attribute); 82 | } 83 | 84 | @Override 85 | public Color convertToEntityAttribute(String dbData) { 86 | return this.importer.apply(dbData); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/DateConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.time.LocalDate; 8 | 9 | import javax.persistence.AttributeConverter; 10 | 11 | /** 12 | * Date Converter. 13 | * 14 | * @author madmath03 15 | */ 16 | public class DateConverter implements AttributeConverter { 17 | 18 | public static class DateExporter implements ParameterExporter { 19 | 20 | @Override 21 | public String apply(Object object) { 22 | return object instanceof LocalDate ? ((LocalDate) object).toString() : null; 23 | } 24 | 25 | } 26 | 27 | public static class DateImporter implements ParameterImporter { 28 | 29 | @Override 30 | public LocalDate apply(String value) { 31 | return value != null ? LocalDate.parse(value) : null; 32 | } 33 | 34 | } 35 | 36 | private final DateExporter exporter; 37 | 38 | private final DateImporter importer; 39 | 40 | /** 41 | * Create a {@link DateConverter}. 42 | * 43 | */ 44 | public DateConverter() { 45 | this.exporter = new DateExporter(); 46 | this.importer = new DateImporter(); 47 | } 48 | 49 | @Override 50 | public String convertToDatabaseColumn(LocalDate attribute) { 51 | return this.exporter.apply(attribute); 52 | } 53 | 54 | @Override 55 | public LocalDate convertToEntityAttribute(String dbData) { 56 | return this.importer.apply(dbData); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/DateTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.time.LocalDateTime; 8 | 9 | import javax.persistence.AttributeConverter; 10 | 11 | /** 12 | * DateTime Converter. 13 | * 14 | * @author madmath03 15 | */ 16 | public class DateTimeConverter implements AttributeConverter { 17 | 18 | public static class DateTimeExporter implements ParameterExporter { 19 | 20 | @Override 21 | public String apply(Object object) { 22 | return object instanceof LocalDateTime ? ((LocalDateTime) object).toString() : null; 23 | } 24 | 25 | } 26 | 27 | public static class DateTimeImporter implements ParameterImporter { 28 | 29 | @Override 30 | public LocalDateTime apply(String value) { 31 | return value != null ? LocalDateTime.parse(value) : null; 32 | } 33 | 34 | } 35 | 36 | private final DateTimeExporter exporter; 37 | 38 | private final DateTimeImporter importer; 39 | 40 | /** 41 | * Create a {@link DateTimeConverter}. 42 | * 43 | */ 44 | public DateTimeConverter() { 45 | this.exporter = new DateTimeExporter(); 46 | this.importer = new DateTimeImporter(); 47 | } 48 | 49 | @Override 50 | public String convertToDatabaseColumn(LocalDateTime attribute) { 51 | return this.exporter.apply(attribute); 52 | } 53 | 54 | @Override 55 | public LocalDateTime convertToEntityAttribute(String dbData) { 56 | return this.importer.apply(dbData); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/DoubleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import javax.persistence.AttributeConverter; 8 | 9 | /** 10 | * Double Converter. 11 | * 12 | * @author madmath03 13 | */ 14 | public class DoubleConverter implements AttributeConverter { 15 | 16 | public static class DoubleExporter implements ParameterExporter { 17 | 18 | @Override 19 | public String apply(Object object) { 20 | return object instanceof Double ? ((Double) object).toString() : null; 21 | } 22 | 23 | } 24 | 25 | public static class DoubleImporter implements ParameterImporter { 26 | 27 | @Override 28 | public Double apply(String value) { 29 | return value != null ? Double.valueOf(value) : null; 30 | } 31 | 32 | } 33 | 34 | private final DoubleExporter exporter; 35 | 36 | private final DoubleImporter importer; 37 | 38 | /** 39 | * Create a {@link DoubleConverter}. 40 | * 41 | */ 42 | public DoubleConverter() { 43 | this.exporter = new DoubleExporter(); 44 | this.importer = new DoubleImporter(); 45 | } 46 | 47 | @Override 48 | public String convertToDatabaseColumn(Double attribute) { 49 | return this.exporter.apply(attribute); 50 | } 51 | 52 | @Override 53 | public Double convertToEntityAttribute(String dbData) { 54 | return this.importer.apply(dbData); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/IntegerConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import javax.persistence.AttributeConverter; 8 | 9 | /** 10 | * Integer Converter. 11 | * 12 | * @author madmath03 13 | */ 14 | public class IntegerConverter implements AttributeConverter { 15 | 16 | public static class IntegerExporter implements ParameterExporter { 17 | 18 | @Override 19 | public String apply(Object object) { 20 | return object instanceof Integer ? ((Integer) object).toString() : null; 21 | } 22 | 23 | } 24 | 25 | public static class IntegerImporter implements ParameterImporter { 26 | 27 | @Override 28 | public Integer apply(String value) { 29 | return value != null ? Integer.valueOf(value) : null; 30 | } 31 | 32 | } 33 | 34 | private final IntegerExporter exporter; 35 | 36 | private final IntegerImporter importer; 37 | 38 | /** 39 | * Create a {@link IntegerConverter}. 40 | * 41 | */ 42 | public IntegerConverter() { 43 | this.exporter = new IntegerExporter(); 44 | this.importer = new IntegerImporter(); 45 | } 46 | 47 | @Override 48 | public String convertToDatabaseColumn(Integer attribute) { 49 | return this.exporter.apply(attribute); 50 | } 51 | 52 | @Override 53 | public Integer convertToEntityAttribute(String dbData) { 54 | return this.importer.apply(dbData); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/ParameterExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import com.monogramm.starter.persistence.AbstractParameter; 8 | 9 | import java.util.function.Function; 10 | 11 | /** 12 | * A functional interface for exporting an object to a string representation. 13 | * 14 | * @see ParameterImporter 15 | * @see AbstractParameter#setValue(String) 16 | * 17 | * @author madmath03 18 | */ 19 | public interface ParameterExporter extends Function { 20 | 21 | /** 22 | * Export an object to a string representation. 23 | * 24 | * @see ParameterImporter#apply(String) 25 | * 26 | * @param object object to export to a string. 27 | * 28 | * @return the object as a string. 29 | */ 30 | @Override 31 | String apply(final Object object); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/ParameterImporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import com.monogramm.starter.persistence.AbstractParameter; 8 | 9 | import java.util.function.Function; 10 | 11 | /** 12 | * A functional interface for importing a string representation of a parameter to an object. 13 | * 14 | * @see ParameterExporter 15 | * @see AbstractParameter#getValue() 16 | * 17 | * @param target data type 18 | * 19 | * @author madmath03 20 | */ 21 | public interface ParameterImporter extends Function { 22 | 23 | /** 24 | * Import an object from a string representation. 25 | * 26 | * @see ParameterExporter#apply(Object) 27 | * 28 | * @param value value to import as an object. 29 | * 30 | * @return the value as an object. 31 | */ 32 | @Override 33 | T apply(final String value); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/PathConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | 10 | import javax.persistence.AttributeConverter; 11 | 12 | /** 13 | * Path Converter. 14 | * 15 | * @author madmath03 16 | */ 17 | public class PathConverter implements AttributeConverter { 18 | 19 | public static class PathExporter implements ParameterExporter { 20 | 21 | @Override 22 | public String apply(Object object) { 23 | return object instanceof Path ? ((Path) object).toString() : null; 24 | } 25 | 26 | } 27 | 28 | public static class PathImporter implements ParameterImporter { 29 | 30 | @Override 31 | public Path apply(String value) { 32 | return value != null ? Paths.get(value) : null; 33 | } 34 | 35 | } 36 | 37 | private final PathExporter exporter; 38 | 39 | private final PathImporter importer; 40 | 41 | /** 42 | * Create a {@link PathConverter}. 43 | * 44 | */ 45 | public PathConverter() { 46 | this.exporter = new PathExporter(); 47 | this.importer = new PathImporter(); 48 | } 49 | 50 | @Override 51 | public String convertToDatabaseColumn(Path attribute) { 52 | return this.exporter.apply(attribute); 53 | } 54 | 55 | @Override 56 | public Path convertToEntityAttribute(String dbData) { 57 | return this.importer.apply(dbData); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/StringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import javax.persistence.AttributeConverter; 8 | 9 | /** 10 | * String Converter. 11 | * 12 | * @author madmath03 13 | */ 14 | public class StringConverter implements AttributeConverter { 15 | 16 | public static class StringExporter implements ParameterExporter { 17 | 18 | @Override 19 | public String apply(Object object) { 20 | return object instanceof String ? ((String) object).toString() : null; 21 | } 22 | 23 | } 24 | 25 | public static class StringImporter implements ParameterImporter { 26 | 27 | @Override 28 | public String apply(String value) { 29 | return value != null ? value.toString() : null; 30 | } 31 | 32 | } 33 | 34 | private final StringExporter exporter; 35 | 36 | private final StringImporter importer; 37 | 38 | /** 39 | * Create a {@link StringConverter}. 40 | * 41 | */ 42 | public StringConverter() { 43 | this.exporter = new StringExporter(); 44 | this.importer = new StringImporter(); 45 | } 46 | 47 | @Override 48 | public String convertToDatabaseColumn(String attribute) { 49 | return this.exporter.apply(attribute); 50 | } 51 | 52 | @Override 53 | public String convertToEntityAttribute(String dbData) { 54 | return this.importer.apply(dbData); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/TimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.time.LocalTime; 8 | 9 | import javax.persistence.AttributeConverter; 10 | 11 | /** 12 | * Time Converter. 13 | * 14 | * @author madmath03 15 | */ 16 | public class TimeConverter implements AttributeConverter { 17 | 18 | public static class TimeExporter implements ParameterExporter { 19 | 20 | @Override 21 | public String apply(Object object) { 22 | return object instanceof LocalTime ? ((LocalTime) object).toString() : null; 23 | } 24 | 25 | } 26 | 27 | public static class TimeImporter implements ParameterImporter { 28 | 29 | @Override 30 | public LocalTime apply(String value) { 31 | return value != null ? LocalTime.parse(value) : null; 32 | } 33 | 34 | } 35 | 36 | private final TimeExporter exporter; 37 | 38 | private final TimeImporter importer; 39 | 40 | /** 41 | * Create a {@link TimeConverter}. 42 | * 43 | */ 44 | public TimeConverter() { 45 | this.exporter = new TimeExporter(); 46 | this.importer = new TimeImporter(); 47 | } 48 | 49 | @Override 50 | public String convertToDatabaseColumn(LocalTime attribute) { 51 | return this.exporter.apply(attribute); 52 | } 53 | 54 | @Override 55 | public LocalTime convertToEntityAttribute(String dbData) { 56 | return this.importer.apply(dbData); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/UrlConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | package com.monogramm.starter.utils.converter; 6 | 7 | import java.net.MalformedURLException; 8 | import java.net.URL; 9 | 10 | import javax.persistence.AttributeConverter; 11 | 12 | /** 13 | * URL Converter. 14 | * 15 | * @author madmath03 16 | */ 17 | public class UrlConverter implements AttributeConverter { 18 | 19 | public static class UrlExporter implements ParameterExporter { 20 | 21 | @Override 22 | public String apply(Object object) { 23 | return object instanceof URL ? ((URL) object).toString() : null; 24 | } 25 | 26 | } 27 | 28 | public static class UrlImporter implements ParameterImporter { 29 | 30 | @Override 31 | public URL apply(String value) { 32 | URL url; 33 | try { 34 | url = new URL(value); 35 | } catch (MalformedURLException e) { 36 | url = null; 37 | } 38 | return url; 39 | } 40 | 41 | } 42 | 43 | private final UrlExporter exporter; 44 | 45 | private final UrlImporter importer; 46 | 47 | /** 48 | * Create a {@link UrlConverter}. 49 | * 50 | */ 51 | public UrlConverter() { 52 | this.exporter = new UrlExporter(); 53 | this.importer = new UrlImporter(); 54 | } 55 | 56 | @Override 57 | public String convertToDatabaseColumn(URL attribute) { 58 | return this.exporter.apply(attribute); 59 | } 60 | 61 | @Override 62 | public URL convertToEntityAttribute(String dbData) { 63 | return this.importer.apply(dbData); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/converter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-06. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application conversion Utilities. 7 | * 8 | * @author madmath03 9 | */ 10 | package com.monogramm.starter.utils.converter; 11 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The main package of the starter application Utilities. 3 | * 4 | * @author madmath03 5 | */ 6 | package com.monogramm.starter.utils; 7 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/EmailValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-05. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | import javax.validation.ConstraintValidator; 11 | import javax.validation.ConstraintValidatorContext; 12 | 13 | /** 14 | * The Custom EmailValidator. 15 | * 16 | * @see Baeldung: 17 | * The Registration Process With Spring Security 18 | * 19 | * @author madmath03 20 | */ 21 | public class EmailValidator implements ConstraintValidator { 22 | private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" 23 | + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; 24 | private static final Pattern PATTERN = Pattern.compile(EMAIL_PATTERN); 25 | 26 | private Matcher matcher; 27 | 28 | @Override 29 | public void initialize(final ValidEmail constraintAnnotation) { 30 | this.matcher = null; 31 | } 32 | 33 | @Override 34 | public boolean isValid(final String email, final ConstraintValidatorContext context) { 35 | return validateEmail(email); 36 | } 37 | 38 | private boolean validateEmail(final String email) { 39 | final boolean valid; 40 | 41 | if (email == null) { 42 | valid = false; 43 | } else { 44 | this.matcher = PATTERN.matcher(email); 45 | valid = this.matcher.matches(); 46 | } 47 | 48 | return valid; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/PasswordMatches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-05. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 8 | import static java.lang.annotation.ElementType.TYPE; 9 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 10 | 11 | import java.lang.annotation.Documented; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | import javax.validation.Constraint; 16 | import javax.validation.Payload; 17 | 18 | /** 19 | * The Custom Annotation for Validating a Password Confirmation. 20 | * 21 | * @see Baeldung: 22 | * The Registration Process With Spring Security 23 | * 24 | * @author madmath03 25 | */ 26 | @Target({TYPE, ANNOTATION_TYPE}) 27 | @Retention(RUNTIME) 28 | @Constraint(validatedBy = PasswordMatchesValidator.class) 29 | @Documented 30 | public @interface PasswordMatches { 31 | 32 | /** 33 | * Error message when validation fails. 34 | * 35 | * @return message when validation fails. 36 | */ 37 | String message() default "Passwords don't match"; 38 | 39 | /** 40 | * The validation groups. 41 | * 42 | * @return the validation groups. 43 | */ 44 | Class[] groups() default {}; 45 | 46 | /** 47 | * Custom payload. 48 | * 49 | * @return custom payload. 50 | */ 51 | Class[] payload() default {}; 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/PasswordMatchesValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-05. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import java.util.Arrays; 8 | 9 | import javax.validation.ConstraintValidator; 10 | import javax.validation.ConstraintValidatorContext; 11 | 12 | /** 13 | * The PasswordMatchesValidator Custom Validator. 14 | * 15 | * @see Baeldung: 16 | * The Registration Process With Spring Security 17 | * 18 | * @author madmath03 19 | */ 20 | public class PasswordMatchesValidator 21 | implements ConstraintValidator { 22 | 23 | @Override 24 | public void initialize(final PasswordMatches constraintAnnotation) { 25 | // Nothing to be initialized 26 | } 27 | 28 | @Override 29 | public boolean isValid(final PasswordConfirmationDto dto, 30 | final ConstraintValidatorContext context) { 31 | final boolean valid; 32 | 33 | if (dto == null) { 34 | valid = false; 35 | } else { 36 | valid = Arrays.equals(dto.getPassword(), dto.getMatchingPassword()); 37 | } 38 | 39 | return valid; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/UuidValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-17. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | import javax.validation.ConstraintValidator; 11 | import javax.validation.ConstraintValidatorContext; 12 | 13 | /** 14 | * The Custom UuidValidator. 15 | * 16 | * @see Is there 18 | * a uuid validator annotation? 19 | * 20 | * @author madmath03 21 | */ 22 | public class UuidValidator implements ConstraintValidator { 23 | private static final String UUID_PATTERN = 24 | "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; 25 | private static final Pattern PATTERN = Pattern.compile(UUID_PATTERN, Pattern.CASE_INSENSITIVE); 26 | 27 | private Matcher matcher; 28 | 29 | @Override 30 | public void initialize(final ValidUuid constraintAnnotation) { 31 | this.matcher = null; 32 | } 33 | 34 | @Override 35 | public boolean isValid(final String uuid, final ConstraintValidatorContext context) { 36 | return validateUuid(uuid); 37 | } 38 | 39 | private boolean validateUuid(final String uuid) { 40 | final boolean valid; 41 | 42 | if (uuid == null) { 43 | valid = false; 44 | } else { 45 | this.matcher = PATTERN.matcher(uuid); 46 | valid = this.matcher.matches(); 47 | } 48 | 49 | return valid; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/ValidEmail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-05. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 8 | import static java.lang.annotation.ElementType.FIELD; 9 | import static java.lang.annotation.ElementType.TYPE; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Documented; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.Target; 15 | 16 | import javax.validation.Constraint; 17 | import javax.validation.Payload; 18 | 19 | /** 20 | * The Custom Annotation for Email Validation. 21 | * 22 | * @see Baeldung: 23 | * The Registration Process With Spring Security 24 | * 25 | * @author madmath03 26 | */ 27 | @Target({ TYPE, FIELD, ANNOTATION_TYPE }) 28 | @Retention(RUNTIME) 29 | @Constraint(validatedBy = EmailValidator.class) 30 | @Documented 31 | public @interface ValidEmail { 32 | 33 | /** 34 | * Error message when validation fails. 35 | * 36 | * @return message when validation fails. 37 | */ 38 | String message() default "Invalid Email"; 39 | 40 | /** 41 | * The validation groups. 42 | * 43 | * @return the validation groups. 44 | */ 45 | Class[] groups() default {}; 46 | 47 | /** 48 | * Custom payload. 49 | * 50 | * @return custom payload. 51 | */ 52 | Class[] payload() default {}; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/ValidUuid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-17. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 8 | import static java.lang.annotation.ElementType.FIELD; 9 | import static java.lang.annotation.ElementType.PARAMETER; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Documented; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.Target; 15 | 16 | import javax.validation.Constraint; 17 | import javax.validation.Payload; 18 | 19 | /** 20 | * The Custom Annotation for UUID Validation. 21 | * 22 | * @see Is there 24 | * a uuid validator annotation? 25 | * 26 | * @author madmath03 27 | */ 28 | @Target({FIELD, PARAMETER, ANNOTATION_TYPE}) 29 | @Retention(RUNTIME) 30 | @Constraint(validatedBy = UuidValidator.class) 31 | @Documented 32 | public @interface ValidUuid { 33 | 34 | /** 35 | * Error message when validation fails. 36 | * 37 | * @return message when validation fails. 38 | */ 39 | String message() default "Invalid UUID string"; 40 | 41 | /** 42 | * The validation groups. 43 | * 44 | * @return the validation groups. 45 | */ 46 | Class[] groups() default {}; 47 | 48 | /** 49 | * Custom payload. 50 | * 51 | * @return custom payload. 52 | */ 53 | Class[] payload() default {}; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/monogramm/starter/utils/validation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-05. 3 | */ 4 | 5 | /** 6 | * The main package of the starter application Validation Utilities. 7 | * 8 | * @see Baeldung: The 9 | * Registration Process With Spring Security 10 | * 11 | * @author madmath03 12 | */ 13 | package com.monogramm.starter.utils.validation; 14 | -------------------------------------------------------------------------------- /src/main/resources/app-banner.txt: -------------------------------------------------------------------------------- 1 | 2 | __ __ ____ _ _ ____ _____ _____ __ __ __ __ 3 | | \/ | / __ \ | \ | | / __ \ / ____| | __ \ /\ | \/ | | \/ | 4 | | \ / | | | | | | \| | | | | | | | __ | |__) | / \ | \ / | | \ / | 5 | | |\/| | | | | | | . ` | | | | | | | |_ | | _ / / /\ \ | |\/| | | |\/| | 6 | | | | | | |__| | | |\ | | |__| | | |__| | | | \ \ / ____ \ | | | | | | | | 7 | |_| |_| \____/ |_| \_| \____/ \_____| |_| \_\ /_/ \_\ |_| |_| |_| |_| 8 | -------------------------------------------------------------------------------- /src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | 2 | -- ----------------------------------------------------- 3 | -- Clean generic data for spring_rest_api_starter 4 | -- ----------------------------------------------------- 5 | 6 | DELETE FROM oauth_client_details; 7 | DELETE FROM oauth_client_token; 8 | DELETE FROM oauth_access_token; 9 | DELETE FROM oauth_refresh_token; 10 | DELETE FROM oauth_code; 11 | DELETE FROM oauth_approvals; 12 | DELETE FROM ClientDetails; 13 | 14 | COMMIT; 15 | 16 | -- ----------------------------------------------------- 17 | -- Data for table oauth_client_details 18 | -- ----------------------------------------------------- 19 | 20 | INSERT INTO oauth_client_details 21 | (client_id, client_secret, scope, 22 | authorized_grant_types, 23 | web_server_redirect_uri, authorities, 24 | access_token_validity, refresh_token_validity, 25 | additional_information, autoapprove) 26 | VALUES 27 | ('clientMobileIdPassword', 'secret', 'api,read,write', 28 | 'password,authorization_code,refresh_token', 29 | null, null, 30 | 36000, 36000, 31 | null, true); 32 | 33 | INSERT INTO oauth_client_details 34 | (client_id, client_secret, scope, 35 | authorized_grant_types, 36 | web_server_redirect_uri, authorities, 37 | access_token_validity, refresh_token_validity, 38 | additional_information, autoapprove) 39 | VALUES 40 | ('clientWebIdPassword', 'secret', 'api,read,write', 41 | 'password,authorization_code,refresh_token', 42 | null, null, 43 | 36000, 36000, 44 | null, true); 45 | 46 | COMMIT; 47 | 48 | -------------------------------------------------------------------------------- /src/main/resources/i18n/messages_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Monogramm/spring-rest-api-starter/c59aa382c77b573dbca09e1bc64d494934b4ffdf/src/main/resources/i18n/messages_fr.properties -------------------------------------------------------------------------------- /src/main/resources/log4j2-spring.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/api/discoverability/event/AbstractResourceEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2019-01-13. 3 | */ 4 | 5 | package com.monogramm.starter.api.discoverability.event; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertNotNull; 9 | 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import org.junit.After; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | /** 17 | * {@link AbstractResourceEvent} Unit Test. 18 | * 19 | * @author madmath03 20 | */ 21 | public abstract class AbstractResourceEventTest> { 22 | 23 | private T event; 24 | 25 | /** 26 | * @throws java.lang.Exception if the test setup crashes. 27 | */ 28 | @Before 29 | public void setUp() throws Exception { 30 | this.event = this.buildTestEvent(); 31 | } 32 | 33 | /** 34 | * @throws java.lang.Exception if the test cleanup crashes. 35 | */ 36 | @After 37 | public void tearDown() throws Exception { 38 | this.event = null; 39 | } 40 | 41 | /** 42 | * Get the {@link #event}. 43 | * 44 | * @return the {@link #event}. 45 | */ 46 | protected final T getEvent() { 47 | return event; 48 | } 49 | 50 | protected abstract T buildTestEvent(); 51 | 52 | protected abstract O getTestSource(); 53 | 54 | protected abstract HttpServletResponse getTestResponse(); 55 | 56 | /** 57 | * Test method for {@link AbstractResourceEventTest#AbstractResourceEventTest()}. 58 | */ 59 | @Test 60 | public void testAbstractMailSendingEvent() { 61 | assertNotNull(event); 62 | } 63 | 64 | /** 65 | * Test method for 66 | * {@link com.monogramm.starter.api.discoverability.event.AbstractResourceEvent#getSource()}. 67 | */ 68 | @Test 69 | public void testGetSource() { 70 | assertNotNull(event.getSource()); 71 | assertEquals(getTestSource(), event.getSource()); 72 | } 73 | 74 | /** 75 | * Test method for 76 | * {@link com.monogramm.starter.api.discoverability.event.AbstractResourceEvent#getResponse()}. 77 | */ 78 | @Test 79 | public void testGetResponse() { 80 | assertNotNull(event.getResponse()); 81 | assertEquals(getTestResponse(), event.getResponse()); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/api/user/event/OnPasswordResetEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.api.user.event; 6 | 7 | import com.monogramm.starter.api.AbstractMailSendingEvent; 8 | import com.monogramm.starter.api.AbstractMailSendingEventTest; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | 11 | import java.util.Locale; 12 | 13 | import org.junit.After; 14 | import org.junit.Before; 15 | 16 | /** 17 | * {@link OnPasswordResetEvent} Unit Test. 18 | * 19 | * @author madmath03 20 | */ 21 | public class OnPasswordResetEventTest extends AbstractMailSendingEventTest { 22 | 23 | private User user; 24 | private Locale locale; 25 | private String appUrl; 26 | 27 | @Override 28 | protected AbstractMailSendingEvent buildTestEvent() { 29 | return new OnPasswordResetEvent(user, locale, appUrl); 30 | } 31 | 32 | @Override 33 | protected User getTestUser() { 34 | return user; 35 | } 36 | 37 | @Override 38 | protected Locale getTestLocale() { 39 | return locale; 40 | } 41 | 42 | @Override 43 | protected String getTestAppUrl() { 44 | return appUrl; 45 | } 46 | 47 | /** 48 | * @throws java.lang.Exception if the test setup crashes. 49 | */ 50 | @Before 51 | public void setUp() throws Exception { 52 | this.user = new User(); 53 | this.locale = Locale.getDefault(); 54 | this.appUrl = "http://dummy/"; 55 | 56 | super.setUp(); 57 | } 58 | 59 | /** 60 | * @throws java.lang.Exception if the test cleanup crashes. 61 | */ 62 | @After 63 | public void tearDown() throws Exception { 64 | this.user = null; 65 | this.locale = null; 66 | this.appUrl = null; 67 | 68 | super.tearDown(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/api/user/event/OnRegistrationCompleteEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.api.user.event; 6 | 7 | import com.monogramm.starter.api.AbstractMailSendingEvent; 8 | import com.monogramm.starter.api.AbstractMailSendingEventTest; 9 | import com.monogramm.starter.persistence.user.entity.User; 10 | 11 | import java.util.Locale; 12 | 13 | import org.junit.After; 14 | import org.junit.Before; 15 | 16 | /** 17 | * {@link OnRegistrationCompleteEvent} Unit Test. 18 | * 19 | * @author madmath03 20 | */ 21 | public class OnRegistrationCompleteEventTest extends AbstractMailSendingEventTest { 22 | 23 | private User user; 24 | private Locale locale; 25 | private String appUrl; 26 | 27 | @Override 28 | protected AbstractMailSendingEvent buildTestEvent() { 29 | return new OnRegistrationCompleteEvent(user, locale, appUrl); 30 | } 31 | 32 | @Override 33 | protected User getTestUser() { 34 | return user; 35 | } 36 | 37 | @Override 38 | protected Locale getTestLocale() { 39 | return locale; 40 | } 41 | 42 | @Override 43 | protected String getTestAppUrl() { 44 | return appUrl; 45 | } 46 | 47 | /** 48 | * @throws java.lang.Exception if the test setup crashes. 49 | */ 50 | @Before 51 | public void setUp() throws Exception { 52 | this.user = new User(); 53 | this.locale = Locale.getDefault(); 54 | this.appUrl = "http://dummy/"; 55 | 56 | super.setUp(); 57 | } 58 | 59 | /** 60 | * @throws java.lang.Exception if the test cleanup crashes. 61 | */ 62 | @After 63 | public void tearDown() throws Exception { 64 | this.user = null; 65 | this.locale = null; 66 | this.appUrl = null; 67 | 68 | super.tearDown(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/config/component/CustomPasswordEncoderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | package com.monogramm.starter.config.component; 6 | 7 | import static org.junit.Assert.assertTrue; 8 | 9 | import com.github.madmath03.password.Passwords; 10 | 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | 15 | /** 16 | * {@link CustomPasswordEncoder} Unit Test. 17 | * 18 | * @author madmath03 19 | */ 20 | public class CustomPasswordEncoderTest { 21 | 22 | private static final String PASSWORD_STR = "password"; 23 | private static final char[] PASSWORD = PASSWORD_STR.toCharArray(); 24 | private static final String HASHED_PASSWORD; 25 | 26 | static { 27 | HASHED_PASSWORD = Passwords.getHash(PASSWORD.clone()); 28 | } 29 | 30 | private CustomPasswordEncoder encoder; 31 | 32 | /** 33 | * @throws java.lang.Exception If test initialization crashes. 34 | */ 35 | @Before 36 | public void setUp() throws Exception { 37 | this.encoder = new CustomPasswordEncoder(); 38 | } 39 | 40 | /** 41 | * @throws java.lang.Exception If test clean up crashes. 42 | */ 43 | @After 44 | public void tearDown() throws Exception { 45 | this.encoder = null; 46 | } 47 | 48 | /** 49 | * Test method for 50 | * {@link CustomPasswordEncoder#matches(java.lang.CharSequence, java.lang.String)}. 51 | */ 52 | @Test 53 | public void testMatches() { 54 | assertTrue(this.encoder.matches(PASSWORD_STR, HASHED_PASSWORD)); 55 | } 56 | 57 | /** 58 | * Test method for {@link CustomPasswordEncoder#encode(java.lang.CharSequence)}. 59 | */ 60 | @Test 61 | public void testEncode() { 62 | final String hash = this.encoder.encode(PASSWORD_STR); 63 | 64 | assertTrue(Passwords.isExpectedPassword(PASSWORD_STR, hash)); 65 | assertTrue(Passwords.isExpectedPassword(PASSWORD_STR, HASHED_PASSWORD)); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/config/i8n/ApplicationMessageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-03. 3 | */ 4 | 5 | package com.monogramm.starter.config.i8n; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | 9 | import org.junit.After; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.springframework.context.MessageSource; 13 | 14 | /** 15 | * {@link ApplicationMessage} Unit Test. 16 | * 17 | * @author madmath03 18 | */ 19 | public class ApplicationMessageTest { 20 | 21 | private ApplicationMessage message; 22 | 23 | /** 24 | * @throws java.lang.Exception If test initialization crashes. 25 | */ 26 | @Before 27 | public void setUp() throws Exception { 28 | this.message = new ApplicationMessage(); 29 | } 30 | 31 | /** 32 | * @throws java.lang.Exception If test clean up crashes. 33 | */ 34 | @After 35 | public void tearDown() throws Exception { 36 | this.message = null; 37 | } 38 | 39 | /** 40 | * Test method for {@link ApplicationMessage#messageSource()}. 41 | */ 42 | @Test 43 | public void testMessageSource() { 44 | final MessageSource source = this.message.messageSource(); 45 | 46 | assertNotNull(source); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/dto/parameter/ParameterDtoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.dto.parameter; 6 | 7 | import com.monogramm.starter.dto.AbstractParameterDtoTest; 8 | 9 | /** 10 | * {@link ParameterDto} Unit Test. 11 | * 12 | * @author madmath03 13 | */ 14 | public class ParameterDtoTest extends AbstractParameterDtoTest { 15 | 16 | @Override 17 | protected ParameterDto buildTestDto() { 18 | return new ParameterDto(); 19 | } 20 | 21 | @Override 22 | protected ParameterDto buildTestDto(ParameterDto other) { 23 | return new ParameterDto(other); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/dto/user/PasswordResetTokenDtoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.dto.user; 6 | 7 | import com.monogramm.starter.dto.AbstractTokenDtoTest; 8 | 9 | /** 10 | * {@link PasswordResetTokenDto} Unit Test. 11 | * 12 | * @author madmath03 13 | */ 14 | public class PasswordResetTokenDtoTest extends AbstractTokenDtoTest { 15 | 16 | @Override 17 | protected PasswordResetTokenDto buildTestDto(PasswordResetTokenDto other) { 18 | return new PasswordResetTokenDto(other); 19 | } 20 | 21 | @Override 22 | protected PasswordResetTokenDto buildTestDto() { 23 | return new PasswordResetTokenDto(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/AbstractTokenBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-08. 3 | */ 4 | 5 | package com.monogramm.starter.persistence; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | import com.monogramm.starter.persistence.AbstractToken.AbstractTokenBuilder; 10 | import com.monogramm.starter.persistence.user.entity.User; 11 | 12 | import java.util.Date; 13 | 14 | import org.junit.Test; 15 | 16 | /** 17 | * {@link AbstractTokenBuilder} Unit Test. 18 | * 19 | * @author madmath03 20 | */ 21 | public abstract class AbstractTokenBuilderTest< 22 | T extends AbstractTokenBuilder> 23 | extends AbstractGenericEntityBuilderTest { 24 | 25 | /** 26 | * Test method for {@link AbstractTokenBuilder#code(String)}. 27 | */ 28 | @Test 29 | public void testCode() { 30 | T builder = this.buildTestEntityBuilder(); 31 | 32 | assertEquals(builder, builder.code(null)); 33 | 34 | final String code = "Test"; 35 | assertEquals(code, builder.code(code).build().getCode()); 36 | } 37 | 38 | /** 39 | * Test method for {@link AbstractTokenBuilder#expiryDate(java.util.Date)}. 40 | */ 41 | @Test 42 | public void testExpiryDate() { 43 | T builder = this.buildTestEntityBuilder(); 44 | 45 | assertEquals(builder, builder.createdAt(null)); 46 | 47 | final Date date = new Date(); 48 | assertEquals(date, builder.expiryDate(date).build().getExpiryDate()); 49 | } 50 | 51 | /** 52 | * Test method for {@link AbstractTokenBuilder#user(User)}. 53 | */ 54 | @Test 55 | public void testUser() { 56 | T builder = this.buildTestEntityBuilder(); 57 | 58 | assertEquals(builder, builder.user(null)); 59 | 60 | final User user = new User("testUser"); 61 | assertEquals(user, builder.user(user).build().getUser()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/parameter/entity/ParameterBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-08-27. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.entity; 6 | 7 | import com.monogramm.starter.persistence.AbstractParameterBuilderTest; 8 | import com.monogramm.starter.persistence.parameter.entity.Parameter.ParameterBuilder; 9 | 10 | /** 11 | * {@link ParameterBuilder} Unit Test. 12 | * 13 | * @author madmath03 14 | */ 15 | public class ParameterBuilderTest extends AbstractParameterBuilderTest { 16 | 17 | @Override 18 | protected ParameterBuilder buildTestEntityBuilder() { 19 | return Parameter.builder(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/parameter/entity/ParameterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.entity; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | 9 | import com.monogramm.starter.persistence.AbstractParameterTest; 10 | import com.monogramm.starter.persistence.ParameterType; 11 | 12 | import org.junit.Test; 13 | 14 | /** 15 | * {@link Parameter} Unit Test. 16 | * 17 | * @author madmath03 18 | */ 19 | public class ParameterTest extends AbstractParameterTest { 20 | 21 | /** 22 | * Test method for {@link Parameter#builder()}. 23 | */ 24 | @Test 25 | public void testBuilder() { 26 | assertNotNull(Parameter.builder()); 27 | } 28 | 29 | /** 30 | * Test method for {@link Parameter#builder(java.lang.String, java.lang.String)}. 31 | */ 32 | @Test 33 | public void testBuilderStringString() { 34 | assertNotNull(Parameter.builder("test", "42")); 35 | } 36 | 37 | /** 38 | * Test method for {@link Parameter#builder(String, ParameterType, Object)}. 39 | */ 40 | @Test 41 | public void testBuilderStringParameterTypeString() { 42 | assertNotNull(Parameter.builder("test", ParameterType.INTEGER, "42")); 43 | } 44 | 45 | @Override 46 | protected Parameter buildTestEntity(String name, ParameterType type, Object value) { 47 | return new Parameter(name, type, value); 48 | } 49 | 50 | @Override 51 | protected Parameter buildTestEntity(String name, Object value) { 52 | return new Parameter(name, value); 53 | } 54 | 55 | @Override 56 | protected Parameter buildTestEntity(Parameter other) { 57 | return new Parameter(other); 58 | } 59 | 60 | @Override 61 | protected Parameter buildTestEntity() { 62 | return new Parameter(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/parameter/service/ParameterBridgeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-09. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.parameter.service; 6 | 7 | import com.monogramm.starter.dto.parameter.ParameterDto; 8 | import com.monogramm.starter.persistence.AbstractParameterBridgeTest; 9 | import com.monogramm.starter.persistence.parameter.entity.Parameter; 10 | import com.monogramm.starter.persistence.user.dao.UserRepository; 11 | 12 | /** 13 | * {@link ParameterBridge} Unit Test. 14 | * 15 | * @author madmath03 16 | */ 17 | public class ParameterBridgeTest 18 | extends AbstractParameterBridgeTest { 19 | 20 | @Override 21 | protected ParameterBridge buildTestBridge(UserRepository userRepository) { 22 | return new ParameterBridge(userRepository); 23 | } 24 | 25 | @Override 26 | protected ParameterBridge buildTestBridge() { 27 | return new ParameterBridge(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/permission/entity/PermissionBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-25 3 | */ 4 | 5 | package com.monogramm.starter.persistence.permission.entity; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertNotNull; 9 | import static org.junit.Assert.assertNull; 10 | 11 | import com.monogramm.starter.persistence.AbstractGenericEntityBuilderTest; 12 | import com.monogramm.starter.persistence.permission.entity.Permission; 13 | import com.monogramm.starter.persistence.permission.entity.Permission.PermissionBuilder; 14 | 15 | import org.junit.Test; 16 | 17 | /** 18 | * {@link PermissionBuilder} Unit Test. 19 | * 20 | * @author madmath03 21 | */ 22 | public class PermissionBuilderTest 23 | extends AbstractGenericEntityBuilderTest { 24 | 25 | private static final String DISPLAYNAME = "TEST"; 26 | 27 | @Override 28 | protected PermissionBuilder buildTestEntityBuilder() { 29 | return Permission.builder(); 30 | } 31 | 32 | /** 33 | * Test method for {@link Permission#builder()}. 34 | */ 35 | @Test 36 | public void testGetBuilder() { 37 | Permission.PermissionBuilder builder = Permission.builder(); 38 | 39 | assertNotNull(builder); 40 | 41 | final Permission permissionBuilt = builder.build(); 42 | assertNotNull(permissionBuilt); 43 | assertNull(permissionBuilt.getName()); 44 | } 45 | 46 | /** 47 | * Test method for {@link Permission#builder(java.lang.String)}. 48 | */ 49 | @Test 50 | public void testGetBuilderString() { 51 | Permission.PermissionBuilder builder = Permission.builder(DISPLAYNAME); 52 | 53 | assertNotNull(builder); 54 | 55 | final Permission permissionBuilt = builder.build(); 56 | assertNotNull(permissionBuilt); 57 | assertEquals(DISPLAYNAME, permissionBuilt.getName()); 58 | } 59 | 60 | /** 61 | * Test method for {@link Permission.PermissionBuilder#name(java.lang.String)}. 62 | */ 63 | @Test 64 | public void testName() { 65 | assertEquals(this.getEntityBuilder(), this.getEntityBuilder().name(null)); 66 | 67 | final String name = "TEST"; 68 | assertEquals(name, 69 | this.getEntityBuilder().name(name).build().getName()); 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/type/entity/TypeBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-08-27. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.type.entity; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertNotNull; 9 | import static org.junit.Assert.assertNull; 10 | 11 | import com.monogramm.starter.persistence.AbstractGenericEntityBuilderTest; 12 | import com.monogramm.starter.persistence.type.entity.Type; 13 | import com.monogramm.starter.persistence.type.entity.Type.TypeBuilder; 14 | 15 | import org.junit.Test; 16 | 17 | /** 18 | * {@link TypeBuilder} Unit Test. 19 | * 20 | * @author madmath03 21 | */ 22 | public class TypeBuilderTest extends AbstractGenericEntityBuilderTest { 23 | 24 | private static final String DISPLAYNAME = "TEST"; 25 | 26 | @Override 27 | protected TypeBuilder buildTestEntityBuilder() { 28 | return Type.builder(); 29 | } 30 | 31 | /** 32 | * Test method for {@link Type#builder()}. 33 | */ 34 | @Test 35 | public void testGetBuilder() { 36 | Type.TypeBuilder builder = Type.builder(); 37 | 38 | assertNotNull(builder); 39 | 40 | final Type typeBuilt = builder.build(); 41 | assertNotNull(typeBuilt); 42 | assertNull(typeBuilt.getName()); 43 | } 44 | 45 | /** 46 | * Test method for {@link Type#builder(java.lang.String)}. 47 | */ 48 | @Test 49 | public void testGetBuilderString() { 50 | Type.TypeBuilder builder = Type.builder(DISPLAYNAME); 51 | 52 | assertNotNull(builder); 53 | 54 | final Type typeBuilt = builder.build(); 55 | assertNotNull(typeBuilt); 56 | assertEquals(DISPLAYNAME, typeBuilt.getName()); 57 | } 58 | 59 | /** 60 | * Test method for {@link Type.TypeBuilder#name(java.lang.String)}. 61 | */ 62 | @Test 63 | public void testName() { 64 | assertEquals(this.getEntityBuilder(), this.getEntityBuilder().name(null)); 65 | 66 | final String name = "TEST"; 67 | assertEquals(name, 68 | this.getEntityBuilder().name(name).build().getName()); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/user/entity/PasswordResetTokenBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2018-01-08. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.entity; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertNotNull; 9 | 10 | import com.monogramm.starter.persistence.AbstractTokenBuilderTest; 11 | import com.monogramm.starter.persistence.user.entity.PasswordResetToken.PasswordResetTokenBuilder; 12 | 13 | import java.util.Date; 14 | 15 | import org.junit.Test; 16 | 17 | /** 18 | * {@link PasswordResetTokenBuilder} Unit Test. 19 | * 20 | * @author madmath03 21 | */ 22 | public class PasswordResetTokenBuilderTest 23 | extends AbstractTokenBuilderTest { 24 | 25 | protected static final String DUMMY_CODE = "Foo"; 26 | protected static final Date DUMMY_EXPIRY_DATE = new Date(); 27 | 28 | @Override 29 | protected PasswordResetTokenBuilder buildTestEntityBuilder() { 30 | return PasswordResetToken.builder(); 31 | } 32 | 33 | /** 34 | * Test method for 35 | * {@link PasswordResetToken.PasswordResetTokenBuilder#PasswordResetTokenBuilder(String, Date)}. 36 | */ 37 | @Test 38 | public void testPasswordResetTokenBuilderStringDate() { 39 | PasswordResetToken.PasswordResetTokenBuilder builder = 40 | PasswordResetToken.builder(DUMMY_CODE, DUMMY_EXPIRY_DATE); 41 | 42 | assertNotNull(builder); 43 | 44 | assertEquals(DUMMY_CODE, builder.code(DUMMY_CODE).build().getCode()); 45 | assertEquals(DUMMY_EXPIRY_DATE, builder.expiryDate(DUMMY_EXPIRY_DATE).build().getExpiryDate()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/user/entity/PasswordResetTokenTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.entity; 6 | 7 | import com.monogramm.starter.persistence.AbstractTokenTest; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * {@link PasswordResetToken} Unit Test. 13 | * 14 | * @author madmath03 15 | */ 16 | public class PasswordResetTokenTest extends AbstractTokenTest { 17 | 18 | @Override 19 | protected PasswordResetToken buildTestEntity(String token, Date expiryDate) { 20 | return new PasswordResetToken(token, expiryDate); 21 | } 22 | 23 | @Override 24 | protected PasswordResetToken buildTestEntity(PasswordResetToken other) { 25 | return new PasswordResetToken(other); 26 | } 27 | 28 | @Override 29 | protected PasswordResetToken buildTestEntity() { 30 | return new PasswordResetToken(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/user/service/PasswordResetTokenBridgeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-20. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.PasswordResetTokenDto; 8 | import com.monogramm.starter.persistence.AbstractTokenBridgeTest; 9 | import com.monogramm.starter.persistence.user.dao.UserRepository; 10 | import com.monogramm.starter.persistence.user.entity.PasswordResetToken; 11 | 12 | /** 13 | * {@link PasswordResetTokenBridge} Unit Test. 14 | * 15 | * @author madmath03 16 | */ 17 | public class PasswordResetTokenBridgeTest extends 18 | AbstractTokenBridgeTest { 19 | 20 | @Override 21 | protected PasswordResetTokenBridge buildTestBridge() { 22 | return new PasswordResetTokenBridge(); 23 | } 24 | 25 | @Override 26 | protected PasswordResetTokenBridge buildTestBridge(UserRepository userRepository) { 27 | return new PasswordResetTokenBridge(userRepository); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/persistence/user/service/VerificationTokenBridgeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-12-18. 3 | */ 4 | 5 | package com.monogramm.starter.persistence.user.service; 6 | 7 | import com.monogramm.starter.dto.user.VerificationTokenDto; 8 | import com.monogramm.starter.persistence.AbstractTokenBridgeTest; 9 | import com.monogramm.starter.persistence.user.dao.UserRepository; 10 | import com.monogramm.starter.persistence.user.entity.VerificationToken; 11 | 12 | /** 13 | * {@link VerificationTokenBridge} Unit Test. 14 | * 15 | * @author madmath03 16 | */ 17 | public class VerificationTokenBridgeTest extends 18 | AbstractTokenBridgeTest { 19 | 20 | @Override 21 | protected VerificationTokenBridge buildTestBridge() { 22 | return new VerificationTokenBridge(); 23 | } 24 | 25 | @Override 26 | protected VerificationTokenBridge buildTestBridge(UserRepository userRepository) { 27 | return new VerificationTokenBridge(userRepository); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/utils/validation/EmailValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-10. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import static org.junit.Assert.assertFalse; 8 | import static org.junit.Assert.assertTrue; 9 | import static org.mockito.Mockito.mock; 10 | 11 | import javax.validation.ConstraintValidatorContext; 12 | 13 | import org.junit.After; 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.mockito.Mockito; 17 | 18 | /** 19 | * {@link EmailValidator} Unit Test. 20 | * 21 | * @author madmath03 22 | */ 23 | public class EmailValidatorTest { 24 | 25 | private ValidEmail constraintAnnotation; 26 | 27 | private ConstraintValidatorContext context; 28 | 29 | private EmailValidator validator; 30 | 31 | /** 32 | * @throws java.lang.Exception if the test setup crashes. 33 | */ 34 | @Before 35 | public void setUp() throws Exception { 36 | this.context = mock(ConstraintValidatorContext.class); 37 | 38 | this.validator = new EmailValidator(); 39 | } 40 | 41 | /** 42 | * @throws java.lang.Exception if the test cleanup crashes. 43 | */ 44 | @After 45 | public void tearDown() throws Exception { 46 | Mockito.reset(context); 47 | 48 | this.validator = null; 49 | } 50 | 51 | /** 52 | * Test method for 53 | * {@link EmailValidator#initialize(com.monogramm.starter.utils.validation.ValidEmail)}. 54 | */ 55 | @Test 56 | public void testInitialize() { 57 | this.validator.initialize(this.constraintAnnotation); 58 | } 59 | 60 | /** 61 | * Test method for 62 | * {@link EmailValidator#isValid(java.lang.String, javax.validation.ConstraintValidatorContext)}. 63 | */ 64 | @Test 65 | public void testIsValid() { 66 | assertFalse(this.validator.isValid(null, this.context)); 67 | 68 | assertFalse(this.validator.isValid("", this.context)); 69 | 70 | assertFalse(this.validator.isValid("foo", this.context)); 71 | 72 | assertFalse(this.validator.isValid("foo@bar", this.context)); 73 | 74 | assertFalse(this.validator.isValid("foo42@bar", this.context)); 75 | 76 | assertFalse(this.validator.isValid("foo&@bar", this.context)); 77 | 78 | assertTrue(this.validator.isValid("foo@bar.com", this.context)); 79 | 80 | assertTrue(this.validator.isValid("foo42@bar.com", this.context)); 81 | 82 | assertFalse(this.validator.isValid("foo&@bar.com", this.context)); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/com/monogramm/starter/utils/validation/UuidValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Creation by madmath03 the 2017-11-17. 3 | */ 4 | 5 | package com.monogramm.starter.utils.validation; 6 | 7 | import static org.junit.Assert.assertFalse; 8 | import static org.junit.Assert.assertTrue; 9 | import static org.mockito.Mockito.mock; 10 | 11 | import java.util.UUID; 12 | 13 | import javax.validation.ConstraintValidatorContext; 14 | 15 | import org.junit.After; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | /** 21 | * {@link UuidValidator} Unit Test. 22 | * 23 | * @author madmath03 24 | */ 25 | public class UuidValidatorTest { 26 | 27 | private ValidUuid constraintAnnotation; 28 | 29 | private ConstraintValidatorContext context; 30 | 31 | private UuidValidator validator; 32 | 33 | /** 34 | * @throws java.lang.Exception if the test setup crashes. 35 | */ 36 | @Before 37 | public void setUp() throws Exception { 38 | this.context = mock(ConstraintValidatorContext.class); 39 | 40 | this.validator = new UuidValidator(); 41 | } 42 | 43 | /** 44 | * @throws java.lang.Exception if the test cleanup crashes. 45 | */ 46 | @After 47 | public void tearDown() throws Exception { 48 | Mockito.reset(context); 49 | 50 | this.validator = null; 51 | } 52 | 53 | /** 54 | * Test method for {@link UuidValidator#initialize(ValidUuid)}. 55 | */ 56 | @Test 57 | public void testInitialize() { 58 | this.validator.initialize(this.constraintAnnotation); 59 | } 60 | 61 | /** 62 | * Test method for {@link UuidValidator#isValid(String, ConstraintValidatorContext)}. 63 | */ 64 | @Test 65 | public void testIsValid() { 66 | assertFalse(this.validator.isValid(null, this.context)); 67 | 68 | assertFalse(this.validator.isValid("", this.context)); 69 | 70 | assertFalse(this.validator.isValid("this_is_not_a_UUID", this.context)); 71 | 72 | assertFalse(this.validator.isValid("00000000000000000000000000000000", this.context)); 73 | 74 | assertTrue(this.validator.isValid("00000000-0000-0000-0000-000000000000", this.context)); 75 | 76 | assertTrue(this.validator.isValid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", this.context)); 77 | 78 | assertTrue(this.validator.isValid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA", this.context)); 79 | 80 | assertTrue(this.validator.isValid(UUID.randomUUID().toString(), this.context)); 81 | } 82 | 83 | } 84 | --------------------------------------------------------------------------------