Skip to content

Commit eb2cdcd

Browse files
authored
Merge pull request #1173 from OpenConext/feature/567-service-name-in-push-notification
Fixes #567 service name in push notification
2 parents 957a2b9 + 10245cc commit eb2cdcd

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

myconext-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
<dependency>
166166
<groupId>org.openconext</groupId>
167167
<artifactId>tiqr-java-connector</artifactId>
168-
<version>2.0.3</version>
168+
<version>3.0.0</version>
169169
</dependency>
170170
<dependency>
171171
<groupId>com.fasterxml.jackson.datatype</groupId>

myconext-server/src/main/java/myconext/tiqr/TiqrController.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

myconext-server/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ guest_idp_entity_id: https://localhost.surf.id
9494
my_conext_url: https://my.test2.surfconext.nl
9595
domain: eduid.nl
9696
mijn_eduid_entity_id: http://mijn.localhost/shibboleth
97+
mijn_eduid_service_name: "Mijn eduID"
9798
mobile_app_redirect: eduid:///client/mobile
9899
mobile_app_rp_entity_id: mobile_app_rp_entity_id
99100

0 commit comments

Comments
 (0)