|
43 | 43 | import java.time.Instant; |
44 | 44 | import java.util.*; |
45 | 45 | import java.util.concurrent.atomic.AtomicBoolean; |
| 46 | +import java.util.function.Function; |
46 | 47 |
|
47 | 48 | import static myconext.crypto.HashGenerator.hash; |
48 | 49 | import static myconext.log.MDCContext.logWithContext; |
@@ -528,22 +529,34 @@ public ResponseEntity<Object> doEnrollment(@ModelAttribute Registration registra |
528 | 529 | @PostMapping(value = "/authentication", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) |
529 | 530 | @Hidden |
530 | 531 | public ResponseEntity<Object> doAuthentication(@ModelAttribute AuthenticationData authenticationData) { |
531 | | - String userId = authenticationData.getUserId(); |
532 | | - User user = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException(userId)); |
| 532 | + String metaDataIdentity = authenticationData.getUserId(); |
| 533 | + /* |
| 534 | + * This used to be the userID, but in https://github.com/OpenConext/OpenConext-myconext/issues/552 this has |
| 535 | + * changed to the registrationID. We need to try them both to be backwards compatible |
| 536 | + */ |
| 537 | + Optional<Registration> optionalRegistration = registrationRepository.findById(metaDataIdentity); |
| 538 | + Optional<User> optionalUser = optionalRegistration |
| 539 | + .map(registration -> userRepository.findById(registration.getUserId())) |
| 540 | + .flatMap(Function.identity()); |
| 541 | + User user = optionalUser |
| 542 | + .orElseGet(() -> userRepository.findById(metaDataIdentity) |
| 543 | + .orElseThrow(() -> new UserNotFoundException("User not found with authenticationData#userId:" + metaDataIdentity))); |
| 544 | + |
533 | 545 | if (!rateLimitEnforcer.isUserAllowedTiqrVerification(user)) { |
534 | 546 | return ResponseEntity.ok("ERROR"); |
535 | 547 | } |
536 | 548 | try { |
537 | 549 | tiqrService.postAuthentication(authenticationData); |
538 | 550 |
|
539 | | - LOG.debug("Successful authentication for user " + userId); |
| 551 | + LOG.debug(String.format("Successful authentication for user %s, %s" ,user.getEmail(), user.getId())); |
540 | 552 |
|
541 | 553 | rateLimitEnforcer.unsuspendUserAfterTiqrSuccess(user); |
542 | 554 | return ResponseEntity.ok("OK"); |
543 | 555 | } catch (TiqrException | RuntimeException e) { |
544 | 556 | //Do not show stacktrace |
545 | | - LOG.error(String.format("Exception during authentication for user %s, message %s", |
546 | | - userId, |
| 557 | + LOG.error(String.format("Exception during authentication for user %s, %s message %s", |
| 558 | + user.getEmail(), |
| 559 | + user.getId(), |
547 | 560 | e.getMessage())); |
548 | 561 | rateLimitEnforcer.suspendUserAfterTiqrFailure(user); |
549 | 562 | try { |
|
0 commit comments