Skip to content

Commit

Permalink
Feature/Vas-11619: Show customer name & code on subrogation confirmat…
Browse files Browse the repository at this point in the history
…ion screen
  • Loading branch information
lgheribi committed Mar 27, 2024
1 parent 598a87f commit 50a992f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ public class IdentityProviderDto extends CustomerIdDto {

private Boolean usePkce;

// FIXME : Convert to enum
private String protocoleType;
}
4 changes: 2 additions & 2 deletions cas/cas-server/src/main/config/cas-server-application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ logging:
org.springframework.amqp: 'OFF'
org.springframework.context.annotation: 'OFF'
org.springframework.boot.devtools: 'OFF'
org.apereo.inspektr.audit.support: 'INFO'
org.apereo.cas: 'DEBUG'
org.apereo.inspektr.audit.support: 'OFF'

# Cas CORS (necessary for mobile app)
cas.http-web-request.cors.enabled: true
Expand Down Expand Up @@ -294,6 +293,7 @@ cas.http-web-request.cors.allow-origins:
- "https://dev.vitamui.com:4209"
- "https://dev.vitamui.com:4210"
- "https://dev.vitamui.com:4251"
- "https://dev.vitamui.com"
- "https://localhost:4200"
- "https://localhost:4201"
- "https://localhost:4202"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public Action delegatedAuthenticationAction(
() -> new CustomDelegatedClientAuthenticationAction(delegatedClientAuthenticationConfigurationContext,
delegatedClientWebflowManager, delegatedClientAuthenticationFailureEvaluator,
identityProviderHelper,
providersService, utils, ticketRegistry, vitamuiPortalUrl))
providersService, utils, ticketRegistry, casRestClient, vitamuiPortalUrl))
.withId(CasWebflowConstants.ACTION_ID_DELEGATED_AUTHENTICATION)
.build()
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
public abstract class Constants {

public static final String PROVIDED_USERNAME = "providedUsername";

// surrogation:
public static final String SURROGATE = "surrogate";
public static final String SHOW_SURROGATE_CUSTOMER_NAME = "surrogateCustomerName";
public static final String SHOW_SURROGATE_CUSTOMER_CODE = "surrogateCustomerCode";

public static final String LOGIN_USER_EMAIL_PARAM = "username";
public static final String LOGIN_SURROGATE_EMAIL_PARAM = "surrogateEmail";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import fr.gouv.vitamui.cas.util.Utils;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.iam.common.dto.CustomerDto;
import fr.gouv.vitamui.iam.common.utils.IdentityProviderHelper;
import fr.gouv.vitamui.iam.external.client.CasExternalRestClient;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.apereo.cas.authentication.SurrogateUsernamePasswordCredential;
Expand All @@ -59,6 +61,7 @@
import org.springframework.webflow.execution.RequestContext;

import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;

import static fr.gouv.vitamui.cas.authentication.UserPrincipalResolver.EMAIL_VALID_REGEXP;
Expand All @@ -84,6 +87,8 @@ public class CustomDelegatedClientAuthenticationAction extends DelegatedClientAu

private final TicketRegistry ticketRegistry;

private final CasExternalRestClient casExternalRestClient;

private final String vitamuiPortalUrl;

public CustomDelegatedClientAuthenticationAction(
Expand All @@ -94,12 +99,14 @@ public CustomDelegatedClientAuthenticationAction(
final ProvidersService providersService,
final Utils utils,
final TicketRegistry ticketRegistry,
final CasExternalRestClient casExternalRestClient,
final String vitamuiPortalUrl) {
super(configContext, delegatedClientAuthenticationWebflowManager, failureEvaluator);
this.identityProviderHelper = identityProviderHelper;
this.providersService = providersService;
this.utils = utils;
this.ticketRegistry = ticketRegistry;
this.casExternalRestClient = casExternalRestClient;
this.vitamuiPortalUrl = vitamuiPortalUrl;
}

Expand Down Expand Up @@ -151,6 +158,17 @@ public Event doExecute(final RequestContext context) {
credential.setSurrogateUsername(surrogateEmail);
WebUtils.putCredential(context, credential);

CustomerDto surrogateCustomer =
casExternalRestClient.getCustomersByIds(utils.buildContext(surrogateEmail),
List.of(surrogateCustomerId))
.stream()
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
"Invalid surrogateCustomerId: '" + surrogateCustomerId + "'"));

flowScope.put(Constants.SHOW_SURROGATE_CUSTOMER_CODE, surrogateCustomer.getCode());
flowScope.put(Constants.SHOW_SURROGATE_CUSTOMER_NAME, surrogateCustomer.getCompanyName());

} else if (StringUtils.isNotBlank(username)) {
validateEmail(username);
WebUtils.putCredential(context, new UsernamePasswordCredential(username, null));
Expand All @@ -163,7 +181,7 @@ public Event doExecute(final RequestContext context) {
LOGGER.debug("Provided idp: {}", idp);
if (StringUtils.isNotBlank(idp)) {

// FIXME : IDP vs subrogation vs login. What about customerId
// FIXME LGH : IDP vs subrogation vs login. What about customerId

TicketGrantingTicket tgt = null;
val tgtId = WebUtils.getTicketGrantingTicketId(context);
Expand Down Expand Up @@ -197,7 +215,6 @@ public Event doExecute(final RequestContext context) {

private void validateEmail(String email) {
if (email == null) {
// FIXME
throw new IllegalArgumentException("Null email");
}
if (!Pattern.matches(EMAIL_VALID_REGEXP, email)) {
Expand Down
2 changes: 1 addition & 1 deletion cas/cas-server/src/main/resources/templates/emailForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

<div class="form-line">
<div class="Text-medium-bold" th:text="#{screen.welcome.label.surrogate}">Subrogé :</div>&nbsp;
<div class="Text-medium" th:text="${surrogateEmail}">admin@programmevitam.fr</div>
<div class="Text-medium" th:text="${surrogateEmail + ' (' + surrogateCustomerCode + ' - ' + surrogateCustomerName + ')' }">admin@programmevitam.fr (code - nom d'orga)</div>
</div>
<div class="form-line">
<div class="Text-medium-bold" th:text="#{screen.welcome.label.superuser}">Super utilisateur :</div>&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import fr.gouv.vitamui.cas.util.Constants;
import fr.gouv.vitamui.cas.util.Utils;
import fr.gouv.vitamui.commons.api.identity.ServerIdentityAutoConfiguration;
import fr.gouv.vitamui.iam.common.dto.CustomerDto;
import fr.gouv.vitamui.iam.common.utils.IdentityProviderHelper;
import fr.gouv.vitamui.iam.external.client.CasExternalRestClient;
import lombok.val;
import org.apereo.cas.authentication.SurrogateUsernamePasswordCredential;
import org.apereo.cas.pac4j.client.DelegatedClientAuthenticationFailureEvaluator;
Expand All @@ -23,10 +25,14 @@
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileNotFoundException;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -44,6 +50,8 @@ public final class CustomDelegatedClientAuthenticationActionTest extends BaseWeb
private static final String CUSTOMER_ID_2 = "customer2";
private static final String BAD_EMAIL = "ééééàààà@vitamui.com";
private static final String BAD_CUSTOMER_ID = "ééééàààà";
private static final String CODE = "code";
private static final String COMPANY = "company";

private CustomDelegatedClientAuthenticationAction action;

Expand All @@ -56,10 +64,19 @@ public void setUp() throws FileNotFoundException, InvalidParseOperationException
when(configContext.getDelegatedClientIdentityProvidersProducer()).thenReturn(
mock(DelegatedClientIdentityProviderConfigurationProducer.class));
when(configContext.getDelegatedClientNameExtractor()).thenReturn(mock(DelegatedClientNameExtractor.class));

CasExternalRestClient casExternalRestClient = mock(CasExternalRestClient.class);
CustomerDto surrogateCustomerDto = new CustomerDto();
surrogateCustomerDto.setCode(CODE);
surrogateCustomerDto.setCompanyName(COMPANY);
surrogateCustomerDto.setId(CUSTOMER_ID_2);
doReturn(List.of(surrogateCustomerDto))
.when(casExternalRestClient).getCustomersByIds(any(), eq(List.of(CUSTOMER_ID_2)));

action = new CustomDelegatedClientAuthenticationAction(configContext,
mock(DelegatedClientAuthenticationWebflowManager.class),
mock(DelegatedClientAuthenticationFailureEvaluator.class), mock(IdentityProviderHelper.class),
mock(ProvidersService.class), mock(Utils.class), mock(TicketRegistry.class), "");
mock(ProvidersService.class), mock(Utils.class), mock(TicketRegistry.class), casExternalRestClient, "");
}

@Test
Expand Down Expand Up @@ -104,6 +121,8 @@ public void testSubrogation() {
assertThat(flowParameters.get(Constants.FLOW_LOGIN_CUSTOMER_ID)).isEqualTo(CUSTOMER_ID_1);
assertThat(flowParameters.get(Constants.FLOW_SURROGATE_EMAIL)).isEqualTo(EMAIL2);
assertThat(flowParameters.get(Constants.FLOW_SURROGATE_CUSTOMER_ID)).isEqualTo(CUSTOMER_ID_2);
assertThat(flowParameters.get(Constants.SHOW_SURROGATE_CUSTOMER_CODE)).isEqualTo(CODE);
assertThat(flowParameters.get(Constants.SHOW_SURROGATE_CUSTOMER_NAME)).isEqualTo(COMPANY);

assertNull(flowParameters.get(Constants.PROVIDED_USERNAME));
}
Expand Down

0 comments on commit 50a992f

Please sign in to comment.