-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bytt ut jetty client med hc 5 (#275)
* Fjerner avhengighet av Jetty * Trenger ikke være avhengig av maskinporten token * Optimize imports * Sett contenttype på part 2
- Loading branch information
Showing
10 changed files
with
119 additions
and
156 deletions.
There are no files selected for viewing
This file contains 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
4 changes: 2 additions & 2 deletions
4
src/main/java/no/ks/fiks/io/klient/AuthenticationStrategy.java
This file contains 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package no.ks.fiks.io.klient; | ||
|
||
import org.eclipse.jetty.client.api.Request; | ||
import org.apache.hc.core5.http.ClassicHttpRequest; | ||
|
||
public interface AuthenticationStrategy { | ||
void setAuthenticationHeaders(Request request); | ||
void setAuthenticationHeaders(ClassicHttpRequest request); | ||
} |
This file contains 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 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
25 changes: 11 additions & 14 deletions
25
src/main/java/no/ks/fiks/io/klient/IntegrasjonAuthenticationStrategy.java
This file contains 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 |
---|---|---|
@@ -1,36 +1,33 @@ | ||
package no.ks.fiks.io.klient; | ||
|
||
import no.ks.fiks.maskinporten.AccessTokenRequest; | ||
import no.ks.fiks.maskinporten.MaskinportenklientOperations; | ||
import org.eclipse.jetty.client.api.Request; | ||
import org.eclipse.jetty.http.HttpHeader; | ||
import org.apache.hc.core5.http.ClassicHttpRequest; | ||
import org.apache.hc.core5.http.HttpHeaders; | ||
import org.apache.hc.core5.http.message.BasicHeader; | ||
|
||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
public class IntegrasjonAuthenticationStrategy implements AuthenticationStrategy { | ||
|
||
static final String INTEGRASJON_ID = "IntegrasjonId"; | ||
|
||
static final String INTEGRASJON_PASSWORD = "IntegrasjonPassord"; | ||
|
||
private final MaskinportenklientOperations maskinportenklient; | ||
private final Supplier<String> maskinportenTokenSupplier; | ||
private final UUID integrasjonId; | ||
private final String integrasjonPassord; | ||
|
||
public IntegrasjonAuthenticationStrategy(MaskinportenklientOperations maskinportenklient, UUID integrasjonId, String integrasjonPassord) { | ||
this.maskinportenklient = maskinportenklient; | ||
public IntegrasjonAuthenticationStrategy(Supplier<String> maskinportenTokenSupplier, UUID integrasjonId, String integrasjonPassord) { | ||
this.maskinportenTokenSupplier = maskinportenTokenSupplier; | ||
this.integrasjonId = integrasjonId; | ||
this.integrasjonPassord = integrasjonPassord; | ||
} | ||
|
||
@Override | ||
public void setAuthenticationHeaders(Request request) { | ||
request.headers(m -> m.add(HttpHeader.AUTHORIZATION, "Bearer " + getAccessToken()) | ||
.add(INTEGRASJON_ID, integrasjonId.toString()) | ||
.add(INTEGRASJON_PASSWORD, integrasjonPassord)); | ||
public void setAuthenticationHeaders(ClassicHttpRequest request) { | ||
request.addHeader(new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + maskinportenTokenSupplier.get())); | ||
request.addHeader(new BasicHeader(INTEGRASJON_ID, integrasjonId.toString())); | ||
request.addHeader(new BasicHeader(INTEGRASJON_PASSWORD, integrasjonPassord)); | ||
} | ||
|
||
private String getAccessToken() { | ||
return maskinportenklient.getAccessToken(AccessTokenRequest.builder().scope("ks:fiks").build()); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package no.ks.fiks.io.klient; | ||
|
||
import org.eclipse.jetty.client.api.Request; | ||
|
||
import java.io.Closeable; | ||
import org.apache.hc.core5.http.ClassicHttpRequest; | ||
import org.apache.hc.core5.http.HttpEntity; | ||
|
||
/** | ||
* Factory for nye send requester | ||
*/ | ||
public interface RequestFactory extends Closeable { | ||
public interface RequestFactory { | ||
|
||
/** | ||
* Oppretter ny {@link Request} for å sende til fiks-io | ||
* Oppretter ny {@link ClassicHttpRequest} for å sende til fiks-io | ||
* @param contentProvider innhold som skal sendes | ||
* @return en ny {@link Request} | ||
* @return en ny {@link ClassicHttpRequest} | ||
*/ | ||
Request createSendToFiksIORequest(Request.Content contentProvider); | ||
ClassicHttpRequest createSendToFiksIORequest(HttpEntity contentProvider); | ||
} |
This file contains 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.