我正在使用 j_acegi_security_check登录到SpringWeb 应用程序,但因为它也接受GET参数,这意味着我能够登录到应用程序
<https://localhost:8080/webapp/j_acegi_security_check?j_username=***&j_password=***&loginButton=Login>
我想避免这种情况。它应该只接受POST请求。这该怎么做?
我正在使用 j_acegi_security_check登录到SpringWeb 应用程序,但因为它也接受GET参数,这意味着我能够登录到应用程序
<https://localhost:8080/webapp/j_acegi_security_check?j_username=***&j_password=***&loginButton=Login>
我想避免这种情况。它应该只接受POST请求。这该怎么做?
默认情况下,spring security 3.x 只接受POST登录请求。
postOnly但是您可以使用参数来控制这种行为org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
(但正如我之前所说,默认postOnly为true)
但也许主要问题是您使用的是旧的 spring acegi security 而不是实际的 spring security 3.x。情况是这样,而不是上面的陈述是我不正确的。所以强烈建议更新!
如果是 Spring ACEGI 1.0.x
尝试使用以下方法覆盖attemptAuthentication方法AuthenticationProcessingFilter:
if (request.getMethod().equals("POST"))
return super.attemptAuthentication(request);
else
throw new AuthenticationServiceException("service accept only http post");
查看评论:覆盖onPreAuthentication()接缝也是一个好方法