Commit 5b8f4703 authored by Quxl's avatar Quxl

x

parent 0b3c84af
package com.egolm.sso.oauth;
public class NoTokenException extends OAuthApiException {
private static final long serialVersionUID = 1L;
}
...@@ -339,19 +339,24 @@ public interface OAuthApi { ...@@ -339,19 +339,24 @@ public interface OAuthApi {
} }
/** /**
*
* 系统授权成功后,用户和通过此方法访问应用接口(因甲方未提供相关接口请求数据格式和鉴权设置等信息, 此处只按标准OAuth授权后的请求流程进行操作, 如有出入,用户可以根据实际情况, 重写或重载此方法) * 系统授权成功后,用户和通过此方法访问应用接口(因甲方未提供相关接口请求数据格式和鉴权设置等信息, 此处只按标准OAuth授权后的请求流程进行操作, 如有出入,用户可以根据实际情况, 重写或重载此方法)
* @param url 访问URL * @param url 访问URL
* @param headers HTTP头信息 * @param headers HTTP头信息
* @param data HTTP请求参数 * @param data HTTP请求参数
* @return HTTP请求响应结果 * @return HTTP请求响应结果
* @throws NoTokenException
*/ */
default String doPost(String url, Map<String, String> headers, JSONObject data) { default String doPost(String url, Map<String, String> headers, JSONObject data) throws NoTokenException {
try { try {
String jsonData = data == null ? "" : data.toString(); String jsonData = data == null ? "" : data.toString();
logger.debug("oauth post url: " + url); logger.debug("oauth post url: " + url);
logger.debug("oauth post headers: " + JSON.toJSONString(headers)); logger.debug("oauth post headers: " + JSON.toJSONString(headers));
logger.debug("oauth post data: " + jsonData); logger.debug("oauth post data: " + jsonData);
OAuthToken token = this.getOAuthToken(); OAuthToken token = this.getOAuthToken();
if(token == null) {
throw new NoTokenException();
}
if(System.currentTimeMillis() - token.getCreateMillis() > ((token.getExpiresIn()-5) * 60 * 1000)) { if(System.currentTimeMillis() - token.getCreateMillis() > ((token.getExpiresIn()-5) * 60 * 1000)) {
token = this.refreshOAuthToken(); token = this.refreshOAuthToken();
} }
......
...@@ -9,6 +9,10 @@ public class OAuthApiException extends RuntimeException { ...@@ -9,6 +9,10 @@ public class OAuthApiException extends RuntimeException {
private static final long serialVersionUID = 4300677142149830999L; private static final long serialVersionUID = 4300677142149830999L;
public OAuthApiException() {
super();
}
public OAuthApiException(String message) { public OAuthApiException(String message) {
super(message); super(message);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment