@@ -70,6 +70,7 @@ public class TiqrController implements UserAuthentication {
7070 private final RegistrationRepository registrationRepository ;
7171 private final RateLimitEnforcer rateLimitEnforcer ;
7272 private final CookieValueEncoder cookieValueEncoder ;
73+ private final String mijnEduIdServiceName ;
7374
7475 @ Autowired
7576 public TiqrController (@ Value ("${tiqr_configuration}" ) Resource resource ,
@@ -82,6 +83,7 @@ public TiqrController(@Value("${tiqr_configuration}") Resource resource,
8283 SMSService smsService ,
8384 Environment environment ,
8485 @ Value ("${email.magic-link-url}" ) String magicLinkUrl ,
86+ @ Value ("${mijn_eduid_service_name}" ) String mijnEduIdServiceName ,
8587 CookieValueEncoder cookieValueEncoder ) throws IOException {
8688 this .tiqrConfiguration = new Yaml ().loadAs (resource .getInputStream (), TiqrConfiguration .class );
8789 this .cookieValueEncoder = cookieValueEncoder ;
@@ -112,6 +114,7 @@ public TiqrController(@Value("${tiqr_configuration}") Resource resource,
112114 this .serviceProviderResolver = serviceProviderResolver ;
113115 this .smsService = smsService ;
114116 this .magicLinkUrl = magicLinkUrl ;
117+ this .mijnEduIdServiceName = mijnEduIdServiceName ;
115118 this .rateLimitEnforcer = new RateLimitEnforcer (userRepository , tiqrConfiguration );
116119 }
117120
@@ -405,7 +408,7 @@ private ResponseEntity<VerifyPhoneCode> doVerifyPhoneCode(PhoneVerification phon
405408 public ResponseEntity <StartAuthentication > startAuthenticationForSP (HttpServletRequest request ,
406409 org .springframework .security .core .Authentication authentication ) throws IOException , WriterException , TiqrException {
407410 User user = userFromAuthentication (authentication );
408- ResponseEntity <StartAuthentication > startAuthenticationResponseEntity = doStartAuthentication (request , user );
411+ ResponseEntity <StartAuthentication > startAuthenticationResponseEntity = doStartAuthentication (request , user , this . mijnEduIdServiceName );
409412 String sessionKey = startAuthenticationResponseEntity .getBody ().getSessionKey ();
410413 request .getSession ().setAttribute (SESSION_KEY , sessionKey );
411414 return startAuthenticationResponseEntity ;
@@ -415,16 +418,18 @@ public ResponseEntity<StartAuthentication> startAuthenticationForSP(HttpServletR
415418 @ Hidden
416419 public ResponseEntity <StartAuthentication > startAuthentication (HttpServletRequest request ,
417420 @ Valid @ RequestBody TiqrRequest tiqrRequest ) throws IOException , WriterException , TiqrException {
418- authenticationRequestRepository .findByIdAndNotExpired (tiqrRequest .getAuthenticationRequestId ())
421+ SamlAuthenticationRequest samlAuthenticationRequest = authenticationRequestRepository .findByIdAndNotExpired (tiqrRequest .getAuthenticationRequestId ())
419422 .orElseThrow (() -> new ExpiredAuthenticationException ("Expired tiqrRequest:" + tiqrRequest .getEmail ()));
423+ String serviceName = samlAuthenticationRequest .getServiceName ();
424+
420425 String email = tiqrRequest .getEmail ().trim ();
421426 User user = userRepository .findUserByEmailAndRateLimitedFalse (email )
422427 .orElseThrow (() -> new UserNotFoundException (String .format ("User %s not found" , email )));
423428
424- return doStartAuthentication (request , user );
429+ return doStartAuthentication (request , user , serviceName );
425430 }
426431
427- private ResponseEntity <StartAuthentication > doStartAuthentication (HttpServletRequest request , User user ) throws WriterException , IOException , TiqrException {
432+ private ResponseEntity <StartAuthentication > doStartAuthentication (HttpServletRequest request , User user , String serviceName ) throws WriterException , IOException , TiqrException {
428433 Optional <Cookie > optionalTiqrCookie = cookieByName (request , TIQR_COOKIE_NAME );
429434 AtomicBoolean tiqrCookieValid = new AtomicBoolean (false );
430435 optionalTiqrCookie .ifPresent (tiqrCookie -> tiqrCookieValid .set (this .cookieValueEncoder .matches (user .getUsername (), tiqrCookie .getValue ())));
@@ -435,10 +440,13 @@ private ResponseEntity<StartAuthentication> doStartAuthentication(HttpServletReq
435440 // Reset any outstanding suspensions
436441 rateLimitEnforcer .unsuspendUserAfterTiqrSuccess (user );
437442 boolean sendPushNotification = tiqrCookieValid .get () && this .tiqrConfiguration .isPushNotificationsEnabled ();
443+
444+ // Start Tiqr authentication -- pass the SP name?
438445 Authentication authentication = tiqrService .startAuthentication (
439446 user .getId (),
440447 String .format ("%s %s" , user .getGivenName (), user .getFamilyName ()),
441448 this .tiqrConfiguration .getEduIdAppBaseUrl (),
449+ serviceName ,
442450 sendPushNotification );
443451 String authenticationUrl = authentication .getAuthenticationUrl ();
444452
0 commit comments