diff --git a/CHANGELOGS.md b/CHANGELOGS.md index 935eed4..29b4b50 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -1,3 +1,7 @@ +## 1.0.7 + +- fix: Gitee Issue [#I4GV39](https://gitee.com/fujieid/jap/issues/I4GV39) + ## v1.0.6 (2021-11-02) - feat: 正式支持 LDAP 中用户的登录认证 diff --git a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java index a5902b2..24ec8f8 100644 --- a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java +++ b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java @@ -25,17 +25,27 @@ public enum Oauth2GrantType { /** * Authorization Code Grant */ - AUTHORIZATION_CODE, + AUTHORIZATION_CODE("authorization_code"), /** * Resource Owner Password Credentials Grant */ - PASSWORD, + PASSWORD("password"), /** * Client Credentials Grant */ - CLIENT_CREDENTIALS, + CLIENT_CREDENTIALS("client_credentials"), /** * Refreshing an Access Token */ - REFRESH_TOKEN + REFRESH_TOKEN("refresh_token"); + + private final String type; + + Oauth2GrantType(String type) { + this.type = type; + } + + public String getType() { + return type; + } } diff --git a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java index 5fb5610..9ce2173 100644 --- a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java +++ b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java @@ -25,13 +25,23 @@ public enum Oauth2ResponseType { /** * When authorization code mode or implicit authorization mode is not used, ResponseType needs to be set to {@code none} */ - NONE, + NONE("none"), /** * Authorization Code Grant */ - CODE, + CODE("code"), /** * Implicit Grant */ - TOKEN + TOKEN("token"); + + private final String type; + + Oauth2ResponseType(String type) { + this.type = type; + } + + public String getType() { + return type; + } } diff --git a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java index 4db2a11..925af3c 100644 --- a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java +++ b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java @@ -244,7 +244,7 @@ private String getAuthorizationUrl(OAuthConfig authConfig) { */ private String generateAuthorizationCodeGrantUrl(OAuthConfig authConfig) { Map params = new HashMap<>(6); - params.put("response_type", authConfig.getResponseType()); + params.put("response_type", authConfig.getResponseType().getType()); params.put("client_id", authConfig.getClientId()); if (StrUtil.isNotBlank(authConfig.getCallbackUrl())) { params.put("redirect_uri", authConfig.getCallbackUrl()); diff --git a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java index b9f1d83..2c9aff8 100644 --- a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java +++ b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java @@ -138,7 +138,7 @@ public static void checkOauthConfig(OAuthConfig oAuthConfig) { if (oAuthConfig.getResponseType() == Oauth2ResponseType.CODE) { if (oAuthConfig.getGrantType() != Oauth2GrantType.AUTHORIZATION_CODE) { - throw new JapOauth2Exception("Invalid grantType `" + oAuthConfig.getGrantType() + "`. " + + throw new JapOauth2Exception("Invalid grantType `" + oAuthConfig.getGrantType().getType() + "`. " + "When using authorization code mode, grantType must be `authorization_code`"); } @@ -168,7 +168,7 @@ public static void checkOauthConfig(OAuthConfig oAuthConfig) { else { if (oAuthConfig.getGrantType() != Oauth2GrantType.PASSWORD && oAuthConfig.getGrantType() != Oauth2GrantType.CLIENT_CREDENTIALS) { throw new JapOauth2Exception("When the response type is none in the oauth2 strategy, a grant type other " + - "than the authorization code must be used: " + oAuthConfig.getGrantType()); + "than the authorization code must be used: " + oAuthConfig.getGrantType().getType()); } if (oAuthConfig.getGrantType() == Oauth2GrantType.PASSWORD) { if (!StrUtil.isAllNotEmpty(oAuthConfig.getUsername(), oAuthConfig.getPassword())) { diff --git a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java index 651ee26..ef5e281 100644 --- a/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java +++ b/jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java @@ -90,7 +90,7 @@ private static AccessToken getAccessTokenOfAuthorizationCodeMode(JapHttpRequest String code = request.getParameter("code"); Map params = new HashMap<>(6); - params.put("grant_type", Oauth2GrantType.AUTHORIZATION_CODE.name()); + params.put("grant_type", Oauth2GrantType.AUTHORIZATION_CODE.getType()); params.put("code", code); params.put("client_id", oAuthConfig.getClientId()); params.put("client_secret", oAuthConfig.getClientSecret()); @@ -148,7 +148,7 @@ private static AccessToken getAccessTokenOfImplicitMode(JapHttpRequest request) */ private static AccessToken getAccessTokenOfPasswordMode(OAuthConfig oAuthConfig) throws JapOauth2Exception { Map params = new HashMap<>(6); - params.put("grant_type", Oauth2GrantType.PASSWORD.name()); + params.put("grant_type", Oauth2GrantType.PASSWORD.getType()); params.put("username", oAuthConfig.getUsername()); params.put("password", oAuthConfig.getPassword()); params.put("client_id", oAuthConfig.getClientId()); @@ -175,7 +175,7 @@ private static AccessToken getAccessTokenOfPasswordMode(OAuthConfig oAuthConfig) private static AccessToken getAccessTokenOfClientMode(JapHttpRequest request, OAuthConfig oAuthConfig) throws JapOauth2Exception { throw new JapOauth2Exception("Oauth2Strategy failed to get AccessToken. Grant type of client_credentials type is not supported."); // Map params = Maps.newHashMap(); -// params.put("grant_type", Oauth2GrantType.client_credentials.name()); +// params.put("grant_type", Oauth2GrantType.CLIENT_CREDENTIALS.getType()); // if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) { // params.put("scope", String.join(Oauth2Const.SCOPE_SEPARATOR, oAuthConfig.getScopes())); // } @@ -192,7 +192,7 @@ private static AccessToken getAccessTokenOfClientMode(JapHttpRequest request, OA private static AccessToken refreshToken(OAuthConfig oAuthConfig, String refreshToken) { Map params = new HashMap<>(6); - params.put("grant_type", oAuthConfig.getGrantType().name()); + params.put("grant_type", oAuthConfig.getGrantType().getType()); params.put("refresh_token", refreshToken); if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) { diff --git a/pom.xml b/pom.xml index 06583b4..240015f 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ - 1.0.6 + 1.0.7 1.8 UTF-8