我的应用程序获取了一个自定义令牌,我必须登录。 我有一个自定义应用程序代码来检查令牌是否有效。
例如
public class CustomAuthenticationTokenProvider implements AuthenticationProvider {
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
// logic for validating the token. This gives a validated authentication
...
...
//Here first argument to constructor is principal and 2nd argument is //credentials.
CustomAuthenticationToken customAuthenticationToken = new CustomAuthenticationToken(authentication.getToken(), null);
return customAuthenticationToken;
}
}
我上面有测试,它运行正常。
查询:我是否必须要求凭据才能创建成功的身份验证对象。这种方法是否存在任何风险。
答案 0 :(得分:-1)
不,您实际上可以在没有任何凭据的情况下创建完全身份验证的身份验证对象,但是问问自己......您是在没有提供任何凭据的情况下向用户提供完整身份验证,因此任何可以访问您的过滤器的人都可以访问网址能够得到认证。
您必须非常谨慎使用此应用令牌,因为任何获得此令牌的人都可以访问您受保护的网址