mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-09 23:12:06 -03:30
Migrate old recaptcha secret name when used
Closes #38607 Signed-off-by: rmartinc <rmartinc@redhat.com> (cherry picked from commit ba91a092ab6a8266a89be254405d3a6d64dcce85)
This commit is contained in:
parent
019cd474c5
commit
e368185abd
@ -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));
|
||||
formparams.add(new BasicNameValuePair("remoteip", context.getConnection().getRemoteAddr()));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user