Skip to content

Commit 096caa7

Browse files
fix(workspace): resolve architecture test failures and integration test 500s
- Move providers logic from controller to WorkspaceQueryService (fixes controllersAreThin: max 5 constructor params) - Add @PreAuthorize("permitAll()") to public endpoints (fixes controllerMethodsHaveSecurityAnnotations) - Add IdentityProviderController to workspace context test exclusions (fixes dataEndpointsReceiveWorkspaceContext) - Make ensureAuthenticatedGitLabUser gracefully handle missing gitlab_id JWT claim instead of throwing (fixes integration test 500s for users authenticated via GitHub)
1 parent 0486612 commit 096caa7

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

server/application-server/src/main/java/de/tum/in/www1/hephaestus/account/IdentityProviderController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.swagger.v3.oas.annotations.tags.Tag;
55
import java.util.List;
66
import org.springframework.http.ResponseEntity;
7+
import org.springframework.security.access.prepost.PreAuthorize;
78
import org.springframework.web.bind.annotation.GetMapping;
89
import org.springframework.web.bind.annotation.RequestMapping;
910
import org.springframework.web.bind.annotation.RestController;
@@ -24,6 +25,7 @@ public IdentityProviderController(AccountService accountService) {
2425
}
2526

2627
@GetMapping("/identity-providers")
28+
@PreAuthorize("permitAll()")
2729
@Operation(
2830
summary = "List available identity providers",
2931
description = "Returns all enabled identity providers that can be used for login. Public endpoint — no authentication required."

server/application-server/src/main/java/de/tum/in/www1/hephaestus/workspace/WorkspaceProvisioningService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,14 @@ public void ensureAuthenticatedGitLabUser(String serverUrl) {
284284
gitlabId = jwt.getClaim("gitlab_id");
285285
}
286286
if (gitlabId == null) {
287-
throw new IllegalStateException(
288-
"Cannot create GitLab user: gitlab_id claim missing from JWT. " +
289-
"Ensure the user has logged in via GitLab and the gitlab_id mapper is configured in Keycloak."
287+
// The user may have logged in via GitHub (no gitlab_id in JWT).
288+
// Skip user creation — the workspace will still be created, and the
289+
// owner will be resolved from the existing GitHub-linked User entity.
290+
log.info(
291+
"Skipped GitLab user creation: reason=noGitlabIdInJwt, login={}",
292+
LoggingUtils.sanitizeForLog(login)
290293
);
294+
return;
291295
}
292296

293297
upsertGitLabUser(

server/application-server/src/main/java/de/tum/in/www1/hephaestus/workspace/WorkspaceQueryService.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package de.tum.in.www1.hephaestus.workspace;
22

33
import de.tum.in.www1.hephaestus.core.WorkspaceAgnostic;
4+
import de.tum.in.www1.hephaestus.feature.FeatureFlag;
5+
import de.tum.in.www1.hephaestus.feature.FeatureFlagService;
6+
import de.tum.in.www1.hephaestus.gitprovider.common.gitlab.GitLabProperties;
7+
import de.tum.in.www1.hephaestus.gitprovider.github.GitHubProperties;
48
import de.tum.in.www1.hephaestus.gitprovider.repository.Repository;
59
import de.tum.in.www1.hephaestus.gitprovider.user.User;
610
import de.tum.in.www1.hephaestus.gitprovider.user.UserRepository;
11+
import de.tum.in.www1.hephaestus.workspace.dto.WorkspaceProvidersDTO;
712
import java.util.LinkedHashMap;
813
import java.util.List;
914
import java.util.Optional;
@@ -31,17 +36,42 @@ public class WorkspaceQueryService {
3136
private final WorkspaceMembershipRepository workspaceMembershipRepository;
3237
private final RepositoryToMonitorRepository repositoryToMonitorRepository;
3338
private final UserRepository userRepository;
39+
private final GitHubProperties gitHubProperties;
40+
private final GitLabProperties gitLabProperties;
41+
private final FeatureFlagService featureFlagService;
3442

3543
public WorkspaceQueryService(
3644
WorkspaceRepository workspaceRepository,
3745
WorkspaceMembershipRepository workspaceMembershipRepository,
3846
RepositoryToMonitorRepository repositoryToMonitorRepository,
39-
UserRepository userRepository
47+
UserRepository userRepository,
48+
GitHubProperties gitHubProperties,
49+
GitLabProperties gitLabProperties,
50+
FeatureFlagService featureFlagService
4051
) {
4152
this.workspaceRepository = workspaceRepository;
4253
this.workspaceMembershipRepository = workspaceMembershipRepository;
4354
this.repositoryToMonitorRepository = repositoryToMonitorRepository;
4455
this.userRepository = userRepository;
56+
this.gitHubProperties = gitHubProperties;
57+
this.gitLabProperties = gitLabProperties;
58+
this.featureFlagService = featureFlagService;
59+
}
60+
61+
/**
62+
* Returns available workspace creation providers based on server configuration.
63+
*/
64+
public WorkspaceProvidersDTO getAvailableProviders() {
65+
var github =
66+
gitHubProperties.app().id() > 0 && gitHubProperties.app().installationUrl() != null
67+
? new WorkspaceProvidersDTO.GitHubProviderDTO(gitHubProperties.app().installationUrl())
68+
: null;
69+
70+
var gitlab = featureFlagService.isEnabled(FeatureFlag.GITLAB_WORKSPACE_CREATION)
71+
? new WorkspaceProvidersDTO.GitLabProviderDTO(gitLabProperties.defaultServerUrl())
72+
: null;
73+
74+
return new WorkspaceProvidersDTO(github, gitlab);
4575
}
4676

4777
/**

server/application-server/src/main/java/de/tum/in/www1/hephaestus/workspace/WorkspaceRegistryController.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import de.tum.in.www1.hephaestus.feature.FeatureFlag;
44
import de.tum.in.www1.hephaestus.feature.FeatureFlagService;
5-
import de.tum.in.www1.hephaestus.gitprovider.common.gitlab.GitLabProperties;
6-
import de.tum.in.www1.hephaestus.gitprovider.github.GitHubProperties;
75
import de.tum.in.www1.hephaestus.workspace.dto.CreateWorkspaceRequestDTO;
86
import de.tum.in.www1.hephaestus.workspace.dto.GitLabGroupDTO;
97
import de.tum.in.www1.hephaestus.workspace.dto.GitLabPreflightRequestDTO;
@@ -47,26 +45,16 @@ public class WorkspaceRegistryController {
4745
private final WorkspaceProvisioningService workspaceProvisioningService;
4846
private final GitLabPreflightService gitLabPreflightService;
4947
private final FeatureFlagService featureFlagService;
50-
private final GitHubProperties gitHubProperties;
51-
private final GitLabProperties gitLabProperties;
5248

5349
@GetMapping("/providers")
5450
@Operation(
5551
summary = "List available workspace creation providers",
5652
description = "Returns available workspace providers with their configuration. Public endpoint — no authentication required."
5753
)
5854
@io.swagger.v3.oas.annotations.security.SecurityRequirements
55+
@PreAuthorize("permitAll()")
5956
public ResponseEntity<WorkspaceProvidersDTO> getProviders() {
60-
var github =
61-
gitHubProperties.app().id() > 0 && gitHubProperties.app().installationUrl() != null
62-
? new WorkspaceProvidersDTO.GitHubProviderDTO(gitHubProperties.app().installationUrl())
63-
: null;
64-
65-
var gitlab = featureFlagService.isEnabled(FeatureFlag.GITLAB_WORKSPACE_CREATION)
66-
? new WorkspaceProvidersDTO.GitLabProviderDTO(gitLabProperties.defaultServerUrl())
67-
: null;
68-
69-
return ResponseEntity.ok(new WorkspaceProvidersDTO(github, gitlab));
57+
return ResponseEntity.ok(workspaceQueryService.getAvailableProviders());
7058
}
7159

7260
@PostMapping

server/application-server/src/test/java/de/tum/in/www1/hephaestus/architecture/MultiTenancyArchitectureTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,11 @@ public void check(JavaMethod method, ConditionEvents events) {
897897

898898
// Skip user account operations - these are USER-scoped, not WORKSPACE-scoped.
899899
// Users can access their account settings regardless of workspace context.
900-
if (controllerName.contains("Account") || controllerName.contains("FeatureFlag")) {
900+
if (
901+
controllerName.contains("Account") ||
902+
controllerName.contains("FeatureFlag") ||
903+
controllerName.contains("IdentityProvider")
904+
) {
901905
return;
902906
}
903907

0 commit comments

Comments
 (0)