feat(springSecurity): add spring security in app#79
Conversation
17b3669 to
3ca0012
Compare
7ca2ec9 to
e775d93
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces Spring Security (HTTP Basic) to protect the application’s endpoints, adds in-memory users/roles configured via properties/environment variables, and updates tests + documentation to work with authentication.
Changes:
- Added Spring Security dependency plus a
SecurityFilterChain, in-memoryUserDetailsService, and BCrypt encoder. - Added security-related configuration properties for main and test profiles; updated integration/container tests to send Basic Auth.
- Updated CI workflows and documentation/environment templates to reflect the new security configuration.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfig.java |
Adds Spring Security configuration (Basic auth, stateless, in-memory users). |
src/main/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigurationException.java |
Adds a dedicated runtime exception for security filter chain build failures. |
src/main/resources/application.properties |
Introduces app.security.* properties backed by env vars. |
pom.xml |
Adds spring-boot-starter-security. |
src/test/resources/application-test.properties |
Adds test security credentials and datasource defaults for the test profile. |
src/test/java/feature/SpringIntegrationTest.java |
Updates Cucumber integration test base to use Basic Auth. |
src/test/java/com/xpeho/spring_boot_java_random_user/presentation/UserGetByIdContainerTest.java |
Updates container test to authenticate requests; injects security properties. |
src/test/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigTest.java |
Adds unit tests for security helper methods and in-memory user roles. |
src/test/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigurationExceptionTest.java |
Adds unit test for the new exception. |
.github/workflows/tests.yaml |
Modifies how application-test.properties is prepared in CI. |
.github/workflows/sonar.yaml |
Same CI test-properties preparation change for Sonar job. |
README.md |
Documents security env vars and Basic Auth usage/roles. |
.env.template |
Adds placeholders for the new Spring Security env vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e775d93 to
708523e
Compare
708523e to
5d30f44
Compare
MayuriXx
left a comment
There was a problem hiding this comment.
A corriger le commentaire de copilot et c'est bon pour moi
5d30f44 to
0058607
Compare
0058607 to
b499879
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b499879 to
e9b3b14
Compare
…es and credentials Co-authored-by: Copilot <copilot@github.com>
…operties Co-authored-by: Copilot <copilot@github.com>
…n handling Co-authored-by: Copilot <copilot@github.com>
e9b3b14 to
e856fe6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a401a16 to
293c5eb
Compare
293c5eb to
9b2a10d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
src/test/java/feature/SpringIntegrationTest.java:74
executePutis still using the unauthenticatedrestTemplate, unlike the GET/POST/DELETE helpers above. SincePUT /random-users/**now requires theADMINrole, the Cucumber update scenarios that call this helper will start receiving 401/403 instead of exercising the update path.
protected void executePut(String path, Object payload) {
String url = "http://localhost:" + port + path;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
latestResponse = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9b2a10d to
f7bddb9
Compare
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| spring.sql.init.mode=never | ||
| spring.docker.compose.enabled=false | ||
| logging.level.com.xpeho.spring_boot_java_random_user.presentation.handlers=OFF | ||
| logging.level.com.zaxxer.hikari.pool.PoolBase=ERROR |
| printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties | ||
| fi | ||
| echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties |
| mkdir -p src/test/resources | ||
| echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties | ||
| if [ -n "${{ secrets.APPLICATION_TEST_PROPERTIES }}" ]; then | ||
| printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties |
| .requestMatchers(HttpMethod.GET, RANDOM_USERS_PATH).hasAnyRole(ADMIN_ROLE, "USER", "TEST") | ||
| .requestMatchers(HttpMethod.POST, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE) | ||
| .requestMatchers(HttpMethod.PUT, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE) | ||
| .requestMatchers(HttpMethod.DELETE, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE) |




No description provided.