这是本节的多页打印视图。 点击此处打印.

返回本页常规视图.

接口鉴权

支持通过SPI扩展机制,扩展集成应用接口中的接口鉴权模式(集成应用-接口-安全认证)。

1、概述

接口鉴权场景: 集成应用中调用的三方接口需要前置认证的情况,例如先调用认证接口token,调用其他业务接口时,讲token放到请求头中。

2、接入导图

3、接入步骤

3.1、Demo工程下载

cip-connector-auth-template.zip

注意事项: 1.pom中的版本号要与项目当前版本保持一致,分别为boot版本、cip-connector-api版本

    <parent>
        <groupId>com.seeyon</groupId>
        <artifactId>boot</artifactId>
        <version>3.10.1</version>
    </parent>
    <properties>
        <platform.version>3.10.1</platform.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.seeyon</groupId>
            <artifactId>cip-connector-api</artifactId>
            <version>${platform.version}</version>
        </dependency>
    </dependencies>

3.2. spi jar 打包并部署

参考 SPI扩展

上传完后需要重启cip-connector完成动态加载

3.3、工程开发

注意:每个项目下载工程并开发时,请优先修改工程名称,工程名遵守 cip-connector-auth-项目标识

4、工程核心接口说明

    /**
     * 认证请求(核心)
     * @param authenticationDto 安全数据
     * authId: 该安全认证在数据库中id
     * detailId: 动作id,外部正在执行的动作id
     * json: 页面配置动态数据,自行转换对应dto或者map
     * params: 请求参数
     * user: 当前登录人用户信息(包含用户映射配置信息)
         * innerUserId: 内部用户ID
         * innerUserName: 内部用户名称
         * innerUserCODE: 内部用户编号
         * outerUser: 外部用户账户
         * outerUserId: 外部用户ID
         * innerUserLoginName: 内部用户登录名
         * innerUserEmail: 内部用户邮箱
         * innerUserPhone: 内部用户手机号
         * innerUserOfficeNumber: 内部用户办公电话
         * innerUserBankAccount: 内部用户银行账户
         * innerUserOrgId: 内部用户组织编号
     * @return 请求map  <位置-->Map<key,value>> 位置:header query body
     * 如:  {"body":{"token":"123"}}
     */
    @Override
    public Map<String, Object> doAuthentication(AuthenticationDto authenticationDto) throws Exception {
        // 转换页面动态配置信息为dto
        AuthDto authDto = JsonUtils.fromJson(authenticationDto.getJson(), AuthDto.class);
        AuthenticationUserDto user = authenticationDto.getUser();
        JsonDto jsonDto = new JsonDto();
        String username = null;
        if(user.getUserMap().get(authDto.getUsernameParam()) == null){
            throw new BusinessException("安全登录:用户名为空");
        }else {
            username = user.getUserMap().get(authDto.getUsernameParam()).toString();
            jsonDto.setXxx3(username);
        }
        if(user.getUserMap().get(authDto.getPasswordParam()) == null){
            throw new BusinessException("安全登录:密码为空");
        }else {
            jsonDto.setXxx4( MD5Utils.md5(user.getUserMap().get(authDto.getPasswordParam()).toString()).toLowerCase(Locale.ROOT));
        }
        String json = JsonUtils.toJson(jsonDto);
        String base64 = Base64.getEncoder().encodeToString(json.getBytes(StandardCharsets.UTF_8));
        log.info("安全登录,请求参数加密前:{}",json);
        log.info("安全登录,请求参数加密后:{}",base64);
        HttpResult httpResult = HttpClientUtil.sendPost(authDto.getTokenUrl(), base64);
        if(httpResult.getStatusCode()!= 200){
            throw new BusinessException("安全登录,请求返回结果码:{}", String.valueOf(httpResult.getStatusCode()));
        }
        log.info("安全登录,请求返回结果:{}",httpResult.getResult());
        AuthTokenResponse authTokenResponse = JsonUtils.fromJson(httpResult.getResult(), AuthTokenResponse.class);
        
        HashMap<String, Object> map = new HashMap<>();
        map.put("user",username);
        map.put("token", authTokenResponse.getToken());
        if("param".equals(authDto.getParameterLocation())){
            map.put("projectName",authDto.getProjectName());
        }else{
            map.put("project_name",authDto.getProjectName());
        }
        HashMap<String, Object> result = new HashMap<>();
        result.put(authDto.getParameterLocation(),map);
        return result;
    }

5、注意事项