Search in sources :

Example 1 with EcBaseOauthResourceDTO

use of com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO in project dq-easy-cloud by dq-open-cloud.

the class EcOauthManager method getOauthResourceDTO.

/**
 * <p>
 * 获取授权资源数据传输对象
 * </p>
 *
 * @param oauth2Token
 * @return com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthUserDTO
 * @author daiqi
 * @date 2018/7/16 16:07
 */
@Transactional(rollbackFor = Exception.class)
public EcBaseOauthResourceDTO getOauthResourceDTO(EcBaseOauthToken oauth2Token) {
    try {
        // 获取授权token
        Map<String, Object> oAuthResponseParam = getAccessToken(oauth2Token);
        EcBaseOauthResourceDTO oauthResourceDTO = oauth2Token.doGetOauthResource(oAuthResponseParam);
        oauthService.saveOauthResource(oauthResourceDTO);
        return oauthResourceDTO;
    } catch (Exception e) {
        e.printStackTrace();
        throw new AuthenticationException(e);
    }
}
Also used : AuthenticationException(org.apache.shiro.authc.AuthenticationException) EcBaseOauthResourceDTO(com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO) AuthenticationException(org.apache.shiro.authc.AuthenticationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EcBaseOauthResourceDTO

use of com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO in project dq-easy-cloud by dq-open-cloud.

the class EcBaseOauthToken method doGetOauthResource.

/**
 * <p>
 * 执行获取授权资源信息
 * </p>
 * <pre>
 *     子类可以通过重写该方法实现自己的获取授权资源数据传输对象的数据
 * </pre>
 *
 * @param oAuthResponseParam
 * @return com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO
 * @author daiqi
 * @date 2018/7/18 11:54
 */
public EcBaseOauthResourceDTO doGetOauthResource(Map<String, Object> oAuthResponseParam) throws Exception {
    // 获取资源请求构建者
    EcBaseResourceRequestBuilder resourceRequestBuilder = getResourceRequestBuilder();
    // 构建客户端请求参数
    OAuthClientRequest resourceRequest = resourceRequestBuilder.buildClientRequest(oAuthResponseParam);
    // 执行请求资源
    EcBaseOauthResourceResponse resourceResponse = oAuthClient.resource(resourceRequest, OAuth.HttpMethod.GET, resourceRequestBuilder.getResourceResponseClass());
    // 从资源响应对象中获取资源数据传输对象
    EcBaseOauthResourceDTO resourceDTO = resourceResponse.getResourceObj(resourceResponse.getResourceDTOClass());
    EcLogUtils.info("授权获取到的用户信息", resourceDTO, logger);
    return resourceDTO;
}
Also used : EcBaseOauthResourceResponse(com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse) EcBaseResourceRequestBuilder(com.easy.cloud.core.oauth.client.base.request.builder.EcBaseResourceRequestBuilder) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) EcBaseOauthResourceDTO(com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)

Example 3 with EcBaseOauthResourceDTO

use of com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO in project dq-easy-cloud by dq-open-cloud.

the class EcZfbOauthToken method doGetOauthResource.

@Override
public EcBaseOauthResourceDTO doGetOauthResource(Map<String, Object> oAuthResponseParam) throws Exception {
    AlipayUserInfoShareRequest userInfoShareRequest = new AlipayUserInfoShareRequest();
    String accessToken = EcMapUtils.getString(oAuthResponseParam, EcOauthAccessToken.ACCESS_TOKEN);
    AlipayUserInfoShareResponse shareResponse = alipayClient.execute(userInfoShareRequest, accessToken);
    EcAssert.verifyObjNull(shareResponse, "shareResponse");
    if (shareResponse != null && shareResponse.isSuccess()) {
        EcBaseOauthResourceResponse resourceResponse = EcBeanFactory.newInstance(getResourceRequestBuilder().getResourceResponseClass());
        EcBaseOauthResourceDTO resourceDTO = EcJSONUtils.parseObject(shareResponse, resourceResponse.getResourceDTOClass());
        EcLogUtils.info("授权获取到的用户信息", resourceDTO, logger);
        return resourceDTO;
    } else {
        throw new EcBaseBusinessException(shareResponse.getCode(), shareResponse.getMsg()).buildExceptionDetail(shareResponse);
    }
}
Also used : EcBaseOauthResourceResponse(com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse) AlipayUserInfoShareRequest(com.alipay.api.request.AlipayUserInfoShareRequest) AlipayUserInfoShareResponse(com.alipay.api.response.AlipayUserInfoShareResponse) EcBaseBusinessException(com.easy.cloud.core.exception.bo.EcBaseBusinessException) EcBaseOauthResourceDTO(com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)

Aggregations

EcBaseOauthResourceDTO (com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)3 EcBaseOauthResourceResponse (com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse)2 AlipayUserInfoShareRequest (com.alipay.api.request.AlipayUserInfoShareRequest)1 AlipayUserInfoShareResponse (com.alipay.api.response.AlipayUserInfoShareResponse)1 EcBaseBusinessException (com.easy.cloud.core.exception.bo.EcBaseBusinessException)1 EcBaseResourceRequestBuilder (com.easy.cloud.core.oauth.client.base.request.builder.EcBaseResourceRequestBuilder)1 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 Transactional (org.springframework.transaction.annotation.Transactional)1