提交 93c407e5 编写于 作者: 智布道's avatar 智布道 👁

🎨 Improving code

上级 d4908216
......@@ -17,6 +17,7 @@ package com.fujieid.jap.core.cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.StrUtil;
import java.io.Serializable;
......@@ -62,6 +63,9 @@ public class JapLocalCache implements JapCache {
*/
@Override
public Serializable get(String key) {
if (StrUtil.isEmpty(key)) {
return null;
}
return LOCAL_CACHE.get(key);
}
......
......@@ -91,6 +91,10 @@ public class Oauth2Util {
if (!verifyState) {
return;
}
if (StrUtil.isEmpty(state) || StrUtil.isEmpty(clientId)) {
throw new JapOauth2Exception("Illegal state.");
}
Serializable cacheState = JapCacheContextHolder.getCache().get(Oauth2Const.STATE_CACHE_KEY.concat(clientId));
if (null == cacheState || !cacheState.equals(state)) {
throw new JapOauth2Exception("Illegal state.");
......
......@@ -33,6 +33,9 @@ import java.util.Optional;
*/
public class PkceHelper {
private PkceHelper() {
}
/**
* Create the parameters required by PKCE
*
......
......@@ -41,6 +41,9 @@ import java.util.Map;
*/
public class AccessTokenHelper {
private AccessTokenHelper() {
}
/**
* get access_token
*
......@@ -49,6 +52,9 @@ public class AccessTokenHelper {
* @return AccessToken
*/
public static AccessToken getToken(HttpServletRequest request, OAuthConfig oAuthConfig) {
if(null == oAuthConfig) {
throw new JapOauth2Exception("Oauth2Strategy failed to get AccessToken. OAuthConfig cannot be empty");
}
if (oAuthConfig.getResponseType() == Oauth2ResponseType.code) {
return getAccessTokenOfAuthorizationCodeMode(request, oAuthConfig);
}
......@@ -61,7 +67,7 @@ public class AccessTokenHelper {
if (oAuthConfig.getGrantType() == Oauth2GrantType.client_credentials) {
return getAccessTokenOfClientMode(request, oAuthConfig);
}
throw new JapOauth2Exception("Oauth2Strategy failed to get AccessToken.");
throw new JapOauth2Exception("Oauth2Strategy failed to get AccessToken. Missing required parameters");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册