mirror of
https://gitee.com/fujieid/jap.git
synced 2024-11-29 18:17:34 +08:00
Merge branch 'dev'
This commit is contained in:
commit
4285eb50aa
@ -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 中用户的登录认证
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class Oauth2Strategy extends AbstractJapStrategy {
|
||||
*/
|
||||
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());
|
||||
|
@ -138,7 +138,7 @@ public class Oauth2Util {
|
||||
|
||||
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 class Oauth2Util {
|
||||
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())) {
|
||||
|
@ -90,7 +90,7 @@ public class AccessTokenHelper {
|
||||
|
||||
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());
|
||||
@ -148,7 +148,7 @@ public class AccessTokenHelper {
|
||||
*/
|
||||
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());
|
||||
@ -175,7 +175,7 @@ public class AccessTokenHelper {
|
||||
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()));
|
||||
// }
|
||||
@ -192,7 +192,7 @@ public class AccessTokenHelper {
|
||||
|
||||
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())) {
|
||||
|
Loading…
Reference in New Issue
Block a user