SmartBi 单点登录的实现

  • 注:目前由于类似于OA的系统需要集成SmartBi工具,这个集成的大概意思是当用户登录进OA后就可以直接通过单点登录的方式进入SmartBi。

准备Smartbi服务器加载LoginToken扩展包

下载路径:
http://wiki.smartbi.com.cn/download/attachments/27001766/logintoken.ext?version=3&modificationDate=1498640793000&api=v2

修改SmartBi 的配置

登录到 Smartbi 配置管理页面,地址为 http://10.xxx.xx.xx/smartbi/vision/config.jsp

  • 在页面中的用户管理模块
    修改加密类型为:class
    登录验证类:smartbi.usermanager.auth.impl.ADAuthentication

  • 将LoginToken扩展包上传到服务器
    上传路径:/usr/local/tomcat-smartbi/webapps/smartbi/WEB-INF/extensions

  • 保存并重启smartbi。

编写单点登录的接口

  • 接口说明:该接口通过Spring boot 部署,第三方系统只需要通过访问该接口并传入用户名便可实现单点登录到smartBi的登录界面。

  • 接口安全性说明:对于第三方用户传进来的用户名通过DES对称加密的方式进行传递;

    该接口的访问端口只对集群内服务器进行开放,以及该接口支持配置IP白名单对用户IP进行限制访问。

  • 核心代码块

/**
     * 通过管理员获取用户与密码
     * 这个插件的用途是使得在URL中传递密码只能使用一次,集成系统首先通过Smartbi的SDK获取用户的动态密码密码60秒内有效
     * 可在LoginToken.ext\META-INF\aplicationContext.xml修改timeout属性;
     * 获取动态密码的示例:(目前因为这种方式不支持直接跳转到smartBi主页,因而这个方法只是用来获取动态密码)
     * http://10.xxx.xx.xx/smartbi.openresource.jsp?user=demo&password=
     * I8a42c394015f5ce25ce27fa2015f5cee60e70017
     * 
     */
    public static String getSmartBiToken(String userName) {
        ClientConnector conn = null;
        InvokeResult result = null;
        try {
            conn = new ClientConnector(PropertyUtil.getProperty("smartBiConn"));
            conn.open(PropertyUtil.getProperty("smartBiAdmin"), PropertyUtil.getProperty("smartBiPwd"));// 以管理员身份登录
            result = conn.remoteInvoke("LoginTokenModule", "generateLoginToken", new Object[] { userName });// 用户名
            log.info("GetSmartBiToken is success and the result is " + result.toString());
        } catch (Exception e) {
            log.error("GetSmartBiToken is failed and the errMag=" + e.getMessage());
            e.printStackTrace();
        } finally {
            conn.close();
        }
        return result.getResult().toString();
    }

@Controller
public class SmartBiController {
    private static Logger log = Logger.getLogger(SmartBiController.class);

    @GetMapping("/login_smartBi")
    String loginSmartBi(HttpServletRequest request,
            @RequestParam(value = "userName", required = true) String userName) {

        try {
            log.info("userName: " + userName);
            userName = DESUtils.decrypt(userName);
            log.info("decrypt userName: " + userName);
            userName = SmartBiService.handleSpecialChar(userName);
            log.info("handleSpecialChar userName: " + userName);

        } catch (Exception e) {
            log.error("LoginSmartBi is failed and the errMes=" + e.getMessage());
            e.printStackTrace();
        }

        String userPwd = SmartBiService.getSmartBiToken(userName);
        request.setAttribute("userPwd", userPwd);
        request.setAttribute("userName", userName);
        request.setAttribute("smartBiIndex", PropertyUtil.getProperty("smartBiIndex"));

        log.info("userName:" + userName + ",userPwd:" + userPwd);

        return "loginSmartBi";
    }

注:上述代码需要一些必要的jar,
1、获取这些jar的方式:
打开服务器部署文件smartbi.war,解压后将smartbi.war\WEB-INF\lib\目录下的 smartbi-SDK.jar、smartbi-Common.jar、ezmorph-0.8.1.jar、commons-logging-1.1.jar、commons-beanutils.jar、commons-collections-3.2.jar 包加入到您的Java 项目的classpath 中去。

2、注意不能通过该方法获取admin管理员的动态密码,也就是说admin用户不支持单点登录。如需要管理员也能单点登录则可以另添加一个帐号不为admin的管理员。

3、得到密码后可以通过openresource.jsp?user=demo&password=上述得到的动态密码打开Smartbi的资源,但是发现得到的动态密码并不支持直接登录到smartbi的首页,因而这里自己编写登录脚本进行登录。
登录脚本的核心代码块如下:

<!DOCTYPE html>
<html>
<body>
    <form method="POST" id="formLogin" th:action="${smartBiIndex}">
        <input type="hidden" name="user"  th:value="${userName}"/> 
        <input type="hidden" name="password" th:value="${userPwd}"/>
    </form>
</body>

<script type="text/javascript">
    document.getElementById("formLogin").submit();
</script>
</html>

上述代码传送的用户名是DES对称加密的,密码是加密后并只有60秒时效的密码。

单点登录接口规范

​ GET

  • 请求参数:
参数名必选说明
userName通过DES对称加密后的用户名
  • 返回参数
    成功则直接跳转到SmartBi的主页,否则跳转到SmartBi登录界面

同步第三方系统用户到SmartBi

  • 实现思路:
    通过定时任务定时同步权限系统中rbac.t_user 表中有效的用户进行到SmartBi对应的t_user、t_group_user表中。
  • 同步进来的用户默认有效且部门为普通用户,如所需要进行更新用户角色则需要以管理员身份登录SmartBi进行手动授权。

  • 注:
    1、由于目前该产品只买了25个帐号,在测试的过程中发现当用户添加超过25个,系统后台将报错并无法进行单点登录。

  • 特别提醒:
    SmartBi不支持特殊字符,但是用户是通过统一身份认证单点登录进来的,也就是说这些通过单点登录进来的用户帐号可能带有特殊字符。
    因此我们需要将这些用户中存在的特殊字符处理掉后再添加到smartBi。目前单点登录那些的处理逻辑是当用户帐号中有( \ / ’ | ” * ? % . = : ; )这些符号(不包含括号)则替换成@符号。例如:
    统一身份认证的用户帐号为:dll01dd4@gzemail.cn 则我们在smartBi中手动添加进来的用户则应该是:dll01dd4@gzemail@cn,也就是说把点号替换成了@符号。

参考文档:
http://wiki.smartbi.com.cn/plugins/servlet/mobile?from=singlemessage#content/view/27001766
http://wiki.smartbi.com.cn/plugins/servlet/mobile?from=singlemessage#content/view/27002118

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值