Skip to content
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

Adapt single tenant token keys requests #1407

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

liga-oz
Copy link
Contributor

@liga-oz liga-oz commented Dec 20, 2023

No description provided.

@@ -94,11 +94,21 @@ private PublicKey fetchPublicKey(Token token, JwtSignatureAlgorithm algorithm) t
return tokenKeyService.getPublicKey(algorithm, keyId, uri, params);
}

private String composeZidQueryParameter(Token token) {
String composeQueryParameters(Token token) {
Copy link
Contributor

@finkmanAtSap finkmanAtSap Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about one of the following alternatives that, albeit not shorter, are probably more expressive / easier to maintain? Too much overhead?

String composeQueryParameters(Token token) {
        String query = 
                Map.of("zid", Objects.requireNonNullElse(token.getAppTid(), ""),
                        "client_id", Objects.requireNonNullElse(configuration.getClientId(), ""))
                .entrySet().stream()
                .filter(entry -> !entry.getValue().isBlank())
                .map(entry -> entry.getKey() + "=" + entry.getValue())
                .sorted()
                .collect(Collectors.joining("&", "?", ""));

        query = Objects.equals("?", query) ? "" : query;

        LOGGER.debug("Composed query parameter for token keys: {}", query);
        return query;
    }
String composeQueryParameters(Token token) {
        List<Map.Entry<String, String>> parameters = 
                Map.of("zid", Objects.requireNonNullElse(token.getAppTid(), ""),
                        "client_id", Objects.requireNonNullElse(configuration.getClientId(), ""))
                .entrySet().stream()
                .filter(entry -> !entry.getValue().isBlank())
                .collect(Collectors.toList());
        
        String query = parameters.isEmpty()
                ? ""
                : parameters.stream()
                .map(entry -> entry.getKey() + "=" + entry.getValue())
                .sorted()
                .collect(Collectors.joining("&", "?", ""));

        LOGGER.debug("Composed query parameter for token keys: {}", query);
        return query;
    }

String zid = token.getAppTid();
String clientId = token.getClientId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be changed to

configuration.getClientId()

})
void composeQueryParams(String clientId, String appTid, String query) {
Token tokenMock = Mockito.mock(Token.class);
Mockito.when(tokenMock.getClientId()).thenReturn(clientId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this must be changed to

Mockito.when(mockConfiguration.getClientId()).thenReturn(clientId);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants