From 87bbf89c6a06c2d455f06262639ad994d0f039cf Mon Sep 17 00:00:00 2001 From: spacecodee Date: Mon, 9 Dec 2024 18:20:21 +0000 Subject: [PATCH 1/5] moved .env example to .dev container, updated readme.md for better doc, ignored my own .env --- .env.example => .devcontainer/.env.example | 0 .gitignore | 2 +- readme.md | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename .env.example => .devcontainer/.env.example (100%) diff --git a/.env.example b/.devcontainer/.env.example similarity index 100% rename from .env.example rename to .devcontainer/.env.example diff --git a/.gitignore b/.gitignore index c6bf60c..e3616c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .DS_Store -.env +.devcontainer/.env /src/main/resources/application-local.properties HELP.md diff --git a/readme.md b/readme.md index 7e3b466..ab95b93 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ security.cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS security.cors.allowed-headers=Authorization,Content-Type,Accept-Language ``` -Create `.env` file in the root of the application +Create `.env` file in the .devcontainer folder of the application ```.env POSTGRES_USER=#your-database-user From 6334138471b846e2a6833132463298853344b0f7 Mon Sep 17 00:00:00 2001 From: spacecodee Date: Mon, 9 Dec 2024 14:49:52 -0500 Subject: [PATCH 2/5] deleted a file --- a | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 a diff --git a/a b/a deleted file mode 100644 index c6dc465..0000000 --- a/a +++ /dev/null @@ -1,42 +0,0 @@ -// JwtServiceImpl.java - Add new method -@Override -public TokenValidationResult refreshExpiredToken(String jwt, Claims claims, String locale) { - try { - log.info("Refreshing expired token"); - // Delete old token - this.jwtTokenService.deleteByToken(locale, jwt); - - // Generate new token with existing claims - String newToken = buildToken(new TokenClaims(claims.getSubject(), claims)); - - return new TokenValidationResult(newToken, true); - } catch (Exception e) { - log.error("Error refreshing token", e); - throw new TokenExpiredException("token.refresh.failed", locale); - } -} - -@Override -public TokenValidationResult validateDeleteExpiredToken(String jwt, String locale) { - try { - Claims claims = extractAllClaims(jwt); - boolean isExpired = claims.getExpiration().before(new Date()); - - if (isExpired) { - log.info("Token is expired, refreshing"); - return refreshExpiredToken(jwt, claims, locale); - } - - return new TokenValidationResult(jwt, false); - } catch (Exception e) { - log.info("Token validation failed, deleting token"); - this.jwtTokenService.deleteByToken(locale, jwt); - throw new TokenExpiredException("token.expired", locale); - } -} - -// IJwtService.java - Add new method -public interface IJwtService { - // ... existing methods - TokenValidationResult refreshExpiredToken(String jwt, Claims claims, String locale); -} \ No newline at end of file From 3152f35e35e6f1ab8b940e9bb508f5d9405a3ce9 Mon Sep 17 00:00:00 2001 From: spacecodee Date: Sat, 21 Dec 2024 15:53:41 -0500 Subject: [PATCH 3/5] A --- .github/copilot-instructions.md | 0 error.json | 29 +++++++++++++++++++++++++++++ error.log | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 .github/copilot-instructions.md create mode 100644 error.json create mode 100644 error.log diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..e69de29 diff --git a/error.json b/error.json new file mode 100644 index 0000000..2b43140 --- /dev/null +++ b/error.json @@ -0,0 +1,29 @@ +{ + "timestamp": "2024-12-15 05:45:16", + "backendMessage": "MethodArgumentNotValidException", + "message": "Validation error: 2", + "path": "/api/v1/auth/authenticate", + "method": "POST", + "data": [ + { + "field": "password", + "rejectedValue": "123", + "message": "Password must be between 6 and 32 characters", + "parameters": [ + "123", + 6, + 32 + ] + }, + { + "field": "username", + "rejectedValue": "a", + "message": "Username must be between 3 and 50 characters", + "parameters": [ + "a", + 3, + 50 + ] + } + ] + } \ No newline at end of file diff --git a/error.log b/error.log new file mode 100644 index 0000000..9161188 --- /dev/null +++ b/error.log @@ -0,0 +1,2 @@ +05:45:16.667 [http-nio-8080-exec-1] DEBUG c.s.s.language.MessageUtilComponent - Parameterized message resolved: 'Validation error: 2' +05:45:16.735 [http-nio-8080-exec-1] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved [org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [1] in public org.springframework.http.ResponseEntity> com.spacecodee.springbootsecurityopentemplate.controller.api.auth.impl.AuthenticationControllerImpl.authenticate(java.lang.String,com.spacecodee.springbootsecurityopentemplate.data.vo.auth.LoginUserVO) with 2 errors: [Field error in object 'loginUserVO' on field 'password': rejected value [123]; codes [Size.loginUserVO.password,Size.password,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [loginUserVO.password,password]; arguments []; default message [password],32,6]; default message [Password must be between {1} and {2} characters]] [Field error in object 'loginUserVO' on field 'username': rejected value [a]; codes [Size.loginUserVO.username,Size.username,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [loginUserVO.username,username]; arguments []; default message [username],50,3]; default message [Username must be between {1} and {2} characters]] ] \ No newline at end of file From 10e46a6d90187c02175e0263868ee538dc980a11 Mon Sep 17 00:00:00 2001 From: spacecodee Date: Mon, 23 Dec 2024 09:14:50 -0500 Subject: [PATCH 4/5] updated sh --- .devcontainer/backup.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 .devcontainer/backup.sh diff --git a/.devcontainer/backup.sh b/.devcontainer/backup.sh new file mode 100755 index 0000000..73c8775 --- /dev/null +++ b/.devcontainer/backup.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Define the backup file name and path +BACKUP_FILE="../src/main/resources/data/full_backup.sql" + +# Check if docker-compose.yml exists in the current directory +if [ ! -f docker-compose.yml ]; then + echo "docker-compose.yml not found in the current directory." + exit 1 +fi + +# Run the pg_dump command inside the db container with --inserts option +docker-compose exec db pg_dump --username=spacecodee --dbname=springboot_security_open_template --inserts > $BACKUP_FILE + +echo "Backup completed: $BACKUP_FILE" \ No newline at end of file From e9dff29c34f9952c8af7cd55a09146bb2fa92c3c Mon Sep 17 00:00:00 2001 From: andresbonelli Date: Sun, 29 Dec 2024 11:20:22 -0300 Subject: [PATCH 5/5] Repositories: IRole/IUser: replaced positional params with named params. --- .../persistence/repository/IRoleRepository.java | 9 +++++---- .../persistence/repository/IUserRepository.java | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IRoleRepository.java b/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IRoleRepository.java index ae0beaf..eefa38c 100644 --- a/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IRoleRepository.java +++ b/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IRoleRepository.java @@ -4,6 +4,7 @@ import com.spacecodee.springbootsecurityopentemplate.persistence.entity.RoleEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -11,10 +12,10 @@ @Repository public interface IRoleRepository extends JpaRepository { - @Query("select r from RoleEntity r where r.name = ?1") - Optional findByName(RoleEnum defaultRoleName); + @Query("select r from RoleEntity r where r.name = :defaultRoleName") + Optional findByName(@Param("defaultRoleName") RoleEnum defaultRoleName); // get the admin role from properties located in resources/application.properties - @Query("select r from RoleEntity r where r.name = ?1") - Optional findAdminRole(RoleEnum roleName); + @Query("select r from RoleEntity r where r.name = :roleName") + Optional findAdminRole(@Param("roleName") RoleEnum roleName); } \ No newline at end of file diff --git a/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IUserRepository.java b/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IUserRepository.java index 6aeb6d3..b0e2500 100644 --- a/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IUserRepository.java +++ b/src/main/java/com/spacecodee/springbootsecurityopentemplate/persistence/repository/IUserRepository.java @@ -4,14 +4,15 @@ import com.spacecodee.springbootsecurityopentemplate.persistence.entity.UserEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; import java.util.Optional; public interface IUserRepository extends JpaRepository { - @Query("select count(u) from UserEntity u where u.roleEntity.name = ?1") - long countAdmins(RoleEnum name); + @Query("select count(u) from UserEntity u where u.roleEntity.name = :name") + long countAdmins(@Param("name") RoleEnum name); Optional findByUsername(String username);