Skip to content

Commit

Permalink
fix(login): extract urls and make it environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
albertrodriguezin2 committed Oct 11, 2024
1 parent a002ab5 commit 73c1edb
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package es.in2.vcverifier.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "ui.urls")
public record UiUrlsProperties(String onboardingUrl, String supportUrl, String walletUrl) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package es.in2.vcverifier.oid4vp.controller;

import es.in2.vcverifier.config.properties.UiUrlsProperties;
import es.in2.vcverifier.exception.QRCodeGenerationException;
import lombok.RequiredArgsConstructor;
import net.glxn.qrgen.javase.QRCode;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
Expand All @@ -11,8 +13,11 @@
import java.util.Base64;

@Controller
@RequiredArgsConstructor
public class LoginQrController {

private final UiUrlsProperties uiUrlsProperties;


@GetMapping("/login")
@ResponseStatus(HttpStatus.OK)
Expand All @@ -27,14 +32,18 @@ public String showQrLogin(@RequestParam("authRequest") String authRequest, @Requ
// Pasar el sessionId al modelo
model.addAttribute("state", state);

model.addAttribute("onboardingUrl", uiUrlsProperties.onboardingUrl());
model.addAttribute("supportUrl", uiUrlsProperties.supportUrl());
model.addAttribute("walletUrl", uiUrlsProperties.walletUrl());

} catch (Exception e) {
throw new QRCodeGenerationException(e.getMessage());
}

return "login";
}

private String generateQRCodeImageBase64(String barcodeText){
private String generateQRCodeImageBase64(String barcodeText) {
ByteArrayOutputStream stream = QRCode
.from(barcodeText)
.withSize(250, 250)
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ trustedIssuerList:

crypto:
privateKey:

ui:
urls:
onboardingUrl:
supportUrl:
walletUrl:
8 changes: 7 additions & 1 deletion src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ trustedIssuerList:
uri: "http://localhost:8080/v4/issuers/"

crypto:
privateKey: "73e509a7681d4a395b1ced75681c4dc4020dbab02da868512276dd766733d5b5" # for test purposes
privateKey: "73e509a7681d4a395b1ced75681c4dc4020dbab02da868512276dd766733d5b5" # for test purposes

ui:
urls:
onboardingUrl:
supportUrl:
walletUrl:
8 changes: 7 additions & 1 deletion src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ trustedIssuerList:
uri:

crypto:
privateKey:
privateKey:

ui:
urls:
onboardingUrl:
supportUrl:
walletUrl:
8 changes: 7 additions & 1 deletion src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ trustedIssuerList:
uri:

crypto:
privateKey:
privateKey:

ui:
urls:
onboardingUrl:
supportUrl:
walletUrl:
8 changes: 7 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ trustedIssuerList:
uri: "http://localhost:8080/v4/issuers/"

crypto:
privateKey: "73e509a7681d4a395b1ced75681c4dc4020dbab02da868512276dd766733d5b5" # for test purposes
privateKey: "73e509a7681d4a395b1ced75681c4dc4020dbab02da868512276dd766733d5b5" # for test purposes

ui:
urls:
onboardingUrl:
supportUrl:
walletUrl:
7 changes: 4 additions & 3 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@
<div class="left-column">
<div class="registration-card">
<h3>Your organization must be registered in the marketplace before you log in.</h3>
<button onclick="window.location.href='https://knowledgebase.dome-marketplace-prd.org/shelves/company-onboarding-process'">
<button th:attr="onclick='window.location.href=' + '${onboardingUrl}'">
<i class="fa-solid fa-laptop"></i>
Registration
</button>
</div>
<div class="card">
<h3>Having trouble logging in?</h3>
<p>Get help from <a href="https://ticketing.dome-marketplace-sbx.org">Customer Support</a></p>
<p>Get help from <a th:href="${supportUrl}">Customer Support</a></p>
</div>
</div>
<div class="right-column">
Expand All @@ -283,7 +283,8 @@ <h3>Login from the same device</h3>
</div>
<div class="instructions">
<h3>Login instructions</h3>
<h4>1. You must register or log in to a Wallet using your phone. You may use the <a href="https://wallet.dome-marketplace-lcl.org">DOME Wallet</a>.</h4>
<h4>1. You must register or log in to a Wallet using your phone. You may use the <a
th:href="${walletUrl}">DOME Wallet</a>.</h4>
<h4>2. Scan the QR code.</h4>
<h4>3. Select the credential.</h4>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package es.in2.vcverifier.config.properties;

import es.in2.vcverifier.objectmothers.UiUrlsPropertiesMother;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
class UiUrlPropertiesTest {
@Autowired
private UiUrlsProperties uiUrlsProperties;

private static final String ONBOARDING_URL = UiUrlsPropertiesMother.createOnboardingUrl();
private static final String SUPPORT_URL = UiUrlsPropertiesMother.createSupportUrl();
private static final String WALLET_URL = UiUrlsPropertiesMother.createWalletUrl();

@DynamicPropertySource
static void setDynamicProperties(DynamicPropertyRegistry registry) {
registry.add("ui.urls.onboardingUrl", () -> ONBOARDING_URL);
registry.add("ui.urls.supportUrl", () -> SUPPORT_URL);
registry.add("ui.urls.walletUrl", () -> WALLET_URL);
}

@Test
void testUiUrlsOnboardingUrl() {
assertThat(uiUrlsProperties.onboardingUrl()).isEqualTo(ONBOARDING_URL);
}

@Test
void testUiUrlSupportUrl() {
assertThat(uiUrlsProperties.supportUrl()).isEqualTo(SUPPORT_URL);
}

@Test
void testUiUrlwalletUrl() {
assertThat(uiUrlsProperties.walletUrl()).isEqualTo(WALLET_URL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package es.in2.vcverifier.objectmothers;

public final class UiUrlsPropertiesMother {
private UiUrlsPropertiesMother() {
}

public static String createOnboardingUrl(){
return "knowledge-base.example.org";
}

public static String createSupportUrl(){
return "ticketing.example.org";
}

public static String createWalletUrl(){
return "wallet.example.org";
}
}

0 comments on commit 73c1edb

Please sign in to comment.