Commit 4aab0770 authored by Quxl's avatar Quxl

x

parent bdbb231c
...@@ -2,10 +2,18 @@ package com.egolm.sso.oauth; ...@@ -2,10 +2,18 @@ package com.egolm.sso.oauth;
import java.io.Serializable; import java.io.Serializable;
import org.apache.axis.encoding.Base64; /**
* 例如: <pre>{
import com.alibaba.fastjson.JSON; "access_token": "0a379729-4c5b-45b9-a598-eed9cedfecd8",
"refresh_token": "784d4e94-efa2-4a64-94ad-942ef18db3c1",
"scope": "openid profile",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdF9oYXNoIjoiczBtRHJvLUxBQXRLMnFDRWdtSWM3dyIsIkVtYWlsIjoicGFydGhhc2FyYXRoaS5wYWxAbWFpbGluYXRvci5jb20iLCJpbmR1c3RyeVNlZ21lbnQiOiJJRDUiLCJwb3N0YWxDb2RlIjoiNDM0NDIiLCJjb21wYW55U3RhdGUiOiJBSCIsImlzcyI6Imh0dHBzOi8vaWRlbnRpdHktc3RnLnNjaG5laWRlci1lbGVjdHJpYy5jb206NDQzL2FjY2Vzc21hbmFnZXIvb2F1dGgyL3NlIiwiY291bnR5IjoiSW5kaWEiLCJjb21wYW55U3RyZWV0IjoiamIiLCJjdXN0b21fYXR0cmlidXRlcyI6eyJlbWFpbCI6InBhcnRoYXNhcmF0aGkucGFsQG1haWxpbmF0b3IuY29tIiwiRW1haWwiOiJwYXJ0aGFzYXJhdGhpLnBhbEBtYWlsaW5hdG9yLmNvbSIsIkNvdW50cnkiOiJDTiIsImZlZGVyYXRlZElkIjoiY24wMFpPanctZTJjZS1HNW44LTZ0U3EtWVdiOUIyMW1NbkFWIiwiRmlyc3ROYW1lIjoicGFydGhhc2FyYXRoaSIsImZpcnN0TmFtZSI6InBhcnRoYXNhcmF0aGkiLCJsYXN0TmFtZSI6InBhbCIsIkxhc3ROYW1lIjoicGFsIiwiY2xhc3NMZXZlbDEiOiJFVSIsImNsYXNzTGV2ZWwyIjpudWxsfSwicmVnaXN0ZXJ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* @author Quxl
*
*/
public class OAuthToken implements Serializable { public class OAuthToken implements Serializable {
private static final long serialVersionUID = -73234152183180980L; private static final long serialVersionUID = -73234152183180980L;
...@@ -31,12 +39,23 @@ public class OAuthToken implements Serializable { ...@@ -31,12 +39,23 @@ public class OAuthToken implements Serializable {
private String tokenType; private String tokenType;
/** /**
* 过期时间 * 过期时间(秒?)
*/ */
private Long expiresIn; private Long expiresIn;
/**
* Token创建时间(毫秒)
*/
private Long createMillis; private Long createMillis;
/**
* 构造函数
* @param accessToken access_token
* @param refreshToken refresh_token
* @param idToken id_token
* @param tokenType token_type
* @param expiresIn expires_in
*/
public OAuthToken(String accessToken, String refreshToken, String idToken, String tokenType, Long expiresIn) { public OAuthToken(String accessToken, String refreshToken, String idToken, String tokenType, Long expiresIn) {
this.accessToken = accessToken; this.accessToken = accessToken;
this.refreshToken = refreshToken; this.refreshToken = refreshToken;
...@@ -74,13 +93,4 @@ public class OAuthToken implements Serializable { ...@@ -74,13 +93,4 @@ public class OAuthToken implements Serializable {
return createMillis; return createMillis;
} }
public static void main(String[] args) {
String str = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdF9oYXNoIjoiczBtRHJvLUxBQXRLMnFDRWdtSWM3dyIsIkVtYWlsIjoicGFydGhhc2FyYXRoaS5wYWxAbWFpbGluYXRvci5jb20iLCJpbmR1c3RyeVNlZ21lbnQiOiJJRDUiLCJwb3N0YWxDb2RlIjoiNDM0NDIiLCJjb21wYW55U3RhdGUiOiJBSCIsImlzcyI6Imh0dHBzOi8vaWRlbnRpdHktc3RnLnNjaG5laWRlci1lbGVjdHJpYy5jb206NDQzL2FjY2Vzc21hbmFnZXIvb2F1dGgyL3NlIiwiY291bnR5IjoiSW5kaWEiLCJjb21wYW55U3RyZWV0IjoiamIiLCJjdXN0b21fYXR0cmlidXRlcyI6eyJlbWFpbCI6InBhcnRoYXNhcmF0aGkucGFsQG1haWxpbmF0b3IuY29tIiwiRW1haWwiOiJwYXJ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dXRvbWF0aW9uSG9tZSxBcHAiLCJlbXBsb3llZVR5cGUiOiJAV29yayIsInVwZGF0ZVNvdXJjZSI6IlVpbXMiLCJmZWRlcmF0ZWRJZCI6ImNuMDBaT2p3LWUyY2UtRzVuOC02dFNxLVlXYjlCMjFtTW5BViIsInJlYWxtIjoiL3NlIiwiaW5ldFVzZXJTdGF0dXMiOiJBY3RpdmUiLCJmYW1pbHlfbmFtZSI6InBhbCJ9.yly0EYywEjkVtXwrrlH8_dZ62YqFDxoEjX5uGpbg8C4";
String[] strs = str.split("\\.");
System.out.println(JSON.parseObject(new String(Base64.decode(strs[0]))));
System.out.println(JSON.parseObject(new String(Base64.decode(strs[1]))));
System.out.println(strs[2]);
}
} }
...@@ -5,6 +5,12 @@ import java.net.URLEncoder; ...@@ -5,6 +5,12 @@ import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
/**
* HTTP URL 构造器
* 用于组装构造HTTP完整链接
* @author Quxl
*
*/
public class UrlBuilder { public class UrlBuilder {
private String url; private String url;
...@@ -15,20 +21,41 @@ public class UrlBuilder { ...@@ -15,20 +21,41 @@ public class UrlBuilder {
this.url = url; this.url = url;
} }
/**
* 设置参数
* @param key 参数名
* @param value 参数值
* @return
*/
public UrlBuilder setParameter(String key, String value) { public UrlBuilder setParameter(String key, String value) {
parameters.put(key, value); parameters.put(key, value);
return this; return this;
} }
/**
* 设置头信息
* @param key 参数名
* @param value 参数值
* @return
*/
public UrlBuilder setHeader(String key, String value) { public UrlBuilder setHeader(String key, String value) {
headers.put(key, value); headers.put(key, value);
return this; return this;
} }
/**
* 获取全部头信息
* @return
*/
public Map<String, String> getHeaders() { public Map<String, String> getHeaders() {
return headers; return headers;
} }
/**
* 转为HTTP链接(URL已编码)
* @return
* @throws UnsupportedEncodingException
*/
public String toEncodeUrlString() throws UnsupportedEncodingException { public String toEncodeUrlString() throws UnsupportedEncodingException {
StringBuffer sb = new StringBuffer(url); StringBuffer sb = new StringBuffer(url);
if (!url.contains("?")) { if (!url.contains("?")) {
...@@ -51,6 +78,10 @@ public class UrlBuilder { ...@@ -51,6 +78,10 @@ public class UrlBuilder {
return urlString; return urlString;
} }
/**
* 转为HTTP链接(URL未编码)
* @return
*/
public String toUrlString() { public String toUrlString() {
StringBuffer sb = new StringBuffer(url); StringBuffer sb = new StringBuffer(url);
if (!url.contains("?")) { if (!url.contains("?")) {
......
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