小编Jac*_*aby的帖子

如何在春季启动时验证谷歌recaptcha?

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)依赖项

java recaptcha spring-boot

6
推荐指数
1
解决办法
965
查看次数

如何在Thymeleaf中访问contextPath?

我想在没有设置org.springframework.ui.Model的情况下访问thymeleaf中的contextPath.我在application.properties文件中配置了上下文路径

thymeleaf spring-boot

3
推荐指数
2
解决办法
7942
查看次数

如果我使用Md5PasswordEncoder进行密码加密,如何在spring security config中配置passwordEncoder?

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()

java spring spring-mvc spring-boot

0
推荐指数
2
解决办法
1万
查看次数

标签 统计

spring-boot ×3

java ×2

recaptcha ×1

spring ×1

spring-mvc ×1

thymeleaf ×1