Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 9, 2024
1 parent 0949f1b commit bef6c3d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.openconext</groupId>
<artifactId>tiqr-java-connector</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<name>tiqr-java-connector</name>

<dependencies>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/tiqr/org/DefaultTiqrService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

public class DefaultTiqrService implements TiqrService {

Expand Down Expand Up @@ -81,7 +82,8 @@ public MetaData getMetaData(String enrollmentKey) throws TiqrException {

LOG.debug("Get metadata for enrollment for user " + enrollment.getUserID());

enrollmentRepository.save(enrollment);
enrollment.setRegistrationId(UUID.randomUUID().toString());
enrollment = enrollmentRepository.save(enrollment);
return new MetaData(Service.addEnrollmentSecret(this.service, enrollmentSecret), new Identity(enrollment));
}

Expand All @@ -104,6 +106,8 @@ public Registration enrollData(Registration registration) throws TiqrException {
Instant now = Instant.now();
registration.setCreated(now);
registration.setUpdated(now);
registration.setId(enrollment.getRegistrationId());
registration.setUsePrimaryIdentifier(true);

Registration savedRegistration = registrationRepository.save(registration);

Expand Down Expand Up @@ -145,7 +149,7 @@ public Authentication startAuthentication(String userId, String userDisplayName,
String challenge = Challenge.generateQH10Challenge();
String authenticationUrl = String.format("%s/tiqrauth/?u=%s&s=%s&q=%s&i=%s&v=%s",
eduIdAppBaseUrl,
encode(userId),
encode(registration.isUsePrimaryIdentifier() ? registration.getId() : userId),
encode(sessionKey),
encode(challenge),
encode(this.service.getIdentifier()),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/tiqr/org/model/Enrollment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Enrollment implements Serializable {
private String userID;
private String userDisplayName;
private EnrollmentStatus status;
private String registrationId;
private Instant created;
private Instant updated;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tiqr/org/model/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Identity {
private String displayName;

public Identity(Enrollment enrollment) {
this.identifier = enrollment.getUserID();
this.identifier = enrollment.getRegistrationId();
this.displayName = enrollment.getUserDisplayName();
}
}
1 change: 1 addition & 0 deletions src/main/java/tiqr/org/model/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Registration implements Serializable {
private RegistrationStatus status;
private Instant created;
private Instant updated;
private boolean usePrimaryIdentifier;

public void validateForInitialEnrollment() {
validateForPushNotification();
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/tiqr/org/TiqrServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ void enrollmentScenario() throws TiqrException {
assertNotNull(enrollmentSecret);

assertEquals(EnrollmentStatus.RETRIEVED, tiqrService.enrollmentStatus(enrollment.getKey()).getStatus());
assertEquals(metaData.getIdentity().getIdentifier(), enrollment.getRegistrationId());

when(enrollmentRepository.save(any(Enrollment.class))).thenAnswer(i -> i.getArguments()[0]);
when(registrationRepository.save(any(Registration.class))).thenAnswer(i -> i.getArguments()[0]);
when(enrollmentRepository.findEnrollmentByEnrollmentSecret(enrollmentSecret)).thenReturn(Optional.of(enrollment));

Registration registration = getRegistration(enrollmentSecret);
Registration result = tiqrService.enrollData(registration);
assertEquals(metaData.getIdentity().getIdentifier(), registration.getId());

SecretCipher cipher = new SecretCipher("secret");
assertEquals(result.getSecret(), cipher.encrypt(sharedSecret));
Expand Down

0 comments on commit bef6c3d

Please sign in to comment.