Skip to content

Commit

Permalink
fix: get userIdClaim variable at runtime
Browse files Browse the repository at this point in the history
There is some incompatibility with native executable, please vide the exception below.

```
- the runtime value of 'quarkus.rest-client.rems_yaml.user-id-claim' is [sub] but the value [null] was injected into io.github.genomicdatainfrastructure.daam.security.PostAuthenticationFilter()
```
  • Loading branch information
brunopacheco1 committed Sep 16, 2024
1 parent 3f08c43 commit 50647ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.ext.Provider;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import java.util.Optional;
import org.eclipse.microprofile.config.ConfigProvider;

import static io.github.genomicdatainfrastructure.daam.api.ApplicationQueryApiImpl.DEFAULT_USER_ID_CLAIM;

Expand All @@ -27,22 +25,22 @@ public class PostAuthenticationFilter implements ContainerRequestFilter {

private final SecurityIdentity identity;
private final CreateRemsUserService createRemsUserService;
private final Optional<String> userIdClaim;

@Inject
public PostAuthenticationFilter(
SecurityIdentity identity,
CreateRemsUserService createRemsUserService,
@ConfigProperty(name = "quarkus.rest-client.rems_yaml.user-id-claim") Optional<String> userIdClaim
CreateRemsUserService createRemsUserService
) {
this.identity = identity;
this.createRemsUserService = createRemsUserService;
this.userIdClaim = userIdClaim;
}

@Override
public void filter(ContainerRequestContext requestContext) {
if (!identity.isAnonymous()) {
var userIdClaim = ConfigProvider.getConfig().getOptionalValue(
"quarkus.rest-client.rems_yaml.user-id-claim", String.class);

var oidcPrincipal = (OidcJwtCallerPrincipal) identity.getPrincipal();

createRemsUserService.createRemsUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.util.Optional.of;
import static org.mockito.Mockito.*;

@QuarkusTest
Expand All @@ -29,8 +28,7 @@ class PostAuthenticationFilterTest {

@BeforeEach
void setUp() {
underTest = new PostAuthenticationFilter(securityIdentity, createRemsUserService, of(
"sub"));
underTest = new PostAuthenticationFilter(securityIdentity, createRemsUserService);
}

@Test
Expand Down

0 comments on commit 50647ff

Please sign in to comment.