Skip to content

Commit

Permalink
[SELC-5037] feat: add param lang and concat language param in BO Url (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
giulia-tremolada authored Jun 10, 2024
1 parent 4469e5d commit b413a7d
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 43 deletions.
21 changes: 19 additions & 2 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,15 @@
"schema" : {
"type" : "string"
}
}, {
"name" : "lang",
"in" : "query",
"description" : "Selected language",
"required" : false,
"style" : "form",
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
Expand Down Expand Up @@ -1869,6 +1878,15 @@
"schema" : {
"type" : "string"
}
}, {
"name" : "lang",
"in" : "query",
"description" : "Selected language",
"required" : false,
"style" : "form",
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
Expand Down Expand Up @@ -4099,8 +4117,7 @@
},
"partyRole" : {
"type" : "string",
"description" : "Party role",
"enum" : [ "DELEGATE", "MANAGER", "OPERATOR", "SUB_DELEGATE" ]
"description" : "Party role, available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA"
},
"productRoles" : {
"type" : "array",
Expand Down
2 changes: 1 addition & 1 deletion connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.1.10</version>
<version>0.1.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ public URI retrieveProductBackoffice(@ApiParam("${swagger.dashboard.products.mod
String institutionId,
@ApiParam("${swagger.dashboard.product-backoffice-configurations.model.environment}")
@RequestParam(value = "environment", required = false)
Optional<String> environment) {
Optional<String> environment,
@ApiParam("${swagger.dashboard.product-backoffice-configurations.model.lang}")
@RequestParam(value = "lang", required = false)
String lang) {
log.trace("accessProductBackoffice start");
log.debug("accessProductBackoffice institutionId = {}, productId = {}", institutionId, productId);
final ExchangedToken exchangedToken = exchangeTokenService.exchange(institutionId, productId, environment);
final ExchangedToken exchangedToken = exchangeTokenService.exchange(institutionId, productId, environment, lang);
final URI location = URI.create(exchangedToken.getBackOfficeUrl().replace("<IdentityToken>", exchangedToken.getIdentityToken()));
log.trace("accessProductBackoffice end");
return location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import it.pagopa.selfcare.dashboard.web.model.IdentityTokenResource;
import it.pagopa.selfcare.dashboard.web.security.ExchangeTokenServiceV2;
import lombok.extern.slf4j.Slf4j;
import org.owasp.encoder.Encode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -50,7 +51,7 @@ public IdentityTokenResource exchange(@ApiParam("${swagger.dashboard.institution
log.trace("exchange start");
log.debug("exchange institutionId = {}, productId = {}", institutionId, productId);

String token = exchangeTokenService.exchange(institutionId, productId, environment).getIdentityToken();
String token = exchangeTokenService.exchange(institutionId, productId, environment, null).getIdentityToken();
IdentityTokenResource identityToken = new IdentityTokenResource();
identityToken.setToken(token);

Expand All @@ -71,15 +72,18 @@ public URI billingToken(@ApiParam("${swagger.dashboard.institutions.model.id}")
@ApiParam("${swagger.dashboard.product-backoffice-configurations.model.environment}")
@RequestParam(value = "environment", required = false)
Optional<String> environment,
JwtAuthenticationToken jwtAuthenticationToken) {
JwtAuthenticationToken jwtAuthenticationToken,
@ApiParam("${swagger.dashboard.product-backoffice-configurations.model.lang}")
@RequestParam(value = "lang", required = false)
String lang) {

log.trace("billing exchange start");
log.debug("billing exchange institutionId = {}", institutionId);
log.info("env parameter: {}", environment);
log.debug("billing exchange institutionId = {}", Encode.forJava(institutionId));
log.info("env parameter: {}", Encode.forJava(environment.orElse("")));

final ExchangedToken exchangedToken = exchangeTokenService.retrieveBillingExchangedToken(institutionId);
final ExchangedToken exchangedToken = exchangeTokenService.retrieveBillingExchangedToken(institutionId, lang);
final URI location = URI.create(exchangedToken.getBackOfficeUrl().replace("<IdentityToken>", exchangedToken.getIdentityToken()));
log.debug(LogUtils.CONFIDENTIAL_MARKER, "billing exchange result = {}", location);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "billing exchange result = {}", Encode.forJava(String.valueOf(location)));
log.trace("billing exchange end");

return location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static ProductRoleMappingsResource toProductRoleMappingsResource(Map.Entry<Party
ProductRoleMappingsResource resource = null;
if (entry != null) {
resource = new ProductRoleMappingsResource();
resource.setPartyRole(entry.getKey());
resource.setPartyRole(entry.getKey().name());
resource.setSelcRole(entry.getKey() != PartyRole.OPERATOR ? SelfCareAuthority.ADMIN : SelfCareAuthority.LIMITED);
resource.setMultiroleAllowed(entry.getValue().isMultiroleAllowed());
if (entry.getValue().getRoles() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.swagger.annotations.ApiModelProperty;
import it.pagopa.selfcare.commons.base.security.SelfCareAuthority;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -12,7 +11,7 @@
public class ProductRoleMappingsResource {

@ApiModelProperty(value = "${swagger.dashboard.product-role-mappings.model.partyRole}")
private PartyRole partyRole;
private String partyRole;

@ApiModelProperty(value = "${swagger.dashboard.product-role-mappings.model.selcRole}")
private SelfCareAuthority selcRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ExchangeTokenServiceV2(JwtService jwtService,
}


public ExchangedToken exchange(String institutionId, String productId, Optional<String> environment) {
public ExchangedToken exchange(String institutionId, String productId, Optional<String> environment, String lang) {
log.trace("exchange start");
log.debug(LogUtils.CONFIDENTIAL_MARKER, "exchange institutionId = {}, productId = {}", institutionId, productId);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Expand Down Expand Up @@ -129,12 +129,13 @@ public ExchangedToken exchange(String institutionId, String productId, Optional<

final String urlBO = environment.map(env -> product.getBackOfficeEnvironmentConfigurations().get(env).getUrl())
.orElse(product.getUrlBO());
final String urlBOLang = Objects.nonNull(lang) ? urlBO.concat("?lang="+lang) : urlBO;

log.trace("exchange end");
return new ExchangedToken(jwts, urlBO);
return new ExchangedToken(jwts, urlBOLang);
}

public ExchangedToken retrieveBillingExchangedToken(String institutionId) {
public ExchangedToken retrieveBillingExchangedToken(String institutionId, String lang) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication.getPrincipal() == null || authentication.getCredentials() == null) {
throw new IllegalStateException("Authentication is required");
Expand Down Expand Up @@ -165,8 +166,9 @@ public ExchangedToken retrieveBillingExchangedToken(String institutionId) {
String jwts = createJwts(claims);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "Exchanged token = {}", jwts);
log.trace("exchange end");
final String billingUrlLang = Objects.nonNull(lang) ? billingUrl.concat("?lang=" + lang) : billingUrl;

return new ExchangedToken(jwts, billingUrl);
return new ExchangedToken(jwts, billingUrlLang);
}

private List<String> retrieveInvoiceableProductList() {
Expand Down
3 changes: 2 additions & 1 deletion web/src/main/resources/swagger/swagger_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ swagger.dashboard.products.model.activatedAt=Date the products was activated
swagger.dashboard.products.model.active=flag indicating whether the institution has a valid contract related to the product
swagger.dashboard.products.model.authorized=flag indicating whether the logged user has the authorization to manage the product
swagger.dashboard.products.model.backOfficeEnvironmentConfigurations=Environment-specific configurations for back-office redirection with Token Exchange
swagger.dashboard.product-role-mappings.model.partyRole=Party role
swagger.dashboard.product-role-mappings.model.partyRole=Party role, available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA
swagger.dashboard.product-role-mappings.model.selcRole=Self Care role
swagger.dashboard.product-role-mappings.model.multiroleAllowed=Indicates if an User can have more than one product role
swagger.dashboard.product-role-mappings.model.productRoles=Available product roles
swagger.dashboard.product-role.model.code=Product role internal code
swagger.dashboard.product-role.model.label=Product role label
swagger.dashboard.product-role.model.description=Product role description
swagger.dashboard.product-backoffice-configurations.model.environment=Back Office environment
swagger.dashboard.product-backoffice-configurations.model.lang=Selected language
swagger.dashboard.user.model.id=User's unique identifier
swagger.dashboard.user.model.relationshipId=Unique relationship identifier between User and Product
swagger.dashboard.user.model.name=User's name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.net.URI;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -46,14 +46,16 @@ void retrieveProductBackoffice() throws Exception {
// given
String productId = "prod1";
String institutionId = "inst1";
String lang = "en";
final String identityToken = "identityToken";
final String backOfficeUrl = "back-office-url#token=";
when(exchangeTokenServiceMock.exchange(any(), any(), any()))
when(exchangeTokenServiceMock.exchange(any(), any(), any(), anyString()))
.thenReturn(new ExchangedToken(identityToken, backOfficeUrl + "<IdentityToken>"));
// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/{productId}/back-office", productId)
.queryParam("institutionId", institutionId)
.queryParam("lang", lang)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
Expand All @@ -64,7 +66,7 @@ void retrieveProductBackoffice() throws Exception {
assertTrue(response.toString().contains(backOfficeUrl));

verify(exchangeTokenServiceMock, times(1))
.exchange(institutionId, productId, Optional.empty());
.exchange(institutionId, productId, Optional.empty(), lang);
verifyNoMoreInteractions(exchangeTokenServiceMock);
verifyNoInteractions(productServiceMock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

Expand All @@ -48,7 +47,7 @@ void exchange() throws Exception {
// given
String institutionId = "inst1";
String productId = "prod1";
Mockito.when(exchangeTokenServiceMock.exchange(anyString(), anyString(), any()))
Mockito.when(exchangeTokenServiceMock.exchange(anyString(), anyString(), any(), eq(null)))
.thenReturn(new ExchangedToken("token", "urlBO"));
// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
Expand All @@ -64,20 +63,22 @@ void exchange() throws Exception {
assertNotNull(resource);
assertNotNull(resource.getToken());
verify(exchangeTokenServiceMock, Mockito.times(1))
.exchange(institutionId, productId, Optional.empty());
.exchange(institutionId, productId, Optional.empty(), null);
verifyNoMoreInteractions(exchangeTokenServiceMock);
}

@Test
void billingExchange() throws Exception {
// given
String institutionId = "inst1";
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(anyString()))
String lang = "en";
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(anyString(), anyString()))
.thenReturn(new ExchangedToken("token", "urlBO"));
// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/exchange/fatturazione")
.param("institutionId", institutionId)
.param("lang", lang)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
Expand All @@ -86,7 +87,7 @@ void billingExchange() throws Exception {
URI resource = objectMapper.readValue(result.getResponse().getContentAsString(), URI.class);
assertNotNull(resource);
verify(exchangeTokenServiceMock, Mockito.times(1))
.retrieveBillingExchangedToken(institutionId);
.retrieveBillingExchangedToken(institutionId, lang);
verifyNoMoreInteractions(exchangeTokenServiceMock);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void toProductRoleMappingsResource_fromEntry_notNull() {
assertNotNull(output);
assertNotNull(output.getProductRoles());
assertEquals(productRoleInfo.getRoles().size(), output.getProductRoles().size());
assertEquals(input.getKey(), output.getPartyRole());
assertEquals(input.getKey().name(), output.getPartyRole());
assertEquals(SelfCareAuthority.ADMIN, output.getSelcRole());
assertEquals(input.getValue().isMultiroleAllowed(), output.isMultiroleAllowed());
}
Expand Down
Loading

0 comments on commit b413a7d

Please sign in to comment.