mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-12-21 19:09:45 +08:00
sso,oauth2插件中调用配置类使用getter方法
This commit is contained in:
@@ -223,6 +223,13 @@ public class SaOAuth2Config implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 函数 OAuth-Server端:未登录时返回的View
|
||||
*/
|
||||
public Supplier<Object> getNotLoginView() {
|
||||
return notLoginView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param confirmView OAuth-Server端:确认授权时返回的View
|
||||
* @return 对象自身
|
||||
@@ -231,7 +238,14 @@ public class SaOAuth2Config implements Serializable {
|
||||
this.confirmView = confirmView;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 函数 OAuth-Server端:确认授权时返回的View
|
||||
*/
|
||||
public BiFunction<String, String, Object> getConfirmView() {
|
||||
return confirmView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param doLoginHandle OAuth-Server端:登录函数
|
||||
* @return 对象自身
|
||||
@@ -241,7 +255,13 @@ public class SaOAuth2Config implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 函数 OAuth-Server端:登录函数
|
||||
*/
|
||||
public BiFunction<String, String, Object> getDoLoginHandle() {
|
||||
return doLoginHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SaOAuth2Config [isCode=" + isCode + ", isImplicit=" + isImplicit + ", isPassword=" + isPassword
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SaOAuth2Handle {
|
||||
// 模式一:Code授权码
|
||||
if(req.isPath(Api.authorize) && req.isParam(Param.response_type, ResponseType.code)) {
|
||||
SaClientModel cm = currClientModel();
|
||||
if(cfg.isCode && (cm.isCode || cm.isAutoMode)) {
|
||||
if(cfg.getIsCode() && (cm.isCode || cm.isAutoMode)) {
|
||||
return authorize(req, res, cfg);
|
||||
}
|
||||
throw new SaOAuth2Exception("暂未开放的授权模式");
|
||||
@@ -75,7 +75,7 @@ public class SaOAuth2Handle {
|
||||
// 模式二:隐藏式
|
||||
if(req.isPath(Api.authorize) && req.isParam(Param.response_type, ResponseType.token)) {
|
||||
SaClientModel cm = currClientModel();
|
||||
if(cfg.isImplicit && (cm.isImplicit || cm.isAutoMode)) {
|
||||
if(cfg.getIsImplicit() && (cm.isImplicit || cm.isAutoMode)) {
|
||||
return authorize(req, res, cfg);
|
||||
}
|
||||
throw new SaOAuth2Exception("暂未开放的授权模式");
|
||||
@@ -84,7 +84,7 @@ public class SaOAuth2Handle {
|
||||
// 模式三:密码式
|
||||
if(req.isPath(Api.token) && req.isParam(Param.grant_type, GrantType.password)) {
|
||||
SaClientModel cm = currClientModel();
|
||||
if(cfg.isPassword && (cm.isPassword || cm.isAutoMode)) {
|
||||
if(cfg.getIsPassword() && (cm.isPassword || cm.isAutoMode)) {
|
||||
return password(req, res, cfg);
|
||||
}
|
||||
throw new SaOAuth2Exception("暂未开放的授权模式");
|
||||
@@ -93,7 +93,7 @@ public class SaOAuth2Handle {
|
||||
// 模式四:凭证式
|
||||
if(req.isPath(Api.client_token) && req.isParam(Param.grant_type, GrantType.client_credentials)) {
|
||||
SaClientModel cm = currClientModel();
|
||||
if(cfg.isClient && (cm.isClient || cm.isAutoMode)) {
|
||||
if(cfg.getIsClient() && (cm.isClient || cm.isAutoMode)) {
|
||||
return clientToken(req, res, cfg);
|
||||
}
|
||||
throw new SaOAuth2Exception("暂未开放的授权模式");
|
||||
@@ -114,7 +114,7 @@ public class SaOAuth2Handle {
|
||||
|
||||
// 1、如果尚未登录, 则先去登录
|
||||
if(StpUtil.isLogin() == false) {
|
||||
return cfg.notLoginView.get();
|
||||
return cfg.getNotLoginView().get();
|
||||
}
|
||||
|
||||
// 2、构建请求Model
|
||||
@@ -129,7 +129,7 @@ public class SaOAuth2Handle {
|
||||
// 5、判断:如果此次申请的Scope,该用户尚未授权,则转到授权页面
|
||||
boolean isGrant = SaOAuth2Util.isGrant(ra.loginId, ra.clientId, ra.scope);
|
||||
if(isGrant == false) {
|
||||
return cfg.confirmView.apply(ra.clientId, ra.scope);
|
||||
return cfg.getConfirmView().apply(ra.clientId, ra.scope);
|
||||
}
|
||||
|
||||
// 6、判断授权类型
|
||||
@@ -226,7 +226,7 @@ public class SaOAuth2Handle {
|
||||
* @return 处理结果
|
||||
*/
|
||||
public static Object doLogin(SaRequest req, SaResponse res, SaOAuth2Config cfg) {
|
||||
return cfg.doLoginHandle.apply(req.getParamNotNull(Param.name), req.getParamNotNull("pwd"));
|
||||
return cfg.getDoLoginHandle().apply(req.getParamNotNull(Param.name), req.getParamNotNull("pwd"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,7 +264,7 @@ public class SaOAuth2Handle {
|
||||
SaHolder.getStorage().set(StpUtil.stpLogic.splicingKeyJustCreatedSave(), "no-token");
|
||||
|
||||
// 4、调用API 开始登录,如果没能成功登录,则直接退出
|
||||
Object retObj = cfg.doLoginHandle.apply(username, password);
|
||||
Object retObj = cfg.getDoLoginHandle().apply(username, password);
|
||||
if(StpUtil.isLogin() == false) {
|
||||
return retObj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user