Skip to content
Snippets Groups Projects
Commit 80aef6a4 authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Change scope to vararg since there can be multiple scope for one client configuration

parent 84dbe784
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
...@@ -17,10 +17,10 @@ public interface Sender { ...@@ -17,10 +17,10 @@ public interface Sender {
* *
* @param clientId - a unique identifier within the FIT-Co platform environment * @param clientId - a unique identifier within the FIT-Co platform environment
* @param clientSecret - a secret that is only known by the application and the OAuth server * @param clientSecret - a secret that is only known by the application and the OAuth server
* @param scope - OAuth scope that determines if a submission is accepted by the client * @param scope - OAuth scope(s) that determines if a submission is accepted by the client
* @return {@link OAuthToken} that holds the access-token * @return {@link OAuthToken} that holds the access-token
*/ */
OAuthToken retrieveAuthenticationToken(final String clientId, final String clientSecret, String scope); OAuthToken retrieveAuthenticationToken(final String clientId, final String clientSecret, String... scope);
// TODO // TODO
ValidationResult validateCertificateChain(byte[] chain); ValidationResult validateCertificateChain(byte[] chain);
......
...@@ -4,5 +4,5 @@ import java.util.Optional; ...@@ -4,5 +4,5 @@ import java.util.Optional;
public interface OAuthService { public interface OAuthService {
Optional<OAuthToken> authenticate(String clientId, String clientSecret, String scope); Optional<OAuthToken> authenticate(String clientId, String clientSecret, String... scope);
} }
...@@ -10,6 +10,7 @@ import java.net.URI; ...@@ -10,6 +10,7 @@ import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -31,7 +32,7 @@ public class FitCoAuthService implements OAuthService { ...@@ -31,7 +32,7 @@ public class FitCoAuthService implements OAuthService {
} }
@Override @Override
public Optional<OAuthToken> authenticate(String clientId, String clientSecret, String scope) { public Optional<OAuthToken> authenticate(String clientId, String clientSecret, String... scope) {
final String requestBody = buildRequestBody(clientId, clientSecret, scope); final String requestBody = buildRequestBody(clientId, clientSecret, scope);
try { try {
return Optional.of(performTokenRequest(requestBody)); return Optional.of(performTokenRequest(requestBody));
...@@ -41,14 +42,15 @@ public class FitCoAuthService implements OAuthService { ...@@ -41,14 +42,15 @@ public class FitCoAuthService implements OAuthService {
} }
} }
private String buildRequestBody(String clientId, String clientSecret, String scope) { private String buildRequestBody(String clientId, String clientSecret, String... scope) {
var data = new HashMap<String, String>() {{ var data = new HashMap<String, String>() {{
put("grant_type", "client_credentials"); put("grant_type", "client_credentials");
put("client_id", clientId); put("client_id", clientId);
put("client_secret", clientSecret); put("client_secret", clientSecret);
put("scope", scope);
}}; }};
Arrays.stream(scope).forEach(s -> data.put("scope", s));
return data.entrySet() return data.entrySet()
.stream() .stream()
.map(e -> e.getKey() + "=" + e.getValue()) .map(e -> e.getKey() + "=" + e.getValue())
......
...@@ -18,7 +18,7 @@ public class SubmissionSender implements Sender { ...@@ -18,7 +18,7 @@ public class SubmissionSender implements Sender {
} }
@Override @Override
public OAuthToken retrieveAuthenticationToken(String clientId, String clientSecret, String scope) { public OAuthToken retrieveAuthenticationToken(String clientId, String clientSecret, String... scope) {
return authService.authenticate(clientId, clientSecret, scope).orElseThrow(); return authService.authenticate(clientId, clientSecret, scope).orElseThrow();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment