public class GoogleReCaptchaChecker {
@Value("${google.recaptcha.url}")
private String url;
@Value("${google.recaptcha.secret-key}")
private String secretKey;
@Value("${google.recaptcha.site-key}")
private String siteKey;
@Autowired
RestTemplate restTemplate;
public Boolean validateGoogleReCaptcha(String reCaptchaResponseStr, String remoteAddr) {
try {
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(secretKey);
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, siteKey, reCaptchaResponseStr);
return reCaptchaResponse.isValid();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的"google recaptcha"验证代码,但它总是返回false,我不知道需要传递什么参数.是否有任何maven依赖进行ReCaptcha验证?我正在使用这个net.tanesha.recaptcha4j(version-0.0.7)依赖项
我想在没有设置org.springframework.ui.Model的情况下访问thymeleaf中的contextPath.我在application.properties文件中配置了上下文路径
Encryption
Md5PasswordEncoder md5PasswordEncoder =new Md5PasswordEncoder();
md5PasswordEncoder.encodePassword(userRegistrationInfo.getPassword(),AppConstants.MD5_PASSWORD_ENCODER_SALT);
Spring Security Configuration
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder(){
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
Run Code Online (Sandbox Code Playgroud)
我需要使用org.springframework.security.authentication.encoding.Md5PasswordEncoder进行密码加密.但我不知道如何在Spring安全配置中配置passwordEncoder()