Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Nov 29, 2021
2 parents 0a565b0 + cba56a0 commit 4285eb5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOGS.md
Original file line number Diff line number Diff line change
@@ -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 中用户的登录认证
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private String getAuthorizationUrl(OAuthConfig authConfig) {
*/
private String generateAuthorizationCodeGrantUrl(OAuthConfig authConfig) {
Map<String, Object> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`");
}

Expand Down Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static AccessToken getAccessTokenOfAuthorizationCodeMode(JapHttpRequest

String code = request.getParameter("code");
Map<String, String> 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());
Expand Down Expand Up @@ -148,7 +148,7 @@ private static AccessToken getAccessTokenOfImplicitMode(JapHttpRequest request)
*/
private static AccessToken getAccessTokenOfPasswordMode(OAuthConfig oAuthConfig) throws JapOauth2Exception {
Map<String, String> 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());
Expand All @@ -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<String, String> 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()));
// }
Expand All @@ -192,7 +192,7 @@ private static AccessToken getAccessTokenOfClientMode(JapHttpRequest request, OA

private static AccessToken refreshToken(OAuthConfig oAuthConfig, String refreshToken) {
Map<String, String> 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())) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<properties>
<!-- jap version -->
<revision>1.0.6</revision>
<revision>1.0.7</revision>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- maven -->
Expand Down

0 comments on commit 4285eb5

Please sign in to comment.