用于第三方系统集成Smartbi中单点登录加密传输用户信息,安全系数更高,不会暴露用户的真实密码。
第三方系统使用密钥对用户登录信息进行AES或DES加密来形成token,当客户端发起的请求携带有令牌登录参数以及目标跳转地址时,Smartbi服务器拦截到请求后,对token信息进行解析和校验,如果成功解析出用户信息并校验成功,则将用户设置为登录状态,再重定向到对应地址,后续访问其他地址无须重新登录。可用于第三方系统集成Smartbi中单点登录加密传输用户信息,安全系数更高,不会暴露用户的真实密码。
token:token是客户端使用密钥加密用户登录信息形成的一串字符串,以作客户端进行请求的一个令牌。
访问Smartbi的Config配置界面 (地址为 http://IP:PORT/smartbi/vision/config.jsp),配置令牌登录的信息:密钥、超时时间等
配置项 | 说明 | |
---|---|---|
密钥 | 用来解密token信息。客户端需要用密钥来进行加密用户信息。密钥为默认空,表示不支持令牌登录这种方式。 密钥由用户自定义输入8位或16位字符串,后续生成令牌信息时需要使用相同的密钥
| |
令牌超时时间 | token有效时间。当【服务器解析请求时间戳 - token的生成的时间戳 > 超时设置 】成立时,则代表token已超时,不能进行登录; | |
需要校验密码 | 设置token中是否要包含密码,使用密码来进行登录。
|
使用 smartbi-CryptoUtil.jar 的工具类的encrypt方法(默认使用AES-GCM方式加密)来加密token来获得令牌,其中加密API是:smartbi.crypto.CryptoUtil.encrypt(String, String)。
另外DES的加密API是:CryptoUtil.encrypt(AlgorithmType.DES,String,String)。
参考示例:
//生成token String secretKey = "12345678";// 密钥 Long timestamp = new java.util.Date().getTime();// 时间戳 String userName = "admin";// 用户名 String password = "admin";// 用户密码(可选) String token = "{\"username\":\"" + userName + "\",\"password\":\"" + password + "\",\"timestamp\":" + timestamp + "}"; String encryptedToken = null; try { encryptedToken = CryptoUtil.encrypt(token, secretKey); //如果选择使用使用des加密,使用接口: CryptoUtil.encrypt(AlgorithmType.DES,token, secretKey); } catch(Exception e) { // } |
Token的结构参考如下:
{ "timestamp":时间戳, "username":"用户名", "password":"可选,用户密码" } |
token为json格式,其中时间戳在java语法中指new java.util.Date().getTime()获取的毫秒数,如1648519473246,不需要双引号,其他部分的双引号不可以缺少 |
链接格式:http://ip:port/smartbi/vision/loginByToken?smartbiToken=用户信息加密串&targetPath=目标跳转链接及其参数
链接格式解析 | 作用 | |
---|---|---|
ip:port | Smartbi系统服务器地址及端口 | |
smartbiToken | 令牌,即使用AES或DES加密的token信息,token信息在js代码中需要使用encodeURIComponent转义,java代码中需要URLEncoder.encode("密文", "UTF-8"),避免 token中存在特殊字符导致令牌解密失败 | |
targetPath | 目标跳转界面,当token校验结束后,直接重定向到该地址,只接受相对路径。
|
常用集成界面示例:
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649...&targetPath=index.jsp |
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649...&targetPath=openresource.jsp?resid=I2c94ea86298cbe6c01298cfd9ba900fa |
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649...&targetPath=openmodule.jsp?id=Analysis&showbanner=false |
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649...&targetPath=createresource.jsp?restype=VISUAL |
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649b0d41c35..&targetPath=mobileX/index |
http://localhost:8080/smartbi/vision/loginByToken?smartbiToken=54f296bd4649b0d41....&targetPath=mobileX/report?resid=I2c94ea86298cbe6c01298cfd9ba900fa |
web项目使用令牌登录集成Smartbi:使用令牌登录示例.zip
注:该示例只对V11版本2023-10-19之后打包的日期才有效,之前的版本可以沿用V10的示例