如何创建使用Java认证令牌 [英] How to create a authentication token using Java

查看:983
本文介绍了如何创建使用Java认证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java EE6,REST服务,我想使用的认证令牌从移动设备登录,用户将派出自己的用户名,密码,服务器会发送回一个令牌,该令牌将被用来授权他们还要求用户对于给定的时间。

On my Java EE6, REST service, I want to use authentication tokens for login from mobile devices, User will send their username, password and server will send back a token, which will be used to authorize the user on their further requests for a given time.

我可以简单地创建令牌自己这样吗?(我想我不需要加密此,因为我将使用HTTPS。)

Can I simply create a token myself like this?(I guess I do not need to encrypt this since I will use HTTPS.)

String token = UUID.randomUUID().toString().toUpperCase() 
            + "|" + "userid" + "|"
            + cal.getTimeInMillis();

,或者对建立我的标记更非标准的方式?也许它存在于API的一个

Or there is a more standart way to create my tokens? maybe it exists in one of API's

推荐答案

在有效地提出该方案允许客户端不受限制地访问你的服务。初始登录之后,UID和'用户ID'将被提供给客户,它可以与一个总是有效的时间戳被简单地结合起来。

The scheme you are proposing effectively allows a client unlimited access to your service. After an initial login, the UID and 'userid' will be made available to the client, which can be simply combined with an always valid timestamp.

如果您需要登录和会话令牌的服务,那么为什么不使用一个HttpSession?

If you need a service with 'login' and a session token, then why not just use an HttpSession?

这篇关于如何创建使用Java认证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆