-
Notifications
You must be signed in to change notification settings - Fork 0
Development: Add credential-based login and refactor authentication flow
#32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f2280f2
Add username and password fields to StartAnalysis component
JanaNF 77bd888
Remove log following and shutdown handling from docker_start.sh
JanaNF 33b7407
Remove application.yml configuration file
JanaNF e852fb0
Implement credential-based login functionality with JWT authentication
JanaNF 3236872
Implement dynamic authentication and repository fetching with encrypt…
JanaNF df7eef0
Refactor data transformation comments and add start analysis flow dia…
JanaNF a68c450
Refactor authentication flow in start_analysis_flow diagram to includ…
JanaNF 1078750
Remove application.yml from .gitignore and add configuration file for…
JanaNF 863873d
chore: update OpenAPI spec and generated client
github-actions[bot] 3895c81
Refactor authentication and encryption logic; update API calls to rem…
JanaNF 82e023e
Merge branch 'feature/credential-login' of https://github.com/ls1intu…
JanaNF dd6f1be
feat: add validation to LoginRequestDTO and simplify AuthController l…
JanaNF 1c93849
refactor: clean up code formatting and remove unused imports in vario…
JanaNF 750c651
chore: update OpenAPI spec and generated client
github-actions[bot] d268969
Remove accidentally pushed team repos and add Projects/ to gitignore
JanaNF d87624d
fix: remove optional parameters from onStart function in StartAnalysi…
JanaNF 18eb5b6
feat: implement AuthResource for user authentication and cookie manag…
JanaNF 8781966
feat: introduce GitOperationException for improved error handling in …
JanaNF 56cce72
fix: remove redundant exception rethrow in authenticate method
JanaNF 32aea4c
feat: refactor authentication handling to use ArtemisCredentials DTO …
JanaNF 8563039
feat: add TestCredentialsLoader for dynamic authentication and manage…
JanaNF 583439c
Merge main and resolve conflicts in dataLoaders.ts
JanaNF 1943d1b
fix: update TODO comments to use 'server' instead of 'backend' for co…
JanaNF f69b5ac
chore: update OpenAPI spec and generated client
github-actions[bot] 24ceefd
fix: remove trailing whitespace in ArtemisCredentials methods for cle…
JanaNF b27abe8
Merge branch 'feature/credential-login' of https://github.com/ls1intu…
JanaNF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,3 +35,6 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| Projects/ | ||
| test-credentials.properties | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| @startuml StartAnalysisFlow | ||
| title Start Analysis Flow | ||
|
|
||
| actor User | ||
| participant "Client (React)" as Client | ||
| participant "AuthController" as Auth | ||
| participant "RequestResource" as Controller | ||
| participant "RequestService" as ReqService | ||
| participant "RepositoryFetchingService" as RepoService | ||
| participant "ArtemisClientService" as ArtemisClient | ||
| participant "GitOperationsService" as GitService | ||
| participant "Artemis Server" as Artemis | ||
| participant "Git Server" as Git | ||
|
|
||
| == Authentication Phase == | ||
| User -> Client: Enter Credentials & Click "Start" | ||
| Client -> Auth: POST /api/auth/login | ||
| note right of Client: Sends username, password, serverUrl | ||
| Auth -> ArtemisClient: authenticate(url, user, pass) | ||
| ArtemisClient -> Artemis: POST /api/core/public/authenticate | ||
| Artemis --> ArtemisClient: 200 OK (Set-Cookie: jwt) | ||
| ArtemisClient --> Auth: jwtToken | ||
| Auth -> Client: 200 OK (Set-Cookie: jwt, username, password) | ||
| Client -> Client: Navigate to /teams | ||
|
|
||
| == Data Loading Phase == | ||
| Client -> Controller: GET /api/requestResource/fetchAndCloneRepositories | ||
| note right of Client: Cookies included automatically | ||
| Controller -> Controller: Extract & Decrypt Credentials | ||
| Controller -> ReqService: fetchAndCloneRepositories(url, jwt, user, pass) | ||
| ReqService -> RepoService: fetchAndCloneRepositories(url, jwt, user, pass) | ||
|
|
||
| == Fetching Participations == | ||
| RepoService -> ArtemisClient: fetchParticipations(url, jwt) | ||
| ArtemisClient -> Artemis: GET /api/exercise/exercises/{id}/participations | ||
| Artemis --> ArtemisClient: List<ParticipationDTO> | ||
| ArtemisClient --> RepoService: List<ParticipationDTO> | ||
|
|
||
| == Cloning Repositories == | ||
| loop For each Participation | ||
| RepoService -> GitService: cloneOrPullRepository(uri, teamName, user, pass) | ||
| GitService -> Git: git clone / git pull | ||
| note right of GitService: Uses Instructor Username/Password directly | ||
| Git --> GitService: Repository Content | ||
| GitService --> RepoService: Local Path | ||
| end | ||
|
|
||
| == Response Phase == | ||
| RepoService --> ReqService: List<TeamRepositoryDTO> | ||
| ReqService --> Controller: List<TeamRepositoryDTO> | ||
| Controller --> Client: 200 OK (JSON List) | ||
| Client -> Client: Transform Data (Mock Analysis) | ||
| Client -> User: Display Team Cards | ||
|
|
||
| @enduml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/de/tum/cit/aet/core/dto/ArtemisCredentials.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package de.tum.cit.aet.core.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
|
||
| /** | ||
| * DTO holding Artemis authentication credentials. | ||
| * Used to pass credentials through the application layers cleanly. | ||
| */ | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public record ArtemisCredentials( | ||
| String serverUrl, | ||
| String jwtToken, | ||
| String username, | ||
| String password | ||
| ) { | ||
| /** | ||
| * Checks if the credentials contain valid authentication data. | ||
| * | ||
| * @return true if serverUrl and jwtToken are present | ||
| */ | ||
| public boolean isValid() { | ||
| return serverUrl != null && !serverUrl.isBlank() | ||
| && jwtToken != null && !jwtToken.isBlank(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if username/password credentials are available for Git operations. | ||
| * | ||
| * @return true if both username and password are present | ||
| */ | ||
| public boolean hasGitCredentials() { | ||
| return username != null && !username.isBlank() | ||
| && password != null && !password.isBlank(); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/de/tum/cit/aet/core/exceptions/GitOperationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package de.tum.cit.aet.core.exceptions; | ||
|
|
||
| /** | ||
| * Custom exception for errors occurring during Git operations. | ||
| * This class provides a more specific way to catch and handle failures | ||
| * related to cloning, pulling, or other Git functionality. | ||
| */ | ||
| public class GitOperationException extends RuntimeException { | ||
|
|
||
| /** | ||
| * Constructs a new GitOperationException with the specified detail message. | ||
| * | ||
| * @param message the detail message. | ||
| */ | ||
| public GitOperationException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a new GitOperationException with the specified detail message and cause. | ||
| * | ||
| * @param message the detail message. | ||
| * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). | ||
| */ | ||
| public GitOperationException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
src/main/java/de/tum/cit/aet/core/security/CryptoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package de.tum.cit.aet.core.security; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import javax.crypto.Cipher; | ||
| import javax.crypto.spec.GCMParameterSpec; | ||
| import javax.crypto.spec.SecretKeySpec; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.security.MessageDigest; | ||
| import java.security.SecureRandom; | ||
| import java.util.Arrays; | ||
| import java.util.Base64; | ||
|
|
||
| @Service | ||
| public class CryptoService { | ||
|
|
||
| private static final String ALGORITHM = "AES/GCM/NoPadding"; | ||
| private static final int GCM_TAG_LENGTH = 128; | ||
| private static final int GCM_IV_LENGTH = 12; | ||
|
|
||
| private final SecretKeySpec secretKey; | ||
|
|
||
| public CryptoService(@Value("${harmonia.security.secret-key:default-secret-key-change-me-in-prod}") String secret) { | ||
| this.secretKey = generateKey(secret); | ||
| } | ||
|
|
||
| private SecretKeySpec generateKey(String myKey) { | ||
| try { | ||
| byte[] key = myKey.getBytes(StandardCharsets.UTF_8); | ||
| MessageDigest sha = MessageDigest.getInstance("SHA-256"); | ||
| key = sha.digest(key); | ||
| key = Arrays.copyOf(key, 16); // Use only first 128 bit | ||
| return new SecretKeySpec(key, "AES"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Error generating security key", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Encrypts a string using AES encryption. | ||
| * | ||
| * @param strToEncrypt The string to encrypt | ||
| * @return The encrypted string (Base64 encoded) | ||
| */ | ||
| public String encrypt(String strToEncrypt) { | ||
| try { | ||
| byte[] iv = new byte[GCM_IV_LENGTH]; | ||
| new SecureRandom().nextBytes(iv); | ||
| GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); | ||
| Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
| cipher.init(Cipher.ENCRYPT_MODE, secretKey, spec); | ||
| byte[] cipherText = cipher.doFinal(strToEncrypt.getBytes(StandardCharsets.UTF_8)); | ||
| byte[] encrypted = new byte[iv.length + cipherText.length]; | ||
| System.arraycopy(iv, 0, encrypted, 0, iv.length); | ||
| System.arraycopy(cipherText, 0, encrypted, iv.length, cipherText.length); | ||
| return Base64.getEncoder().encodeToString(encrypted); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Error while encrypting", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Decrypts a string using AES encryption. | ||
| * | ||
| * @param strToDecrypt The string to decrypt (Base64 encoded) | ||
| * @return The decrypted string | ||
| */ | ||
| public String decrypt(String strToDecrypt) { | ||
| try { | ||
| byte[] decoded = Base64.getDecoder().decode(strToDecrypt); | ||
| byte[] iv = new byte[GCM_IV_LENGTH]; | ||
| System.arraycopy(decoded, 0, iv, 0, iv.length); | ||
| GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); | ||
| Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
| cipher.init(Cipher.DECRYPT_MODE, secretKey, spec); | ||
| return new String(cipher.doFinal(decoded, GCM_IV_LENGTH, decoded.length - GCM_IV_LENGTH)); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Error while decrypting", e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.