mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-25 16:42:34 +00:00
Migrate old recaptcha secret name when used
Closes #38607 Signed-off-by: rmartinc <rmartinc@redhat.com>
This commit is contained in:
@@ -47,6 +47,7 @@ public class RegistrationRecaptcha extends AbstractRegistrationRecaptcha {
|
||||
|
||||
// option keys
|
||||
public static final String SECRET_KEY = "secret.key";
|
||||
public static final String OLD_SECRET = "secret";
|
||||
|
||||
@Override
|
||||
public String getDisplayType() {
|
||||
@@ -68,7 +69,8 @@ public class RegistrationRecaptcha extends AbstractRegistrationRecaptcha {
|
||||
|
||||
@Override
|
||||
protected boolean validateConfig(Map<String, String> config) {
|
||||
return !(StringUtil.isNullOrEmpty(config.get(SITE_KEY)) || StringUtil.isNullOrEmpty(config.get(SECRET_KEY)));
|
||||
return !StringUtil.isNullOrEmpty(config.get(SITE_KEY)) &&
|
||||
(!StringUtil.isNullOrEmpty(config.get(SECRET_KEY)) || !StringUtil.isNullOrEmpty(config.get(OLD_SECRET)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +80,16 @@ public class RegistrationRecaptcha extends AbstractRegistrationRecaptcha {
|
||||
|
||||
HttpPost post = new HttpPost("https://www." + getRecaptchaDomain(config) + "/recaptcha/api/siteverify");
|
||||
List<NameValuePair> formparams = new LinkedList<>();
|
||||
formparams.add(new BasicNameValuePair("secret", config.get(SECRET_KEY)));
|
||||
String secret = config.get(SECRET_KEY);
|
||||
if (StringUtil.isNullOrEmpty(secret)) {
|
||||
// migrate old config name to the new one
|
||||
secret = config.get(OLD_SECRET);
|
||||
if (!StringUtil.isNullOrEmpty(secret)) {
|
||||
config.put(SECRET_KEY, secret);
|
||||
config.remove(OLD_SECRET);
|
||||
}
|
||||
}
|
||||
formparams.add(new BasicNameValuePair("secret", secret));
|
||||
formparams.add(new BasicNameValuePair("response", captcha));
|
||||
if (context.getConnection().getRemoteAddr() != null) {
|
||||
formparams.add(new BasicNameValuePair("remoteip", context.getConnection().getRemoteAddr()));
|
||||
|
||||
Reference in New Issue
Block a user