All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dahuatech.icc.brm.vo.BaseRequest Maven / Gradle / Ivy

The newest version!
package com.dahuatech.icc.brm.vo;

import com.dahuatech.icc.brm.exception.BusinessException;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigBaseInfo;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.profile.GrantType;
import com.dahuatech.icc.util.StringUtils;

public abstract class BaseRequest {

    protected OauthConfigBaseInfo oauthConfigBaseInfo;

    public OauthConfigBaseInfo getOauthConfigBaseInfo() {
        return oauthConfigBaseInfo;
    }

    public void setOauthConfigBaseInfo(OauthConfigBaseInfo oauthConfigBaseInfo) {
        this.oauthConfigBaseInfo = oauthConfigBaseInfo;
    }

    public void valid(){
        /**
         * 鉴权参数校验
         */
        baseCheck();
    }

    public void baseCheck(){
        if(this == null){
            throw new BusinessException("请求对象为空");
        }
        if(oauthConfigBaseInfo == null){
            throw new BusinessException("鉴权信息为空");
        }
        if(oauthConfigBaseInfo.getGrantType() == null){
            throw new BusinessException("鉴权类型为空");
        }
        if(StringUtils.isEmpty(oauthConfigBaseInfo.getClientId())){
            throw new BusinessException("申请访问凭证id为空");
        }
        if(StringUtils.isEmpty(oauthConfigBaseInfo.getClientSecret())){
            throw new BusinessException("申请访问凭证密钥为空");
        }
        if(oauthConfigBaseInfo.getHttpConfigInfo() == null){
            throw new BusinessException("平台信息为空");
        }
        if(StringUtils.isEmpty(oauthConfigBaseInfo.getHttpConfigInfo().getHost())){
            throw new BusinessException("平台信息|host为空");
        }
        if(oauthConfigBaseInfo.getGrantType() == GrantType.password){//客户端
            OauthConfigUserPwdInfo oauthConfigUserPwdInfo = (OauthConfigUserPwdInfo)oauthConfigBaseInfo;
            if(StringUtils.isEmpty(oauthConfigUserPwdInfo.getPassword())){
                throw new BusinessException("平台信息|密码为空");
            }
            if(StringUtils.isEmpty(oauthConfigUserPwdInfo.getUsername())){
                throw new BusinessException("平台信息|用户名为空");
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy