Skip to content

Commit

Permalink
Added possibility to get idp token for pre-warming
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelB committed Nov 10, 2023
1 parent e1f8f67 commit 89e9ca7
Show file tree
Hide file tree
Showing 9 changed files with 10,033 additions and 360 deletions.
6,032 changes: 5,826 additions & 206 deletions openapi/openapi.json

Large diffs are not rendered by default.

4,281 changes: 4,147 additions & 134 deletions openapi/openapi.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Context;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class ERezeptWorkflowResource {
HttpServletRequest httpServletRequest;

@POST
@Path("/task")
@Path("task")
public Response createERezeptTask(@HeaderParam("accept") String accept, @QueryParam("flowtype") String flowtype) {

if(flowtype == null) {
Expand All @@ -69,7 +69,7 @@ static RuntimeConfig extractRuntimeConfigFromHeaders(HttpServletRequest httpServ
}

@POST
@Path("/sign")
@Path("sign")
public Response signBundleWithIdentifiers(@HeaderParam("Content-Type") String contentType, String bundle) throws DataFormatException, ERezeptWorkflowException {
Bundle bundleObject = string2bundle(contentType, bundle);
SignResponse signResponse = eRezeptWorkflowService.signBundleWithIdentifiers(bundleObject, false, extractRuntimeConfigFromHeaders(httpServletRequest));
Expand All @@ -87,7 +87,7 @@ static Bundle string2bundle(String contentType, String bundle) {
}

@POST
@Path("/batch-sign")
@Path("batch-sign")
public Response signBundlesWithIdentifiers(@HeaderParam("Content-Type") String contentType, String bundles) throws DataFormatException, ERezeptWorkflowException {
List<Bundle> bundlesList = Arrays.asList(bundles.split("\\r?\\n")).stream().map((bundle) -> string2bundle(contentType, bundle)).collect(Collectors.toList());
List<SignResponse> signResponse = eRezeptWorkflowService.signBundleWithIdentifiers(bundlesList, false, extractRuntimeConfigFromHeaders(httpServletRequest));
Expand All @@ -96,7 +96,7 @@ public Response signBundlesWithIdentifiers(@HeaderParam("Content-Type") String c
}

@GET
@Path("/cards")
@Path("cards")
public GetCardsResponse cards() {
try {
return eRezeptWorkflowService.getCards(extractRuntimeConfigFromHeaders(httpServletRequest));
Expand All @@ -106,43 +106,51 @@ public GetCardsResponse cards() {
}

@POST
@Path("/update")
@Path("update")
public Response updateERezeptTask(UpdateERezept updateERezept) {
eRezeptWorkflowService.updateERezeptTask(updateERezept.getTaskId(), updateERezept.getAccessCode(), Base64.getDecoder().decode(updateERezept.getSignedBytes()), extractRuntimeConfigFromHeaders(httpServletRequest));
return Response.ok().build();
}

@POST
@Path("/abort")
@Path("abort")
public Response abortERezeptTask(AbortERezept abortERezept) {
eRezeptWorkflowService.abortERezeptTask(extractRuntimeConfigFromHeaders(httpServletRequest), abortERezept.getTaskId(), abortERezept.getAccessCode());
return Response.noContent().build();
}

@POST
@Path("/comfortsignature/activate")
@Path("comfortsignature/activate")
public Response activate() {
String userId = eRezeptWorkflowService.activateComfortSignature(extractRuntimeConfigFromHeaders(httpServletRequest));
return Response.ok(Entity.text(userId)).build();
}

@POST
@Path("/comfortsignature/deactivate")
@Path("comfortsignature/deactivate")
public Response deactivate() {
eRezeptWorkflowService.deactivateComfortSignature(extractRuntimeConfigFromHeaders(httpServletRequest));
return Response.ok().build();
}

@GET
@Path("/comfortsignature/user-id")
@Path("comfortsignature/user-id")
public Response getUserId() {
return Response.ok(Entity.text(eRezeptWorkflowService.getUserIdForComfortSignature())).build();
}

@POST
@Path("/comfortsignature/user-id")
@Path("comfortsignature/user-id")
public Response postUserId(String userId) {
eRezeptWorkflowService.setUserIdForComfortSignature(userId);
return Response.ok().build();
}

@GET
@Path("idp-token")
public String idpToken() {
RuntimeConfig runtimeConfig = extractRuntimeConfigFromHeaders(httpServletRequest);
eRezeptWorkflowService.requestNewAccessTokenIfNecessary(runtimeConfig, null, null);
return eRezeptWorkflowService.getBearerToken(runtimeConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PharmacyResource {
HttpServletRequest httpServletRequest;

@GET
@Path("/Task")
@Path("Task")
public Bundle task(@QueryParam("egkHandle") String egkHandle, @QueryParam("smcbHandle") String smcbHandle) throws FaultMessage, de.gematik.ws.conn.eventservice.wsdl.v7.FaultMessage {
return pharmacyService.getEPrescriptionsForCardHandle(egkHandle, smcbHandle, ERezeptWorkflowResource.extractRuntimeConfigFromHeaders(httpServletRequest));
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/health/ere/ps/resource/ipp/PrinterResource.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package health.ere.ps.resource.ipp;


import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.logging.Logger;

Expand All @@ -18,6 +20,7 @@
import com.hp.jipp.encoding.IppOutputStream;
import com.hp.jipp.trans.IppPacketData;
import com.hp.jipp.trans.IppServerTransport;

import health.ere.ps.service.ipp.PrinterService;


Expand All @@ -32,7 +35,7 @@ public class PrinterResource implements IppServerTransport {
private static Logger log = Logger.getLogger(PrinterResource.class.getName());

@POST
@Path("/{queue}")
@Path("{queue}")
public Response handle(@PathParam("queue") String queue, @Context UriInfo uriInfo, InputStream stream) throws IOException {
try {
IppInputStream inputStream = new IppInputStream(stream);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/health/ere/ps/resource/kbv/XSLTResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class XSLTResource {
IParser xmlParser = FhirContext.forR4().newXmlParser();

@POST
@Path("/transform")
@Path("transform")
public Response transform(@HeaderParam("Content-Type") String contentType, String bundle) {
String htmlPreview;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class DocumentResource {
IParser xmlParser = FhirContext.forR4().newXmlParser();

@POST
@Path("/bundles")
@Path("bundles")
public Response createAndSendPrescriptions(String bundlesString) {

JsonArray jsonArray = Json.createReader(new StringReader(bundlesString)).readArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,12 @@ public List<SignResponse> signBundleWithIdentifiers(List<Bundle> bundles, boolea

List<de.gematik.ws.conn.signatureservice.v7_5_5.SignResponse> signResponsesV755;
ContextType contextType = connectorServicesProvider.getContextType(runtimeConfig);
if(userIdForComfortSignature != null) {
contextType.setUserId(userIdForComfortSignature);
if(runtimeConfig != null && runtimeConfig.getUserId() != null) {
contextType.setUserId(runtimeConfig.getUserId());
} else {
if(userIdForComfortSignature != null) {
contextType.setUserId(userIdForComfortSignature);
}
}
if(appConfig.enableBatchSign()) {
String jobNumber = connectorServicesProvider.getSignatureServicePortTypeV755(runtimeConfig).getJobNumber(connectorServicesProvider.getContextType(runtimeConfig));
Expand Down Expand Up @@ -868,7 +872,11 @@ public GetSignatureModeResponseEvent getSignatureMode(RuntimeConfig runtimeConfi
try {
signatureServiceCardHandle = getSignatureServiceCardHandle(runtimeConfig);;
ContextType contextType = connectorServicesProvider.getContextType(runtimeConfig);
contextType.setUserId(userIdForComfortSignature);
if(runtimeConfig != null && runtimeConfig.getUserId() != null) {
contextType.setUserId(runtimeConfig.getUserId());
} else {
contextType.setUserId(userIdForComfortSignature);
}
connectorServicesProvider.getSignatureServicePortTypeV755(runtimeConfig).getSignatureMode(signatureServiceCardHandle, contextType, status, comfortSignatureStatus,
comfortSignatureMax, comfortSignatureTimer, sessionInfo);
return new GetSignatureModeResponseEvent(status.value, comfortSignatureStatus.value, comfortSignatureMax.value, comfortSignatureTimer.value, sessionInfo.value);
Expand Down Expand Up @@ -903,7 +911,11 @@ public void deactivateComfortSignature(RuntimeConfig runtimeConfig, Session repl
try {
signatureServiceCardHandle = getSignatureServiceCardHandle(runtimeConfig);
ContextType contextType = connectorServicesProvider.getContextType(runtimeConfig);
contextType.setUserId(userIdForComfortSignature);
if(runtimeConfig != null && runtimeConfig.getUserId() != null) {
contextType.setUserId(runtimeConfig.getUserId());
} else {
contextType.setUserId(userIdForComfortSignature);
}

connectorServicesProvider.getSignatureServicePortTypeV755(runtimeConfig).deactivateComfortSignature(Arrays.asList(signatureServiceCardHandle));
userIdForComfortSignature = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package health.ere.ps.resource.gematik;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Arrays;
Expand All @@ -15,6 +17,7 @@
import org.mockito.stubbing.Answer;

import health.ere.ps.config.RuntimeConfig;
import health.ere.ps.service.gematik.ERezeptWorkflowService;

public class ERezeptWorkflowResourceTest {
@Test
Expand Down Expand Up @@ -64,4 +67,18 @@ public Object answer(InvocationOnMock invocation) throws Throwable {


}

@Test
public void testIdpToken() {
ERezeptWorkflowResource eRezeptWorkflowResource = new ERezeptWorkflowResource();
eRezeptWorkflowResource.httpServletRequest = mock(HttpServletRequest.class);
when(eRezeptWorkflowResource.httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(Collections.emptyList()));
eRezeptWorkflowResource.eRezeptWorkflowService = mock(ERezeptWorkflowService.class);
when(eRezeptWorkflowResource.eRezeptWorkflowService.getBearerToken(any())).thenReturn("123456");

String token = eRezeptWorkflowResource.idpToken();

assertEquals("123456", token);
verify(eRezeptWorkflowResource.eRezeptWorkflowService).requestNewAccessTokenIfNecessary(any(), any(), any());
}
}

0 comments on commit 89e9ca7

Please sign in to comment.