Skip to content

Commit 4bd3603

Browse files
committed
Default to required otp auth type
This is likely what most people expect, and works around keycloak/keycloak#28979
1 parent f14ae1c commit 4bd3603

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spi/src/main/java/nl/wouterh/keycloak/trusteddevice/authenticator/CredentialConfiguredCondition.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ public boolean matchCondition(AuthenticationFlowContext context) {
2222
if (authConfig != null && authConfig.getConfig() != null) {
2323
boolean negateOutput = Boolean.parseBoolean(
2424
authConfig.getConfig().get(CredentialConfiguredConditionFactory.CONF_NEGATE));
25-
String[] authenticatorNames = Constants.CFG_DELIMITER_PATTERN.split(
26-
authConfig.getConfig().get(CredentialConfiguredConditionFactory.CONF_AUTH));
27-
boolean hasAuthenticator = Arrays.stream(authenticatorNames)
28-
.anyMatch(authenticator -> context.getUser().credentialManager()
29-
.isConfiguredFor(authenticator));
25+
boolean hasAuthenticator = false;
26+
27+
String authenticatorNamesStr = authConfig.getConfig()
28+
.get(CredentialConfiguredConditionFactory.CONF_AUTH);
29+
if (authenticatorNamesStr != null) {
30+
String[] authenticatorNames = Constants.CFG_DELIMITER_PATTERN.split(
31+
authenticatorNamesStr);
32+
hasAuthenticator = Arrays.stream(authenticatorNames)
33+
.anyMatch(authenticator -> context.getUser().credentialManager()
34+
.isConfiguredFor(authenticator));
35+
}
3036

3137
return hasAuthenticator != negateOutput;
3238
}

spi/src/main/java/nl/wouterh/keycloak/trusteddevice/authenticator/CredentialConfiguredConditionFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public List<ProviderConfigProperty> getConfigProperties() {
6363
authTypes.setLabel("Authenticator types");
6464
authTypes.setHelpText(
6565
"Condition matches if one of the user has one of the authenticator types configured");
66+
authTypes.setDefaultValue("otp");
6667

6768
ProviderConfigProperty negateOutput = new ProviderConfigProperty();
6869
negateOutput.setType(ProviderConfigProperty.BOOLEAN_TYPE);

0 commit comments

Comments
 (0)