Filter list of supported OTP applications by current policy (#15113)
Closes #15112
This commit is contained in:
parent
71d9b16717
commit
29b8294dd6
2 changed files with 36 additions and 1 deletions
|
@ -458,9 +458,14 @@ public class ModelToRepresentation {
|
||||||
rep.setOtpPolicyType(otpPolicy.getType());
|
rep.setOtpPolicyType(otpPolicy.getType());
|
||||||
rep.setOtpPolicyLookAheadWindow(otpPolicy.getLookAheadWindow());
|
rep.setOtpPolicyLookAheadWindow(otpPolicy.getLookAheadWindow());
|
||||||
|
|
||||||
rep.setOtpSupportedApplications(session.getAllProviders(OTPApplicationProvider.class).stream().map(OTPApplicationProvider::getName).collect(Collectors.toList()));
|
|
||||||
rep.setOtpPolicyCodeReusable(otpPolicy.isCodeReusable());
|
rep.setOtpPolicyCodeReusable(otpPolicy.isCodeReusable());
|
||||||
|
|
||||||
|
rep.setOtpSupportedApplications(session.getAllProviders(OTPApplicationProvider.class)
|
||||||
|
.stream()
|
||||||
|
.filter(p -> p.supports(otpPolicy))
|
||||||
|
.map(OTPApplicationProvider::getName)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
WebAuthnPolicy webAuthnPolicy = realm.getWebAuthnPolicy();
|
WebAuthnPolicy webAuthnPolicy = realm.getWebAuthnPolicy();
|
||||||
rep.setWebAuthnPolicyRpEntityName(webAuthnPolicy.getRpEntityName());
|
rep.setWebAuthnPolicyRpEntityName(webAuthnPolicy.getRpEntityName());
|
||||||
rep.setWebAuthnPolicySignatureAlgorithms(webAuthnPolicy.getSignatureAlgorithm());
|
rep.setWebAuthnPolicySignatureAlgorithms(webAuthnPolicy.getSignatureAlgorithm());
|
||||||
|
|
|
@ -88,6 +88,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -875,6 +876,35 @@ public class RealmTest extends AbstractAdminTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSupportedOTPApplications() {
|
||||||
|
RealmRepresentation rep = new RealmRepresentation();
|
||||||
|
rep.setRealm("new-realm");
|
||||||
|
|
||||||
|
try {
|
||||||
|
adminClient.realms().create(rep);
|
||||||
|
|
||||||
|
RealmResource realm = adminClient.realms().realm("new-realm");
|
||||||
|
|
||||||
|
rep = realm.toRepresentation();
|
||||||
|
|
||||||
|
List<String> supportedApplications = rep.getOtpSupportedApplications();
|
||||||
|
assertThat(supportedApplications, hasSize(2));
|
||||||
|
assertThat(supportedApplications, containsInAnyOrder("totpAppGoogleName", "totpAppFreeOTPName"));
|
||||||
|
|
||||||
|
rep.setOtpPolicyDigits(8);
|
||||||
|
realm.update(rep);
|
||||||
|
|
||||||
|
rep = realm.toRepresentation();
|
||||||
|
|
||||||
|
supportedApplications = rep.getOtpSupportedApplications();
|
||||||
|
assertThat(supportedApplications, hasSize(1));
|
||||||
|
assertThat(supportedApplications, containsInAnyOrder("totpAppFreeOTPName"));
|
||||||
|
} finally {
|
||||||
|
adminClient.realms().realm(rep.getRealm()).remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupTestAppAndUser() {
|
private void setupTestAppAndUser() {
|
||||||
testingClient.testApp().clearAdminActions();
|
testingClient.testApp().clearAdminActions();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue