keycloak-service
公開メンバ関数 | 静的公開変数類 | 限定公開メンバ関数 | 静的関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.authentication.forms.RegistrationRecaptcha クラス
org.keycloak.authentication.forms.RegistrationRecaptcha の継承関係図
Inheritance graph
org.keycloak.authentication.forms.RegistrationRecaptcha 連携図
Collaboration graph

公開メンバ関数

String getDisplayType ()
 
String getReferenceCategory ()
 
boolean isConfigurable ()
 
AuthenticationExecutionModel.Requirement [] getRequirementChoices ()
 
void buildPage (FormContext context, LoginFormsProvider form)
 
void validate (ValidationContext context)
 
void success (FormContext context)
 
boolean requiresUser ()
 
boolean configuredFor (KeycloakSession session, RealmModel realm, UserModel user)
 
void setRequiredActions (KeycloakSession session, RealmModel realm, UserModel user)
 
boolean isUserSetupAllowed ()
 
void close ()
 
FormAction create (KeycloakSession session)
 
void init (Config.Scope config)
 
void postInit (KeycloakSessionFactory factory)
 
String getId ()
 
String getHelpText ()
 
List< ProviderConfigProperty > getConfigProperties ()
 

静的公開変数類

static final String G_RECAPTCHA_RESPONSE = "g-recaptcha-response"
 
static final String RECAPTCHA_REFERENCE_CATEGORY = "recaptcha"
 
static final String SITE_KEY = "site.key"
 
static final String SITE_SECRET = "secret"
 
static final String PROVIDER_ID = "registration-recaptcha-action"
 

限定公開メンバ関数

boolean validateRecaptcha (ValidationContext context, boolean success, String captcha, String secret)
 

静的関数

 [static initializer]
 

静的非公開変数類

static final Logger logger = Logger.getLogger(RegistrationRecaptcha.class)
 
static AuthenticationExecutionModel.Requirement [] REQUIREMENT_CHOICES
 
static final List< ProviderConfigProperty > CONFIG_PROPERTIES = new ArrayList<ProviderConfigProperty>()
 

詳解

著者
Bill Burke
バージョン
Revision
1

関数詳解

◆ [static initializer]()

org.keycloak.authentication.forms.RegistrationRecaptcha.[static initializer] ( )
inlinestaticpackage

◆ buildPage()

void org.keycloak.authentication.forms.RegistrationRecaptcha.buildPage ( FormContext  context,
LoginFormsProvider  form 
)
inline
94  {
95  AuthenticatorConfigModel captchaConfig = context.getAuthenticatorConfig();
96  String userLanguageTag = context.getSession().getContext().resolveLocale(context.getUser()).toLanguageTag();
97  if (captchaConfig == null || captchaConfig.getConfig() == null
98  || captchaConfig.getConfig().get(SITE_KEY) == null
99  || captchaConfig.getConfig().get(SITE_SECRET) == null
100  ) {
101  form.addError(new FormMessage(null, Messages.RECAPTCHA_NOT_CONFIGURED));
102  return;
103  }
104  String siteKey = captchaConfig.getConfig().get(SITE_KEY);
105  form.setAttribute("recaptchaRequired", true);
106  form.setAttribute("recaptchaSiteKey", siteKey);
107  form.addScript("https://www.google.com/recaptcha/api.js?hl=" + userLanguageTag);
108  }
static final String SITE_SECRET
Definition: RegistrationRecaptcha.java:65
static final String SITE_KEY
Definition: RegistrationRecaptcha.java:64

◆ close()

void org.keycloak.authentication.forms.RegistrationRecaptcha.close ( )
inline
190  {
191 
192  }

◆ configuredFor()

boolean org.keycloak.authentication.forms.RegistrationRecaptcha.configuredFor ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inline
174  {
175  return true;
176  }

◆ create()

FormAction org.keycloak.authentication.forms.RegistrationRecaptcha.create ( KeycloakSession  session)
inline
195  {
196  return this;
197  }

◆ getConfigProperties()

List<ProviderConfigProperty> org.keycloak.authentication.forms.RegistrationRecaptcha.getConfigProperties ( )
inline
240  {
241  return CONFIG_PROPERTIES;
242  }
static final List< ProviderConfigProperty > CONFIG_PROPERTIES
Definition: RegistrationRecaptcha.java:219

◆ getDisplayType()

String org.keycloak.authentication.forms.RegistrationRecaptcha.getDisplayType ( )
inline
71  {
72  return "Recaptcha";
73  }

◆ getHelpText()

String org.keycloak.authentication.forms.RegistrationRecaptcha.getHelpText ( )
inline
215  {
216  return "Adds Google Recaptcha button. Recaptchas verify that the entity that is registering is a human. This can only be used on the internet and must be configured after you add it.";
217  }

◆ getId()

String org.keycloak.authentication.forms.RegistrationRecaptcha.getId ( )
inline
210  {
211  return PROVIDER_ID;
212  }
static final String PROVIDER_ID
Definition: RegistrationRecaptcha.java:68

◆ getReferenceCategory()

String org.keycloak.authentication.forms.RegistrationRecaptcha.getReferenceCategory ( )
inline
76  {
78  }
static final String RECAPTCHA_REFERENCE_CATEGORY
Definition: RegistrationRecaptcha.java:63

◆ getRequirementChoices()

AuthenticationExecutionModel.Requirement [] org.keycloak.authentication.forms.RegistrationRecaptcha.getRequirementChoices ( )
inline
90  {
91  return REQUIREMENT_CHOICES;
92  }
static AuthenticationExecutionModel.Requirement [] REQUIREMENT_CHOICES
Definition: RegistrationRecaptcha.java:85

◆ init()

void org.keycloak.authentication.forms.RegistrationRecaptcha.init ( Config.Scope  config)
inline
200  {
201 
202  }

◆ isConfigurable()

boolean org.keycloak.authentication.forms.RegistrationRecaptcha.isConfigurable ( )
inline
81  {
82  return true;
83  }

◆ isUserSetupAllowed()

boolean org.keycloak.authentication.forms.RegistrationRecaptcha.isUserSetupAllowed ( )
inline
184  {
185  return false;
186  }

◆ postInit()

void org.keycloak.authentication.forms.RegistrationRecaptcha.postInit ( KeycloakSessionFactory  factory)
inline
205  {
206 
207  }

◆ requiresUser()

boolean org.keycloak.authentication.forms.RegistrationRecaptcha.requiresUser ( )
inline
169  {
170  return false;
171  }

◆ setRequiredActions()

void org.keycloak.authentication.forms.RegistrationRecaptcha.setRequiredActions ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inline
179  {
180 
181  }

◆ success()

void org.keycloak.authentication.forms.RegistrationRecaptcha.success ( FormContext  context)
inline
164  {
165 
166  }

◆ validate()

void org.keycloak.authentication.forms.RegistrationRecaptcha.validate ( ValidationContext  context)
inline
111  {
112  MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
113  List<FormMessage> errors = new ArrayList<>();
114  boolean success = false;
115  context.getEvent().detail(Details.REGISTER_METHOD, "form");
116 
117  String captcha = formData.getFirst(G_RECAPTCHA_RESPONSE);
118  if (!Validation.isBlank(captcha)) {
119  AuthenticatorConfigModel captchaConfig = context.getAuthenticatorConfig();
120  String secret = captchaConfig.getConfig().get(SITE_SECRET);
121 
122  success = validateRecaptcha(context, success, captcha, secret);
123  }
124  if (success) {
125  context.success();
126  } else {
127  errors.add(new FormMessage(null, Messages.RECAPTCHA_FAILED));
128  formData.remove(G_RECAPTCHA_RESPONSE);
129  context.error(Errors.INVALID_REGISTRATION);
130  context.validationError(formData, errors);
131  context.excludeOtherErrors();
132  return;
133 
134 
135  }
136  }
boolean validateRecaptcha(ValidationContext context, boolean success, String captcha, String secret)
Definition: RegistrationRecaptcha.java:138
static final String G_RECAPTCHA_RESPONSE
Definition: RegistrationRecaptcha.java:62
static final String SITE_SECRET
Definition: RegistrationRecaptcha.java:65
void success(FormContext context)
Definition: RegistrationRecaptcha.java:164

◆ validateRecaptcha()

boolean org.keycloak.authentication.forms.RegistrationRecaptcha.validateRecaptcha ( ValidationContext  context,
boolean  success,
String  captcha,
String  secret 
)
inlineprotected
138  {
139  HttpClient httpClient = context.getSession().getProvider(HttpClientProvider.class).getHttpClient();
140  HttpPost post = new HttpPost("https://www.google.com/recaptcha/api/siteverify");
141  List<NameValuePair> formparams = new LinkedList<>();
142  formparams.add(new BasicNameValuePair("secret", secret));
143  formparams.add(new BasicNameValuePair("response", captcha));
144  formparams.add(new BasicNameValuePair("remoteip", context.getConnection().getRemoteAddr()));
145  try {
146  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
147  post.setEntity(form);
148  HttpResponse response = httpClient.execute(post);
149  InputStream content = response.getEntity().getContent();
150  try {
151  Map json = JsonSerialization.readValue(content, Map.class);
152  Object val = json.get("success");
153  success = Boolean.TRUE.equals(val);
154  } finally {
155  content.close();
156  }
157  } catch (Exception e) {
158  ServicesLogger.LOGGER.recaptchaFailed(e);
159  }
160  return success;
161  }
void success(FormContext context)
Definition: RegistrationRecaptcha.java:164

メンバ詳解

◆ CONFIG_PROPERTIES

final List<ProviderConfigProperty> org.keycloak.authentication.forms.RegistrationRecaptcha.CONFIG_PROPERTIES = new ArrayList<ProviderConfigProperty>()
staticprivate

◆ G_RECAPTCHA_RESPONSE

final String org.keycloak.authentication.forms.RegistrationRecaptcha.G_RECAPTCHA_RESPONSE = "g-recaptcha-response"
static

◆ logger

final Logger org.keycloak.authentication.forms.RegistrationRecaptcha.logger = Logger.getLogger(RegistrationRecaptcha.class)
staticprivate

◆ PROVIDER_ID

final String org.keycloak.authentication.forms.RegistrationRecaptcha.PROVIDER_ID = "registration-recaptcha-action"
static

◆ RECAPTCHA_REFERENCE_CATEGORY

final String org.keycloak.authentication.forms.RegistrationRecaptcha.RECAPTCHA_REFERENCE_CATEGORY = "recaptcha"
static

◆ REQUIREMENT_CHOICES

AuthenticationExecutionModel.Requirement [] org.keycloak.authentication.forms.RegistrationRecaptcha.REQUIREMENT_CHOICES
staticprivate
初期値:
= {
AuthenticationExecutionModel.Requirement.REQUIRED,
AuthenticationExecutionModel.Requirement.DISABLED
}

◆ SITE_KEY

final String org.keycloak.authentication.forms.RegistrationRecaptcha.SITE_KEY = "site.key"
static

◆ SITE_SECRET

final String org.keycloak.authentication.forms.RegistrationRecaptcha.SITE_SECRET = "secret"
static

このクラス詳解は次のファイルから抽出されました: