From 8b44c8ff7a8eecfbba703554dcd7e4b234171f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=A2=A6=E6=8A=80=E6=9C=AF?= <596392912@qq.com> Date: Wed, 28 Apr 2021 11:46:18 +0800 Subject: [PATCH] :sparkles: Code optimization for easy initialization as a Spring bean. --- .../java/com/fujieid/jap/ids/endpoint/AbstractEndpoint.java | 5 +---- .../java/com/fujieid/jap/ids/endpoint/ApprovalEndpoint.java | 3 --- .../com/fujieid/jap/ids/endpoint/AuthorizationEndpoint.java | 2 +- .../java/com/fujieid/jap/ids/endpoint/LoginEndpoint.java | 2 ++ .../java/com/fujieid/jap/ids/endpoint/LogoutEndpoint.java | 3 +-- .../java/com/fujieid/jap/ids/endpoint/TokenEndpoint.java | 2 -- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AbstractEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AbstractEndpoint.java index d85d362..64a5d34 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AbstractEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AbstractEndpoint.java @@ -15,8 +15,6 @@ */ package com.fujieid.jap.ids.endpoint; -import com.fujieid.jap.ids.JapIds; -import com.fujieid.jap.ids.config.IdsConfig; import com.fujieid.jap.ids.service.Oauth2Service; import com.fujieid.jap.ids.service.Oauth2ServiceImpl; @@ -29,10 +27,9 @@ import com.fujieid.jap.ids.service.Oauth2ServiceImpl; */ public abstract class AbstractEndpoint { protected final Oauth2Service oauth2Service; - protected IdsConfig idsConfig; public AbstractEndpoint() { - this.idsConfig = JapIds.getIdsConfig(); this.oauth2Service = new Oauth2ServiceImpl(); } + } diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/ApprovalEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/ApprovalEndpoint.java index 466123f..34c8ab3 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/ApprovalEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/ApprovalEndpoint.java @@ -16,17 +16,14 @@ package com.fujieid.jap.ids.endpoint; import com.fujieid.jap.ids.JapIds; -import com.fujieid.jap.ids.exception.InvalidClientException; import com.fujieid.jap.ids.model.ClientDetail; import com.fujieid.jap.ids.model.IdsRequestParam; import com.fujieid.jap.ids.model.IdsResponse; import com.fujieid.jap.ids.model.IdsScope; -import com.fujieid.jap.ids.model.enums.ErrorResponse; import com.fujieid.jap.ids.provider.IdsRequestParamProvider; import com.fujieid.jap.ids.provider.IdsScopeProvider; import com.fujieid.jap.ids.util.OauthUtil; import com.fujieid.jap.ids.util.ObjectUtils; -import com.xkcoding.json.util.StringUtil; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AuthorizationEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AuthorizationEndpoint.java index 0e6b477..1bc28a0 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AuthorizationEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/AuthorizationEndpoint.java @@ -75,7 +75,7 @@ public class AuthorizationEndpoint extends AbstractEndpoint { } return new IdsResponse() - .data(OauthUtil.createAuthorizeUrl(idsConfig.getLoginUrl(), param)); + .data(OauthUtil.createAuthorizeUrl(JapIds.getIdsConfig().getLoginUrl(), param)); } /** diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LoginEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LoginEndpoint.java index e05a058..fb656aa 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LoginEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LoginEndpoint.java @@ -17,6 +17,7 @@ package com.fujieid.jap.ids.endpoint; import cn.hutool.core.util.ObjectUtil; import com.fujieid.jap.ids.JapIds; +import com.fujieid.jap.ids.config.IdsConfig; import com.fujieid.jap.ids.exception.IdsException; import com.fujieid.jap.ids.model.IdsResponse; import com.fujieid.jap.ids.model.UserInfo; @@ -93,6 +94,7 @@ public class LoginEndpoint extends AbstractEndpoint { * @return Confirm authorization page */ public IdsResponse signin(HttpServletRequest request) { + IdsConfig idsConfig = JapIds.getIdsConfig(); String username = request.getParameter(idsConfig.getUsernameField()); String password = request.getParameter(idsConfig.getPasswordField()); if (ObjectUtil.hasEmpty(username, password)) { diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LogoutEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LogoutEndpoint.java index 3898cd5..81d1be4 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LogoutEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/LogoutEndpoint.java @@ -17,7 +17,6 @@ package com.fujieid.jap.ids.endpoint; import com.fujieid.jap.ids.JapIds; import com.fujieid.jap.ids.model.IdsResponse; -import com.fujieid.jap.ids.util.TokenUtil; import javax.servlet.http.HttpServletRequest; @@ -34,6 +33,6 @@ public class LogoutEndpoint extends AbstractEndpoint { JapIds.removeUserInfo(request); request.getSession().invalidate(); return new IdsResponse() - .data(idsConfig.getLogoutRedirectUrl()); + .data(JapIds.getIdsConfig().getLogoutRedirectUrl()); } } diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/TokenEndpoint.java b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/TokenEndpoint.java index e4995a9..80ef8fa 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/TokenEndpoint.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/endpoint/TokenEndpoint.java @@ -15,7 +15,6 @@ */ package com.fujieid.jap.ids.endpoint; -import com.fujieid.jap.ids.JapIds; import com.fujieid.jap.ids.exception.UnsupportedGrantTypeException; import com.fujieid.jap.ids.model.IdsRequestParam; import com.fujieid.jap.ids.model.IdsResponse; @@ -23,7 +22,6 @@ import com.fujieid.jap.ids.model.enums.ErrorResponse; import com.fujieid.jap.ids.model.enums.GrantType; import com.fujieid.jap.ids.provider.IdsRequestParamProvider; import com.fujieid.jap.ids.provider.IdsTokenProvider; -import com.fujieid.jap.ids.util.JwtUtil; import com.fujieid.jap.ids.util.TokenUtil; import com.xkcoding.json.util.StringUtil; -- Gitee