我必须说我对整个模型非常困惑,我需要帮助将所有漂浮的部分粘在一起.
我不是在做Spring REST,只是简单的WebMVC控制器.
我的使命:我希望使用用户名+通过身份验证进行表单登录.我想对第三方服务进行身份验证.成功后我想返回一个cookie但不使用默认的cookie令牌机制.我想让cookie改为使用JWT令牌.通过利用cookie机制,每个请求都将与JWT一起发送.
因此,为了打破它,我有以下模块来照顾:
成功验证后,使用我的自定义实现替换cookie会话令牌
每个请求从cookie中解析JWT(使用过滤器)
从JWT中提取用户详细信息/数据,以便控制器可以访问
什么令人困惑?(请纠正我错在哪里)
第三方认证
要对第三方进行身份验证,我需要通过扩展AuthenticationProvider来获得自定义提供程序
public class JWTTokenAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate( Authentication authentication ) throws AuthenticationException {
// auth against 3rd party
// return Authentication
return new UsernamePasswordAuthenticationToken( name, password, new ArrayList<>() );
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals( UsernamePasswordAuthenticationToken.class );
}
}
Run Code Online (Sandbox Code Playgroud)
问题:
用JWT替换cookie令牌
不知道如何优雅地做到这一点,我可以想到多种方式,但他们不是Spring Security方式,我不想打破流程.非常感谢这里的任何建议!
使用cookie的每个请求解析JWT
根据我的理解,我需要像这样扩展AbstractAuthenticationProcessingFilter
public class CookieAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
@Override
public Authentication attemptAuthentication( HttpServletRequest request, …Run Code Online (Sandbox Code Playgroud) 得到错误{"错误":{"message":"(#100)只能在您的应用的有效测试用户上调用此方法","只要尝试写入任何Facebook端点,就输入":"OAuthException"}} .阅读(GET)工作正常,写作(POST)失败.有谁知道如何解决这个问题?
我还在FB开发网站上开了一张票:http: //developers.facebook.com/bugs/184198634991192?浏览器= search_4e93328871c8a3231774584
没有发生的问题是我会从浏览器中发出POST请求,就好像我是用户一样.仅当我们的服务器代表用户从我们的dev计算机发送其他子域名而不是www(例如dev1.blablabla.com&dev2.blablabla.com,而应用程序已注册到www.blablabla.com).
所以问题是,facebook是否尝试对所有写入请求进行反向DNS查询以验证源?
我目前正在阅读"Javascript:The Good Parts"这本书并正在使用函数.我制作了一个测试脚本来测试一些属性,我对结果感到有些困惑.这是代码:
<h3>Object</h3>
<div style="padding-left: 10px;">
<script type="text/javascript">
function outterF()
{
document.writeln("outterF.this = " + this + "<br>");
function innerF()
{
document.writeln("innerF.this = " + this + "<br>");
return this;
};
var inner = innerF();
return this;
}
document.writeln("<b>From Inside:</b><br>");
var outF = outterF();
var inF = outF.inner;
document.writeln("<br>");
document.writeln("<b>From Outside:</b><br>");
document.writeln("outterF.this = " + outF + "<br>");
document.writeln("innerF.this = " + inF + "<br>");
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
结果是:
Object
From Inside:
outterF.this = [object Window]
innerF.this = [object Window] …Run Code Online (Sandbox Code Playgroud)