Commit d4b275f0 authored by Quxl's avatar Quxl

x

parent bf115406
...@@ -24,22 +24,57 @@ import org.apache.oltu.oauth2.common.message.types.GrantType; ...@@ -24,22 +24,57 @@ import org.apache.oltu.oauth2.common.message.types.GrantType;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
/**
*
* SSO 权限校验接口, 权限获取和业务接口调用已经全部封装在接口默认方法中, 使用者只需实现此接口并实现接口中的抽象方法即可.
* 需要实现的抽象方法如下:
* 1. getOAuthConfig 获取OAuth系统配置信息
* 2.getHttpServletRequest 获取HttpServletRequest对象, 用户获取Session保存OAuthToken信息, 也用于获取和解析授权后OAuth回调中的Token信息
* 3.getHttpServletResponse 获取HttpServletResponse对象, 用于直接重定向到OAuth授权页面, 如果业务不需要直接重定向, 也可以通过 getAuthorizationUrl 方法获取OAuth的授权地址, 由用户主动点击跳转到 OAuth授权页面
*
* @author Quxl
*
*/
public interface OAuthApi { public interface OAuthApi {
Log logger = LogFactory.getLog(OAuthApi.class); Log logger = LogFactory.getLog(OAuthApi.class);
/**
* 获取OAuth授权系统配置信息, 此方法需由用户自己实现
* @return OAuthConfig
*/
OAuthConfig getOAuthConfig(); OAuthConfig getOAuthConfig();
/**
* 获取HttpServletRequest
* @return HttpServletRequest
*/
HttpServletRequest getHttpServletRequest(); HttpServletRequest getHttpServletRequest();
/**
* 获取HttpServletResponse
* @return HttpServletResponse
*/
HttpServletResponse getHttpServletResponse(); HttpServletResponse getHttpServletResponse();
/**
* 用户存储在HttpSession中的OAuthToken的键, 通过此变量可在Session中存储或获取已存在的OAuthToken信息
*/
final String OAUTH_TOKEN_SESSION = "OAUTH2_TOKEN_SESSION_KEY"; final String OAUTH_TOKEN_SESSION = "OAUTH2_TOKEN_SESSION_KEY";
/**
* 判断OAuthToken是否已经存在, 或判断用户是否登陆
*
* @return true存在, false不存在
*/
default boolean isExistsOAuthToken() { default boolean isExistsOAuthToken() {
return getOAuthToken() != null; return getOAuthToken() != null;
} }
/**
* 获取存储在Session中的OAuthToken信息
* @return 如果存在则返回, 否则返回null
*/
default OAuthToken getOAuthToken() { default OAuthToken getOAuthToken() {
try { try {
HttpServletRequest request = this.getHttpServletRequest(); HttpServletRequest request = this.getHttpServletRequest();
...@@ -53,7 +88,10 @@ public interface OAuthApi { ...@@ -53,7 +88,10 @@ public interface OAuthApi {
} }
} }
default void doOAuthLogin() { /**
*
*/
default void doRedirectOAuthLogin() {
try { try {
String redirectUrl = this.getAuthorizationUrl(); String redirectUrl = this.getAuthorizationUrl();
HttpServletResponse response = this.getHttpServletResponse(); HttpServletResponse response = this.getHttpServletResponse();
......
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