-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into keycloak21.x.x
- Loading branch information
Showing
16 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ft/keycloak/phone/authentication/authenticators/conditional/ConditionalPhoneProvided.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cc.coopersoft.keycloak.phone.authentication.authenticators.conditional; | ||
|
||
import cc.coopersoft.common.OptionalUtils; | ||
import org.keycloak.authentication.AuthenticationFlowContext; | ||
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticator; | ||
import org.keycloak.authentication.authenticators.conditional.ConditionalUserAttributeValueFactory; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.models.UserModel; | ||
|
||
public class ConditionalPhoneProvided implements ConditionalAuthenticator { | ||
|
||
static final ConditionalPhoneProvided SINGLETON = new ConditionalPhoneProvided(); | ||
|
||
@Override | ||
public boolean matchCondition(AuthenticationFlowContext context) { | ||
var config = context.getAuthenticatorConfig().getConfig(); | ||
boolean negateOutput = Boolean.parseBoolean(config.get(ConditionalUserAttributeValueFactory.CONF_NOT)); | ||
|
||
boolean result = OptionalUtils.ofBlank(OptionalUtils.ofBlank( | ||
context.getHttpRequest().getDecodedFormParameters().getFirst("phone_number")) | ||
.orElse(context.getHttpRequest().getDecodedFormParameters().getFirst("phoneNumber"))).isPresent(); | ||
return negateOutput != result; | ||
} | ||
|
||
@Override | ||
public void action(AuthenticationFlowContext authenticationFlowContext) { | ||
// Not used | ||
} | ||
|
||
@Override | ||
public boolean requiresUser() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setRequiredActions(KeycloakSession keycloakSession, RealmModel realmModel, UserModel userModel) { | ||
// Not used | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// Does nothing | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...loak/phone/authentication/authenticators/conditional/ConditionalPhoneProvidedFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cc.coopersoft.keycloak.phone.authentication.authenticators.conditional; | ||
|
||
import org.keycloak.Config; | ||
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticator; | ||
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticatorFactory; | ||
import org.keycloak.models.AuthenticationExecutionModel; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.ProviderConfigProperty; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ConditionalPhoneProvidedFactory implements ConditionalAuthenticatorFactory { | ||
|
||
public static final String PROVIDER_ID = "conditional-phone-provided"; | ||
public static final String CONF_NOT = "not"; | ||
|
||
private static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = { | ||
AuthenticationExecutionModel.Requirement.REQUIRED, AuthenticationExecutionModel.Requirement.DISABLED | ||
}; | ||
|
||
@Override | ||
public ConditionalAuthenticator getSingleton() { | ||
return ConditionalPhoneProvided.SINGLETON; | ||
} | ||
|
||
@Override | ||
public String getDisplayType() { | ||
return "Condition - phone provided"; | ||
} | ||
|
||
@Override | ||
public boolean isConfigurable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() { | ||
return REQUIREMENT_CHOICES; | ||
} | ||
|
||
@Override | ||
public boolean isUserSetupAllowed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getHelpText() { | ||
return "Flow is executed only if the phone number provided"; | ||
} | ||
|
||
@Override | ||
public List<ProviderConfigProperty> getConfigProperties() { | ||
ProviderConfigProperty negateOutput = new ProviderConfigProperty(); | ||
negateOutput.setType(ProviderConfigProperty.BOOLEAN_TYPE); | ||
negateOutput.setName(CONF_NOT); | ||
negateOutput.setLabel("Negate output"); | ||
negateOutput.setHelpText("Apply a not to the check result"); | ||
|
||
return Collections.singletonList(negateOutput); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope scope) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory keycloakSessionFactory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters