Skip to content

Commit fed9255

Browse files
committed
bugfix for #552
1 parent fc49de2 commit fed9255

File tree

9 files changed

+60
-13
lines changed

9 files changed

+60
-13
lines changed

TIQR.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
```mermaid
2+
sequenceDiagram
3+
actor User
4+
participant Tiqr App
5+
participant eduID
6+
User->>Tiqr App: Start registration
7+
Tiqr App->>eduID: Start enrollment
8+
eduID->>Tiqr App: Enrollment data
9+
Note right of Tiqr App: EnrollmentKey, metaData URL and qrcode
10+
Tiqr App->>eduID: MetaData enrollmentKey
11+
eduID->>Tiqr App: MetaData
12+
Note right of Tiqr App: Service and Identity (=registrationID)
13+
Tiqr App->>eduID: Start authentication
14+
eduID->>Tiqr App: Session key and url
15+
Note right of Tiqr App: Authentication URL with u=registrationID
16+
Tiqr App->>eduID: Finish authentication
17+
Note right of Tiqr App: AuthenticationData with userId=registrationID
18+
eduID->>eduID: Fetch User with AuthenticationData-userId
19+
Note left of eduID: UserNotFoundException
20+
eduID->>eduID: Fetch Registration with AuthenticationData-userId
21+
eduID->>eduID: Fetch User with Registration-userId
22+
eduID->>Tiqr App: OK
23+
Tiqr App->>User: 🙏🏻
24+
```

account-gui/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>myconext</artifactId>
7-
<version>7.4.5</version>
7+
<version>7.4.6</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>account-gui</artifactId>

myconext-gui/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>myconext</artifactId>
7-
<version>7.4.5</version>
7+
<version>7.4.6</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>myconext-gui</artifactId>

myconext-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>myconext</artifactId>
7-
<version>7.4.5</version>
7+
<version>7.4.6</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>myconext-server</artifactId>

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.time.Instant;
4444
import java.util.*;
4545
import java.util.concurrent.atomic.AtomicBoolean;
46+
import java.util.function.Function;
4647

4748
import static myconext.crypto.HashGenerator.hash;
4849
import static myconext.log.MDCContext.logWithContext;
@@ -528,22 +529,34 @@ public ResponseEntity<Object> doEnrollment(@ModelAttribute Registration registra
528529
@PostMapping(value = "/authentication", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
529530
@Hidden
530531
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+
533545
if (!rateLimitEnforcer.isUserAllowedTiqrVerification(user)) {
534546
return ResponseEntity.ok("ERROR");
535547
}
536548
try {
537549
tiqrService.postAuthentication(authenticationData);
538550

539-
LOG.debug("Successful authentication for user " + userId);
551+
LOG.debug(String.format("Successful authentication for user %s, %s" ,user.getEmail(), user.getId()));
540552

541553
rateLimitEnforcer.unsuspendUserAfterTiqrSuccess(user);
542554
return ResponseEntity.ok("OK");
543555
} catch (TiqrException | RuntimeException e) {
544556
//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(),
547560
e.getMessage()));
548561
rateLimitEnforcer.suspendUserAfterTiqrFailure(user);
549562
try {

myconext-server/src/test/java/myconext/tiqr/TiqrControllerTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,16 @@ public void fetchRegistration() throws IOException {
309309
}
310310

311311
@Test
312-
public void startAuthentication() throws Exception {
312+
public void startAuthenticationWithRegistrationID() throws Exception {
313+
doStartAuthentication(true);
314+
}
315+
316+
@Test
317+
public void startAuthenticationBackwardCompatibleWithUserID() throws Exception {
318+
doStartAuthentication(false);
319+
}
320+
321+
private void doStartAuthentication(boolean useRegistrationId) throws Exception {
313322
SamlAuthenticationRequest samlAuthenticationRequest = doEnrollmment(true);
314323

315324
Map<String, Object> results = given()
@@ -338,10 +347,11 @@ public void startAuthentication() throws Exception {
338347
String decryptedSecret = this.decryptRegistrationSecret(registration.getSecret());
339348
String ocra = OCRA.generateOCRA(decryptedSecret, authentication.getChallenge(), sessionKey);
340349

350+
String userId = useRegistrationId ? registration.getId() : samlAuthenticationRequest.getUserId();
341351
given()
342352
.contentType(ContentType.URLENC)
343353
.formParam("sessionKey", sessionKey)
344-
.formParam("userId", samlAuthenticationRequest.getUserId())
354+
.formParam("userId", userId)
345355
.formParam("response", ocra)
346356
.formParam("language", "en")
347357
.formParam("operation", "login")

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.openconext</groupId>
55
<artifactId>myconext</artifactId>
6-
<version>7.4.5</version>
6+
<version>7.4.6</version>
77
<packaging>pom</packaging>
88
<name>myconext</name>
99
<description>My OpenConext</description>

public-gui/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>myconext</artifactId>
7-
<version>7.4.5</version>
7+
<version>7.4.6</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>public-gui</artifactId>

tiqr-mock/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>myconext</artifactId>
7-
<version>7.4.5</version>
7+
<version>7.4.6</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>tiqr-mock</artifactId>

0 commit comments

Comments
 (0)