Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,25 @@
<artifactId>sd-jwt</artifactId>
<version>1.5</version>
</dependency>

<!-- vc renderer -->
<dependency>
<groupId>io.mosip.injivcrenderer</groupId>
<artifactId>injivcrenderer-jvm</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.0.0</version>
</dependency>
<!-- mustache-->
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>

<repositories>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/mosip/mimoto/config/InjiVcRendererConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.mosip.mimoto.config;

import io.mosip.injivcrenderer.InjiVcRenderer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class InjiVcRendererConfig {
@Bean
public InjiVcRenderer injiVcRenderer() {
return new InjiVcRenderer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.mosip.mimoto.constant.SwaggerLiteralConstants;
import io.mosip.mimoto.core.http.ResponseWrapper;
import io.mosip.mimoto.dto.CredentialResponse;
import io.mosip.mimoto.dto.idp.TokenResponseDTO;
import io.mosip.mimoto.exception.ApiNotAccessibleException;
import io.mosip.mimoto.exception.InvalidCredentialResourceException;
Expand Down Expand Up @@ -63,12 +64,12 @@ public ResponseEntity<?> downloadCredentialAsPDF(@RequestParam Map<String, Strin
TokenResponseDTO response = idpService.getTokenResponse(params);

log.info("Initiated Download Credential Call");
ByteArrayInputStream inputStream = credentialService.downloadCredentialAsPDF(issuerId, credentialType, response, credentialValidity, locale);
CredentialResponse inputStream = credentialService.downloadCredentialAsPDF(issuerId, credentialType, response, credentialValidity, locale);
return ResponseEntity
.ok()
.contentType(MediaType.APPLICATION_PDF)
.contentType(inputStream.getMediaType())
.header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition")
.body(new InputStreamResource(inputStream));
.body(new InputStreamResource(inputStream.getContent()));
} catch (ApiNotAccessibleException | IOException exception) {
log.error("Exception occurred while fetching credential types ", exception);
return Utilities.handleErrorResponse(exception, MIMOTO_PDF_SIGN_EXCEPTION.getCode(), HttpStatus.BAD_REQUEST, MediaType.APPLICATION_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,13 @@ public ResponseEntity<InputStreamResource> getVerifiableCredential(
String dispositionType = "download".equalsIgnoreCase(action) ? "attachment" : "inline";
String contentDisposition = String.format("%s; filename=\"%s\"", dispositionType, walletCredentialResponseDTO.getFileName());

MediaType contentType = walletCredentialResponseDTO.getFileName().endsWith(".svg") ?
MediaType.valueOf("image/svg+xml") : MediaType.APPLICATION_PDF;

return ResponseEntity.ok()
.header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION)
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.contentType(MediaType.APPLICATION_PDF)
.contentType(contentType)
.body(walletCredentialResponseDTO.getFileContentStream());
} catch (CredentialNotFoundException e) {
log.error("Credential not found for walletId: {} and credentialId: {}", walletId, credentialId, e);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/mosip/mimoto/dto/CredentialResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.mosip.mimoto.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.MediaType;
import java.io.ByteArrayInputStream;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class CredentialResponse {
private ByteArrayInputStream content;
private MediaType mediaType;
}
Loading