Conversation
…in progress). flyway migration V2 up. working on logic for user check, oversee entity with role?
…lyway, added support for .env file in root.
WalkthroughAdds Google OAuth2 authentication and user management to the backend: new User entity, repository, service to auto-register OAuth2 users, security configuration with OAuth2 login and logout, authentication controller and integration tests, plus related configuration and dependency updates. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Browser as User / Browser
participant App as Spring Boot App
participant Google as Google OAuth2 Provider
participant Service as CustomOAuth2UserService
participant Repo as UserRepository
participant DB as Database
Browser->>App: Click "Sign in with Google"
App->>Google: Redirect to Google authorization endpoint
Google->>Browser: Prompt login & consent
Browser->>Google: Authorize
Google->>App: Redirect with authorization code
App->>Google: Exchange code for access token
Google->>App: Return access token
App->>Google: Request userinfo
Google->>App: Return OAuth2User (sub, email, name)
App->>Service: loadUser(OAuth2UserRequest)
Service->>Repo: findByProviderAndProviderId(provider, sub)
Repo->>DB: SELECT user by provider+providerId
DB-->>Repo: no match / user row
Service->>Repo: save(new User(name,email,provider,providerId))
Repo->>DB: INSERT user
DB-->>Repo: persisted user
Service-->>App: return OAuth2User
App->>App: Establish security context & session
App->>Browser: Redirect to authenticated endpoint (/me)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (11)
backend/src/main/java/org/fungover/zipp/service/UserServiceInterface.java (1)
1-5: EmptyUserServiceInterfaceadds noise without valueThis interface has no methods and (from the rest of the PR) doesn’t appear to be used as an abstraction. It’s effectively dead weight right now.
Consider either:
- Removing
UserServiceInterfaceuntil you have a concrete contract, or- Defining the expected user-related operations here and having
UserServiceimplement it, then injecting the interface in controllers/services.backend/src/test/resources/application.properties (1)
1-21: Be explicit about Flyway vsddl-auto=updatestrategy in testsYou enable Flyway (lines 11–12) and also set
spring.jpa.hibernate.ddl-auto=update(line 15). Running both together can cause schema drift or hide migration issues, especially in integration tests.If you intend Flyway to own schema management, consider switching
ddl-autotovalidateornonefor tests; if you rely on Hibernate’supdatefor convenience, consider disabling Flyway here instead.The
root/rootdefaults and local DB URL are consistent with this project’s agreed dev defaults and look fine. Based on learnings, this is acceptable.backend/src/main/resources/application-dev.yml (1)
1-24: Dev Google OAuth2 config looks reasonable; confirm redirect URI matches consoleThe
devprofile OAuth2 client registration (lines 5–16) is wired as expected: env‑driven client id/secret,profileandPlease just confirm:
- The redirect URI
http://localhost:8080/login/oauth2/code/googleis registered in your Google OAuth2 client, and- You actually want this registration only for the
devprofile, given you also configure a google client inapplication.yml.backend/src/main/resources/application.yml (1)
1-21: Global Google OAuth2 client config is fine; consider duplication with dev profileThe google client registration here mirrors
application-dev.yml, which is good for consistency. With both present, the same client is active for the default profile and thedevprofile.Two minor points to verify:
- That you really want OAuth2 login enabled in both default and
devprofiles (or, if not, consolidate config into one place).- That the redirect URI and scopes here match what you’ve configured in the Google console.
Leaving the provider block commented out is fine if you’re relying on Spring Security’s built‑in Google provider defaults.
backend/src/main/java/org/fungover/zipp/service/UserService.java (1)
1-15:UserServicehas no API yet; consider inlining or defining its contractRight now
UserServiceis just a@Servicewrapper aroundUserRepositorywith no public methods. Combined with the emptyUserServiceInterface, this looks like an incomplete abstraction rather than a useful service layer.Options:
- If you plan to add user-related business logic soon, define the service methods (e.g. “find or create user by OAuth2 principal”) and have
UserServiceimplementUserServiceInterface.- If not, simplify by removing
UserServiceand injectingUserRepositorydirectly until a real service layer is needed.backend/src/main/java/org/fungover/zipp/repository/UserRepository.java (1)
10-16: Repository methods are fine; clean up stale comment and namingThe repository signature looks good and matches the OAuth2 flow:
findByProviderAndProviderIdis exactly whatCustomOAuth2UserServiceneeds.Minor polish suggestions:
- The comment on line 12 (“change to what ever id we use in User”) seems outdated now that you’ve settled on
provider+providerIdas the lookup key; consider removing or updating it.List<User> findUserByEmail(String email);works with Spring Data’s naming rules, butfindByEmailis the more idiomatic convention. Renaming would slightly improve readability if this method is used in multiple places.backend/src/main/java/org/fungover/zipp/security/SecurityConfig.java (1)
13-17: Make the injected dependencyfinaland consider a clearer nameSince
CustomOAuth2UserServiceis required and injected via the constructor, declaringco2usasfinal(and optionally renaming tocustomOAuth2UserService) tightens immutability and makes the intent clearer without behavior change.backend/src/main/java/org/fungover/zipp/service/CustomOAuth2UserService.java (1)
24-43: Guard against missing attributes and consider updating existing usersThis implementation assumes Google/OpenID Connect semantics (
"sub","name","email"), which is fine today but will break or insert invalid data if the provider configuration or scopes change (e.g., missing email) or if you later add another provider. WithUserentity, a null email here will cause a persistence error.It would be safer to:
- Validate that
providerIdand- Relax the DB constraint and handle nulls explicitly, and
- Optionally update
existingusers’ name/email on subsequent logins so your DB mirrors the latest provider profile.For example:
OAuth2User oAuth2User = super.loadUser(userRequest); String providerId = oAuth2User.getAttribute("sub"); String name = oAuth2User.getAttribute("name"); String email = oAuth2User.getAttribute("email"); String provider = userRequest.getClientRegistration().getRegistrationId(); -User existing = userRepository.findByProviderAndProviderId(provider, providerId) - .orElse(null); - -if (existing == null) { +User existing = userRepository.findByProviderAndProviderId(provider, providerId) + .orElse(null); + +if (existing == null) { User newUser = new User(); newUser.setProvider(provider); newUser.setProviderId(providerId); newUser.setName(name); newUser.setEmail(email); userRepository.save(newUser); -} +} else { + existing.setName(name); + existing.setEmail(email); + // userRepository.save(existing); // if your JPA setup doesn’t auto‑flush +}backend/src/main/java/org/fungover/zipp/controller/AuthenticationController.java (2)
13-21: Remove or use the injected dependencies to avoid dead code
ClientRegistrationRepository,UserService, andUserRepositoryare injected but never used in this controller. If they’re only for future work, consider dropping them for now (or adding clear TODOs) to reduce noise and keep the constructor focused on what the controller actually needs today.
35-41: PreferOidcUserover rawOAuth2Userfor Google and fix the response typoSince this endpoint is Google/OpenID‑Connect specific, using
OidcUserwould give you typed accessors (e.g., subject, email) instead of relying on magic strings like"sub","name","email". It also makes intent clearer and reduces risk if claim names change.You might also want to fix the typo in the response text (
"email adress"→"email address").For example:
-@GetMapping("/me") -public String greet(@AuthenticationPrincipal OAuth2User principal) { - String name = principal.getAttribute("name"); - String email = principal.getAttribute("email"); - String id = principal.getAttribute("sub"); - - return "Hello " + name + ", your email adress is: " + email + ", this is your id " + id; -} +@GetMapping("/me") +public String greet(@AuthenticationPrincipal OidcUser principal) { + String name = principal.getFullName(); + String email = principal.getEmail(); + String id = principal.getSubject(); + + return "Hello " + name + ", your email address is: " + email + ", this is your id " + id; +}backend/src/main/java/org/fungover/zipp/entity/User.java (1)
10-84: Entity mapping looks solid; any tweaks are mostly modeling choicesThe JPA mapping (UUID id, non‑nullable
name/createdAtvia@PrePersist) is consistent and should work well with the OAuth2 user creation flow. If you later need stricter guarantees, you can consider adding uniqueness constraints (e.g., on(provider, providerId)) or switchingcreatedAttoInstantfor timezone clarity, but there’s nothing blocking here.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
.gitignore(1 hunks)backend/.gitignore(1 hunks)backend/pom.xml(1 hunks)backend/src/main/java/org/fungover/zipp/controller/AuthenticationController.java(1 hunks)backend/src/main/java/org/fungover/zipp/entity/User.java(1 hunks)backend/src/main/java/org/fungover/zipp/repository/UserRepository.java(1 hunks)backend/src/main/java/org/fungover/zipp/security/SecurityConfig.java(1 hunks)backend/src/main/java/org/fungover/zipp/service/CustomOAuth2UserService.java(1 hunks)backend/src/main/java/org/fungover/zipp/service/UserService.java(1 hunks)backend/src/main/java/org/fungover/zipp/service/UserServiceInterface.java(1 hunks)backend/src/main/resources/application-dev.properties(1 hunks)backend/src/main/resources/application-dev.yml(1 hunks)backend/src/main/resources/application.properties(2 hunks)backend/src/main/resources/application.yml(1 hunks)backend/src/test/java/org/fungover/zipp/AuthTest/AuthenticationIntegrationTest.java(1 hunks)backend/src/test/resources/application.properties(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-26T09:51:20.066Z
Learnt from: alfredbrannare
Repo: fungover/zipp PR: 12
File: docker-compose.yml:6-6
Timestamp: 2025-11-26T09:51:20.066Z
Learning: For the fungover/zipp project, hard-coded development credentials (like MYSQL_ROOT_PASSWORD: root in docker-compose.yml or datasource defaults in application.properties) are intentional development defaults and are not considered security concerns by the project maintainers.
Applied to files:
backend/src/main/resources/application-dev.propertiesbackend/pom.xmlbackend/src/main/resources/application.properties
🧬 Code graph analysis (2)
backend/src/main/java/org/fungover/zipp/service/UserService.java (1)
backend/src/main/java/org/fungover/zipp/service/CustomOAuth2UserService.java (1)
Service(12-48)
backend/src/main/java/org/fungover/zipp/service/CustomOAuth2UserService.java (1)
backend/src/main/java/org/fungover/zipp/service/UserService.java (1)
Service(7-15)
🔇 Additional comments (6)
backend/.gitignore (1)
36-36: Verify that the../.envpattern works as intended in Git.Using
../.envin a subdirectory's.gitignoreto ignore a parent directory's file is unconventional and may not work reliably. Git .gitignore patterns are evaluated relative to the .gitignore file's location, and patterns that escape parent directories have limited or inconsistent support across Git versions and clients.Since the root
.gitignorealready handlesbackend/.env(line 8), and.envat the root is handled by line 10 of the root.gitignore, this pattern inbackend/.gitignoreappears redundant and should likely be removed.Please verify:
- Can you confirm the intent of this pattern?
- Has this been tested to ensure
.envfiles are properly ignored in CI/CD and development workflows?Suggested fix (if redundant):
### Environment Variables -../.env -.env.local +.env.local.gitignore (1)
8-9: Clarify.env.localignore status (inconsistency with AI summary).The AI-generated summary states that the final state "stops ignoring .env.local", but the annotated code still shows
.env.localon line 9, indicating it is being ignored. Please clarify whether.env.localshould be ignored or committed to version control.If
.env.localshould not be ignored, remove it:### Environment Variables backend/.env -.env.local .envIf
.env.localshould continue to be ignored (current state), the AI summary description is inaccurate and should be disregarded.backend/src/main/resources/application-dev.properties (1)
6-13: Dev profile setup looks good, but verify .env import scope.Lines 6 and 13 are appropriate for development (auto-updating schema and importing OAuth2 credentials via
.env). However, verify that the.env[.properties]import on Line 13 is intentional when the same import also appears inapplication.properties(Line 21). If.envis dev-specific, consider removing it from the mainapplication.properties.backend/src/main/resources/application.properties (1)
6-8: Verify datasource configuration across environments.Line 6 adds
createDatabaseIfNotExist=trueto the datasource URL. This is fine for dev/local, but ensure this doesn't inadvertently auto-create databases in production. The setting should ideally be environment-specific or omitted in production if the database is pre-provisioned.Per learnings, hard-coded dev credentials in
application.propertiesare acceptable for this project, so Lines 7–8 (DB_USER:root,DB_PASSWORD:rootdefaults) are approved. Based on learnings, hard-coded development credentials are intentional and acceptable for the fungover/zipp project.backend/pom.xml (1)
79-95: Verify OAuth2 client starter artifactId and dependency alignmentThe added dependencies make sense for this PR: security, OAuth2 client, and
spring-security-testfor youroauth2Login()-based tests.One thing to double‑check: historically the OAuth2 client starter has been named
spring-boot-starter-oauth2-client. Here it’sspring-boot-starter-security-oauth2-client(line 89). If Spring Boot 4.0.0 indeed introduced this new artifact, you’re fine; if not, you may need to switch to the standard artifactId to avoid resolution failures, e.g.:- <artifactId>spring-boot-starter-security-oauth2-client</artifactId> + <artifactId>spring-boot-starter-oauth2-client</artifactId>Also ensure your dependency tree doesn’t accidentally pull conflicting security versions when you add both
spring-boot-starter-securityand the OAuth2 starter.backend/src/main/java/org/fungover/zipp/security/SecurityConfig.java (1)
22-37: Confirm that default CSRF + session behavior matches your intended clientsThe config currently uses the Spring Security defaults for CSRF and session management, which is fine for a browser-based OAuth2 flow but can cause 403s for non-GET requests from SPAs or API clients if you later add such endpoints. Please double‑check that a stateful, session‑based setup with CSRF protection is what you want for this application before you start adding write endpoints.
|
|
||
| # JPA / Hibernate | ||
| spring.jpa.hibernate.ddl-auto=validate | ||
| spring.jpa.hibernate.ddl-auto=update |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's see the full application.properties file
cat -n backend/src/main/resources/application.propertiesRepository: fungover/zipp
Length of output: 735
🏁 Script executed:
# Check for environment-specific profile files
fd -H 'application.*properties' backend/src/main/resources/Repository: fungover/zipp
Length of output: 160
🏁 Script executed:
# Search for Flyway configuration
rg -i 'flyway' backend/src/main/resources/ -A 2 -B 2Repository: fungover/zipp
Length of output: 556
🏁 Script executed:
# Check for .env references and imports
rg 'spring.config.import|\.env' backend/src/main/resources/ -A 1 -B 1Repository: fungover/zipp
Length of output: 362
🏁 Script executed:
# Look for any version control history or indication of the original value
git log -n 5 --oneline -- backend/src/main/resources/application.properties 2>/dev/null || echo "No git history available"Repository: fungover/zipp
Length of output: 120
🏁 Script executed:
# Check the application-dev.properties content to see if it overrides DDL-auto
cat -n backend/src/main/resources/application-dev.propertiesRepository: fungover/zipp
Length of output: 574
Revert DDL-auto to validate in global config and establish proper environment profiles.
Line 15 sets spring.jpa.hibernate.ddl-auto=update globally, which applies to all environments including production. The update mode automatically modifies the database schema at runtime—dangerously unsafe for production. While application-dev.properties (line 6) also declares update, it doesn't override the global value; it only duplicates it. This means production environments will inherit update mode unless an application-prod.properties profile exists to override it.
Additionally, Flyway migrations (lines 11–12) are enabled globally and compete with Hibernate's DDL-auto for schema management. Running both simultaneously undermines Flyway's migration guarantees and can cause schema conflicts. Flyway should have exclusive control over schema changes.
Fix: Move spring.jpa.hibernate.ddl-auto=update from application.properties to application-dev.properties only. Add application-prod.properties with spring.jpa.hibernate.ddl-auto=validate for production safety. Consider disabling Hibernate's DDL-auto entirely (validate or none) and rely solely on Flyway for schema management across all environments.
- spring.jpa.hibernate.ddl-auto=update
+ spring.jpa.hibernate.ddl-auto=validateCreate application-prod.properties with:
spring.config.activate.on-profile=prod
spring.jpa.hibernate.ddl-auto=validate
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| spring.jpa.hibernate.ddl-auto=update | |
| spring.jpa.hibernate.ddl-auto=validate |
🤖 Prompt for AI Agents
In backend/src/main/resources/application.properties around line 15, the global
setting spring.jpa.hibernate.ddl-auto=update is unsafe for production and
conflicts with Flyway; remove this key from application.properties (so Hibernate
DDL-auto is not set globally), add spring.jpa.hibernate.ddl-auto=update only to
application-dev.properties, and create a new application-prod.properties that
activates the prod profile and sets spring.jpa.hibernate.ddl-auto=validate
(spring.config.activate.on-profile=prod and
spring.jpa.hibernate.ddl-auto=validate) so Flyway remains the authoritative
schema manager in production.
| package org.fungover.zipp.AuthTest; | ||
|
|
||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; | ||
| import org.springframework.security.config.Customizer; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| import org.springframework.security.oauth2.core.user.DefaultOAuth2User; | ||
| import org.springframework.security.oauth2.core.user.OAuth2User; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
|
||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| public class AuthenticationIntegrationTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @Test | ||
| void testNotLoggedInUserRedirectedToLogin() throws Exception { | ||
| mockMvc.perform(get("/me")) | ||
| .andExpect((status().is3xxRedirection())); | ||
| } | ||
|
|
||
| @Test | ||
| void testPublicEndpointDoesNotRequiredAuth() throws Exception { | ||
| mockMvc.perform(get("/")) | ||
| .andExpect((status().isOk())); | ||
| } | ||
|
|
||
| @Test | ||
| void testLoggedInUser() throws Exception { | ||
| OAuth2User mockUser = new DefaultOAuth2User( | ||
| List.of(new SimpleGrantedAuthority("USER")), | ||
| Map.of( | ||
| "sub", "mock-google-id-12345", | ||
| "name", "Mock User", | ||
| "email", "mock@example.com" | ||
| ), | ||
| "sub" | ||
| ); | ||
|
|
||
| mockMvc.perform(get("/me") | ||
| .with(oauth2Login().oauth2User(mockUser))) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(content().string(org.hamcrest.Matchers.containsString("Hello Mock User"))) | ||
| .andExpect(content().string(org.hamcrest.Matchers.containsString("mock@example.com"))); | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Spring Boot AutoConfigureMockMvc correct import package
💡 Result:
Use:
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Example:
@SpringBootTest
@AutoConfigureMockMvc
class MyTests { /* ... */ }
Sources: [1] Spring Boot reference docs (testing). [2] Spring Boot API (AutoConfigureMockMvc).
Fix incorrect AutoConfigureMockMvc import to prevent compilation error
The tests use @AutoConfigureMockMvc, but the imported package path is incorrect:
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;The correct import is from org.springframework.boot.test.autoconfigure.web.servlet. Update to:
-import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;Your three test cases provide good coverage: unauthenticated redirect to login on /me, public access to /, and authenticated user content verification via oauth2Login().
🤖 Prompt for AI Agents
In
backend/src/test/java/org/fungover/zipp/AuthTest/AuthenticationIntegrationTest.java
around lines 1 to 59, the test class imports AutoConfigureMockMvc from the wrong
package
(org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc);
replace that import with
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc so
the annotation resolves correctly, then recompile/run tests to confirm the
compilation error is fixed.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
backend/src/main/java/org/fungover/zipp/entity/User.java (1)
30-32: Defaultroleto avoid nulls against non-null columnSince
roleis mapped asnullable = false, it’s safer to give it a default (e.g.Role.USER) so new entities aren’t accidentally persisted with a null role if a caller forgets to set it.Example:
- @Enumerated(EnumType.STRING) - @Column(nullable = false) - private Role role; + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private Role role = Role.USER;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/src/main/java/org/fungover/zipp/entity/Role.java(1 hunks)backend/src/main/java/org/fungover/zipp/entity/User.java(1 hunks)
🔇 Additional comments (1)
backend/src/main/java/org/fungover/zipp/entity/Role.java (1)
3-6: Role enum looks good as a minimal authority modelSimple USER/ADMIN enum is clear and adequate as a starting point; no issues from an entity perspective.
EmpyreanMist
left a comment
There was a problem hiding this comment.
We've implemented this code to be able to build further upon it. It's working great and seems to be no problems.
|
I think this code works well and have not found any issues yet. Im working with this branch right now in our own code aswell. Maybe consider adding your work in a package to avoid conflicts? |
Nishune
left a comment
There was a problem hiding this comment.
As earlier stated i think it looks good and is ready to be merged so we can keep working from this code.
* Add Spring Security and OAuth2 dependencies - Done with Henrik and emily * got OAuth working, but need to configure login and logout * Changes by Alfred * Oauth functioning, CustomOAuth2UserService for handling of user(work in progress). flyway migration V2 up. working on logic for user check, oversee entity with role? * added another field for user - role,updated id to use uuid, removed flyway, added support for .env file in root. * pulled in main before push. * added test, and worked out some issues with the oAuth * Add enum for role * Add Role to User entity and add in Service to new user in database * Add Role to User entity and add in Service to new user in database * Add Role to Service to new user in database --------- Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com>
* Add Spring Security and OAuth2 dependencies - Done with Henrik and emily * got OAuth working, but need to configure login and logout * Changes by Alfred * Oauth functioning, CustomOAuth2UserService for handling of user(work in progress). flyway migration V2 up. working on logic for user check, oversee entity with role? * added another field for user - role,updated id to use uuid, removed flyway, added support for .env file in root. * pulled in main before push. * added test, and worked out some issues with the oAuth * Add enum for role * Add Role to User entity and add in Service to new user in database * Add Role to User entity and add in Service to new user in database * Add Role to Service to new user in database --------- Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com>
* Add Spring Security and OAuth2 dependencies - Done with Henrik and emily * got OAuth working, but need to configure login and logout * Changes by Alfred * Oauth functioning, CustomOAuth2UserService for handling of user(work in progress). flyway migration V2 up. working on logic for user check, oversee entity with role? * added another field for user - role,updated id to use uuid, removed flyway, added support for .env file in root. * pulled in main before push. * added test, and worked out some issues with the oAuth * Add enum for role * Add Role to User entity and add in Service to new user in database * Add Role to User entity and add in Service to new user in database * Add Role to Service to new user in database --------- Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com>
* Bean Validation & Report dto * Bean Validation & Report dto * Reports & Images entity New dependency Flyway migration New Repository * Report service and report entity constructor update * ReportController for POST /api/reports * ReportController for POST /api/reports Bonus: GlobalExceptionhandler * temporary: ReportController for GET /api/reports?userId= * Update * GET all reports sorted by status(example) & cleanup * Refactoring * Code format * Add Taikai for architectural constraints (#29) * CodeRabbit resolved and nitpicked * Change to 2 spaces as in main * Add ADR for database schema management strategy (#31) * Add ADR for database schema management strategy detailing transition from Hibernate `ddl-auto=update` to Flyway * Update ADR for database schema management strategy and adjust editorconfig indentation settings * Spring Security + OAuth2 with Google (#45) * Add Spring Security and OAuth2 dependencies - Done with Henrik and emily * got OAuth working, but need to configure login and logout * Changes by Alfred * Oauth functioning, CustomOAuth2UserService for handling of user(work in progress). flyway migration V2 up. working on logic for user check, oversee entity with role? * added another field for user - role,updated id to use uuid, removed flyway, added support for .env file in root. * pulled in main before push. * added test, and worked out some issues with the oAuth * Add enum for role * Add Role to User entity and add in Service to new user in database * Add Role to User entity and add in Service to new user in database * Add Role to Service to new user in database --------- Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com> * Lollo gro/layout (#46) * First setup * Adjusted margin. * Logo * Removed HTML suggested by code rabbit to make fragments pure and adjusted css styling * Additional css adjustments * Merged main. Commented out ("/") in AuthenticationController because RestController uses same endpoint as Controller. Adjusted styling for focus. * ...and so it goes on... css * Changes L to l * 8 ci pipeline (#32) * Docs: Add DEVLOG.md * Chore: Add dependencies CI-pipeline * modified .github/workflows/ci.yml * Fixed errors from CodeRabbit * Fix: Delete plugins not compatible with java25 * Fix: resolve Checkstyle failures in CI job * Fix: Restored BackendApplication.java- trying to handle CI blockages * Fix: Resolve CI issues in BackendApplication.java * Fix: BackendApplication.java = final * Fix: Remove constructor and allow Spring to initiate this class * Fix: Add constructor,I think coderabbit is having a stroke * Fix: Checkstyle problems * Add CI plugins: Spotless, Checkstyle, SpotBugs, JaCoCo, OWASP * Add CI plugins: Spotless, Checkstyle, SpotBugs, JaCoCo, OWASP * Hunted errors in pom.xml, BackendApplication, checkstyle.xml manualy tested with mvn spotless:check mvn checkstyle:check mvn clean verify mvn pmd:check * Hunted errors in pom.xml, BackendApplication, checkstyle.xml manualy tested with mvn spotless:check mvn checkstyle:check mvn clean verify mvn pmd:check * fixed checkstyle errors * fixed Test-files errors * deleted owasp dependency-check-maven * deleted owasp dependency-check-maven * deleted public in AuthenticationIntegrationTest * Fix class naming convention in IndexController * Remove redundant SpotBugs exclusion file and improve constructor clarity in User entity * Remove redundant comment in User entity constructor --------- Co-authored-by: Ronja Fagerdahl <ronjafagerdahl@gmail.com> Co-authored-by: Jörgen Lindström <jorlind@telia.com> Co-authored-by: Martin Blomberg <martin.blomberg@outlook.com> * Spotless style applied * Fixes Checkstyle errors * CodeRabbit resolved * mvn spotless:apply * sonarqubecloud check warning * Add merge_group trigger to CI workflow (#57) * Update application.properties and application.yml according to issue #35 (#56) Co-authored-by: Alfred Brännare <alfred-brannare@hotmail.com> * feat: added docker-compose.yml for local dev mimicing production env (#35) * feat: added continous deployment pipeline, validation on PR creation and deployment on merge to main (#42) * feat: added Jenkinsfile to enable continous deployment of app to our production servers * fix: adjustments to Jenkinsfile * test: added Dockerfile to test CD * fix: dockerfile again * fix: Dockerfile removed * feat: added ability to cache dockerimage from PR creation, to be used on merge - added feedback from pipeline * fix: dockerfile for testing - in the right directory * fix: dockerfile - wrong jdk * fix: dockerfile, again * chore: trigger build * fix: Jenkinsfile - export PATH to trivy to ensure env is available during pipeline-run * feat: add live comments to Jenkinsfile during run * feat: hardening Jenkinsfile credentials * feat: improvments to Jenkinsfile * fix: hardened credentials for local ips failed, reverted to functional state * feat: improvments to Jenkinsfile * fix: syntaxerror Jenkinsfile * fix: syntaxerror Jenkinsfile * test: invalid dockerfile to test logs of CD pipeline * fix: resolve issue where logs on failed pipeline was not commented in the pr * feat: improved log output in pr comments on fail * fix: jenkinsfile again * fix: fix after fix, jenkinsfile * fix: jenkinsfile logs * fix: jenkins... * fix: jenkinsfile, please be final * test: dockerfile test * test: cd fail test * test: test webhook * test: test cd * test: damn cd.. * test: PROGRESS! * test: testtest * test: test cd * test: test cd * test: hopefully, the final test of CD pipeline * feat: moved 'git rev-parse' to checkout-stage to make the pipeline more resillient * feat: added k8s secret reference for spring_datasource_url * feat: added k8s secrets reference for google client id and secret * fix: fixed null Docker tags with delayed env var assignment (#60) * fix: add commit hash fallback and conditional Trivy scan for images * fix: replaced deprecated flag * fix: enable full git clone in checkout for reliable commit hashing * fix: use GIT_COMMIT env for reliable Docker tagging * fix: delay docker_image env var to avoid null tag from early interpolation * Handle Github merge queue branches in Jenkins Pipeline (#62) * fix: enable deployment on GitHub merge queue temp branches via regex checks * fix: resolve syntaxerror regarding disableConcurrentBuilds * fix: removed -o pipefail as it was illegal (#64) * TODO comment * Image validation * jts-core dep update --------- Co-authored-by: Patrik Eriksson <pat_p3@hotmail.com> Co-authored-by: Martin Blomberg <martin.blomberg@outlook.com> Co-authored-by: Brannar3 <alfred-brannare@hotmail.com> Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com> Co-authored-by: Louise <emmalouisekarlsson@hotmail.com> Co-authored-by: Jörgen Lindström <jorgenlindstrom@icloud.com> Co-authored-by: Ronja Fagerdahl <ronjafagerdahl@gmail.com> Co-authored-by: Jörgen Lindström <jorlind@telia.com> Co-authored-by: Dennis Andersen <dennis-andersen@outlook.com>
* Bean Validation & Report dto * Bean Validation & Report dto * Reports & Images entity New dependency Flyway migration New Repository * Report service and report entity constructor update * ReportController for POST /api/reports * ReportController for POST /api/reports Bonus: GlobalExceptionhandler * temporary: ReportController for GET /api/reports?userId= * Update * GET all reports sorted by status(example) & cleanup * Refactoring * Code format * CodeRabbit resolved and nitpicked * Change to 2 spaces as in main * Spotless style applied * Fixes Checkstyle errors * CodeRabbit resolved * mvn spotless:apply * Send Kafka events when Post request is made * Code format * Add Taikai for architectural constraints (#29) * CodeRabbit resolved and nitpicked * Change to 2 spaces as in main * Add ADR for database schema management strategy (#31) * Add ADR for database schema management strategy detailing transition from Hibernate `ddl-auto=update` to Flyway * Update ADR for database schema management strategy and adjust editorconfig indentation settings * Spring Security + OAuth2 with Google (#45) * Add Spring Security and OAuth2 dependencies - Done with Henrik and emily * got OAuth working, but need to configure login and logout * Changes by Alfred * Oauth functioning, CustomOAuth2UserService for handling of user(work in progress). flyway migration V2 up. working on logic for user check, oversee entity with role? * added another field for user - role,updated id to use uuid, removed flyway, added support for .env file in root. * pulled in main before push. * added test, and worked out some issues with the oAuth * Add enum for role * Add Role to User entity and add in Service to new user in database * Add Role to User entity and add in Service to new user in database * Add Role to Service to new user in database --------- Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com> * Lollo gro/layout (#46) * First setup * Adjusted margin. * Logo * Removed HTML suggested by code rabbit to make fragments pure and adjusted css styling * Additional css adjustments * Merged main. Commented out ("/") in AuthenticationController because RestController uses same endpoint as Controller. Adjusted styling for focus. * ...and so it goes on... css * Changes L to l * 8 ci pipeline (#32) * Docs: Add DEVLOG.md * Chore: Add dependencies CI-pipeline * modified .github/workflows/ci.yml * Fixed errors from CodeRabbit * Fix: Delete plugins not compatible with java25 * Fix: resolve Checkstyle failures in CI job * Fix: Restored BackendApplication.java- trying to handle CI blockages * Fix: Resolve CI issues in BackendApplication.java * Fix: BackendApplication.java = final * Fix: Remove constructor and allow Spring to initiate this class * Fix: Add constructor,I think coderabbit is having a stroke * Fix: Checkstyle problems * Add CI plugins: Spotless, Checkstyle, SpotBugs, JaCoCo, OWASP * Add CI plugins: Spotless, Checkstyle, SpotBugs, JaCoCo, OWASP * Hunted errors in pom.xml, BackendApplication, checkstyle.xml manualy tested with mvn spotless:check mvn checkstyle:check mvn clean verify mvn pmd:check * Hunted errors in pom.xml, BackendApplication, checkstyle.xml manualy tested with mvn spotless:check mvn checkstyle:check mvn clean verify mvn pmd:check * fixed checkstyle errors * fixed Test-files errors * deleted owasp dependency-check-maven * deleted owasp dependency-check-maven * deleted public in AuthenticationIntegrationTest * Fix class naming convention in IndexController * Remove redundant SpotBugs exclusion file and improve constructor clarity in User entity * Remove redundant comment in User entity constructor --------- Co-authored-by: Ronja Fagerdahl <ronjafagerdahl@gmail.com> Co-authored-by: Jörgen Lindström <jorlind@telia.com> Co-authored-by: Martin Blomberg <martin.blomberg@outlook.com> * Spotless style applied * Fixes Checkstyle errors * CodeRabbit resolved * mvn spotless:apply * sonarqubecloud check warning * Add merge_group trigger to CI workflow (#57) * Update application.properties and application.yml according to issue #35 (#56) Co-authored-by: Alfred Brännare <alfred-brannare@hotmail.com> * feat: added docker-compose.yml for local dev mimicing production env (#35) * feat: added continous deployment pipeline, validation on PR creation and deployment on merge to main (#42) * feat: added Jenkinsfile to enable continous deployment of app to our production servers * fix: adjustments to Jenkinsfile * test: added Dockerfile to test CD * fix: dockerfile again * fix: Dockerfile removed * feat: added ability to cache dockerimage from PR creation, to be used on merge - added feedback from pipeline * fix: dockerfile for testing - in the right directory * fix: dockerfile - wrong jdk * fix: dockerfile, again * chore: trigger build * fix: Jenkinsfile - export PATH to trivy to ensure env is available during pipeline-run * feat: add live comments to Jenkinsfile during run * feat: hardening Jenkinsfile credentials * feat: improvments to Jenkinsfile * fix: hardened credentials for local ips failed, reverted to functional state * feat: improvments to Jenkinsfile * fix: syntaxerror Jenkinsfile * fix: syntaxerror Jenkinsfile * test: invalid dockerfile to test logs of CD pipeline * fix: resolve issue where logs on failed pipeline was not commented in the pr * feat: improved log output in pr comments on fail * fix: jenkinsfile again * fix: fix after fix, jenkinsfile * fix: jenkinsfile logs * fix: jenkins... * fix: jenkinsfile, please be final * test: dockerfile test * test: cd fail test * test: test webhook * test: test cd * test: damn cd.. * test: PROGRESS! * test: testtest * test: test cd * test: test cd * test: hopefully, the final test of CD pipeline * feat: moved 'git rev-parse' to checkout-stage to make the pipeline more resillient * feat: added k8s secret reference for spring_datasource_url * feat: added k8s secrets reference for google client id and secret * fix: fixed null Docker tags with delayed env var assignment (#60) * fix: add commit hash fallback and conditional Trivy scan for images * fix: replaced deprecated flag * fix: enable full git clone in checkout for reliable commit hashing * fix: use GIT_COMMIT env for reliable Docker tagging * fix: delay docker_image env var to avoid null tag from early interpolation * Handle Github merge queue branches in Jenkins Pipeline (#62) * fix: enable deployment on GitHub merge queue temp branches via regex checks * fix: resolve syntaxerror regarding disableConcurrentBuilds * fix: removed -o pipefail as it was illegal (#64) * TODO comment * Image validation * feat: Made sure POST report works in Insomnia - Added Dev configuration in SecurityConfig to permit all requests in dev mode - Added jackson dependencies - Fixed: Some local server and database issues Co-authored-by: Johnny Åström <johnny.astrom@hotmail.com> Co-authored-by: Taru Keskinen <tarukeskinen@hotmail.com> * fix: Fixed duplicate dependencies in pom file Co-authored-by: Taru tarukeskinen@hotmail.com Co-authored-by: Viktor vikkerinho@gmail.com * fix: Fixed duplicate dependencies in pom file Co-authored-by: Taru tarukeskinen@hotmail.com Co-authored-by: Viktor vikkerinho@gmail.com * fix: security chain conflict by prioritizing dev configuration Co-authored-by: tarukeskinen@hotmail.com Co-authored-by: vikkerinho@gmail.com * minor fix: run spotless and checkstyle. Co-authored-by: Taru Potter tarukeskinen@hotmail.com Co-authored-by: Viktor Eriksson vikkerinho@gmail.com Co-authored-by: Alexander Andersson alle7000.andersson@gmail.com * maybe fix: issues with jenkins failing when pushing to github * Fixed according to Code Rabbit suggestions - Kafka send potential exceptions in ReportController - Removed old version of lz4 from pom.xml Co-authored-by: Taru Keskinen tarukeskinen@hotmail.com Co-authored-by: Johnny Åström johnny.astrom@hotmail.com * Apply code formatting Co-authored-by: Taru Keskinen <tarukeskinen@hotmail.com> Co-authored-by: Johnny Åström <johnny.astrom@hotmail.com> * Apply code formatting Co-authored-by: Taru Keskinen <tarukeskinen@hotmail.com> Co-authored-by: Johnny Åström <johnny.astrom@hotmail.com> --------- Co-authored-by: Kirill <kirillsavorin@gmail.com> Co-authored-by: Martin Blomberg <martin.blomberg@outlook.com> Co-authored-by: ViktorNoskire <vikkerinho@gmail.com> Co-authored-by: Patrik Eriksson <pat_p3@hotmail.com> Co-authored-by: Brannar3 <alfred-brannare@hotmail.com> Co-authored-by: Henrik <Henrikmattsson89@gmail.com> Co-authored-by: Emilyempa <emilypettersson@hotmail.com> Co-authored-by: Louise <emmalouisekarlsson@hotmail.com> Co-authored-by: Jörgen Lindström <jorgenlindstrom@icloud.com> Co-authored-by: Ronja Fagerdahl <ronjafagerdahl@gmail.com> Co-authored-by: Jörgen Lindström <jorlind@telia.com> Co-authored-by: Dennis Andersen <dennis-andersen@outlook.com> Co-authored-by: Kirill <127823714+Kirill9m@users.noreply.github.com> Co-authored-by: Johnny Åström <johnny.astrom@hotmail.com>
Description
This PR sets up
Spring SecuritywithOAuth2Google Authentication.Resolves issue #4
What's included
/has.permitAll().CustomOAuth2UserServicefor future business logic, currently this is where we check if the user exists in the database, if not we save them. Queried byfindByProviderAndProviderId(provider, providerId).GET /meendpoint for showcasing how the extract information from theAuthenticationPrincipal.Userentity for saving users to our database:id: Autogenerated UUIDname: Extracted fromOAuth2UserRequestemail: Extracted fromOAuth2UserRequestprovider: Extracted fromOAuth2UserRequestproviderId: Extracted fromOAuth2UserRequestrole: Adds role User as defaultcreatedAt: Default LocalDateTimeUserRepositorythat extendsJpaRepository<User, UUID>.Testing
AuthenticationIntegrationTestWe tried creating a test for
CustomOAuth2Servicebut we didn't quite get it to work properly so we excluded it. Either the test was green or the application was working, not both at the same time though.To try this
.envin root with keys provided in DiscordDO NOT COMMIT ENV FILE
/me/meshould also showcase yourname,emailandid.Contributors:
Summary by CodeRabbit
Release Notes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.