Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaRESTAPI中的自定义身份验证_Java_Facebook_Rest_Authentication_Jersey - Fatal编程技术网

JavaRESTAPI中的自定义身份验证

JavaRESTAPI中的自定义身份验证,java,facebook,rest,authentication,jersey,Java,Facebook,Rest,Authentication,Jersey,我正在尝试使用运行在Tomcat7上的Jersey framework v2.5.1在我们的JavaRESTAPI中实现我自己身份验证的最佳方法 API将通过我们的iOS应用程序访问。在iOS应用程序中,我们使用facebooksdk使用Facebook身份验证,然后在对restapi的每次调用中使用访问令牌 @Provider @Priority(Priorities.AUTHENTICATION) public class AuthenticationFilter implements Co

我正在尝试使用运行在Tomcat7上的Jersey framework v2.5.1在我们的JavaRESTAPI中实现我自己身份验证的最佳方法

API将通过我们的iOS应用程序访问。在iOS应用程序中,我们使用facebooksdk使用Facebook身份验证,然后在对restapi的每次调用中使用访问令牌

@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFilter implements ContainerRequestFilter
{
    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException
    {
        // Extract the access token from the HTTP header
        // Look up in the database to see if we have a user with that token
        // If there is a user found, proceed
        // If we can't find a user, we are going to send the token to Facebook to get the user details. If the token is invalid, we throw an exception. If it is valid, we look up if we can match the Facebook details with an existing user. When we can't match, we create a new user.
    }
}
此筛选器将在每个API请求中执行

我的问题是:

这是正确的工作流程吗? 我们是否应该每次联系Facebook来验证令牌?这将导致大量开销。 对每个请求执行此筛选器。我们如何排除某些URL某些资源不需要身份验证?我想在filter类中保存一组url,看看请求的url是否与定义的公共url之一匹配。如果匹配,请不要进行身份验证。
谢谢

我认为如果您能为您的用户提供此选项可能会更好: 登录/使用facebook帐户登录。 所以你不必联系Facebook,除非用户选择使用他们的FB帐户登录。 此外,身份验证应基于会话。会话信息可以包括用户、会话密钥、有效时间范围,也可能包括源IP。用户成功登录后,将生成一个会话。然后,对于每个请求,您只需检查会话密钥是否仍然有效