📝 change: Optimize code

This commit is contained in:
yadong.zhang 2021-09-20 20:08:44 +08:00
parent 2c623eaeca
commit c2dad67d5d
2 changed files with 15 additions and 7 deletions

View File

@ -22,6 +22,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.fujieid.jap.core.context.JapAuthentication; import com.fujieid.jap.core.context.JapAuthentication;
import com.fujieid.jap.core.exception.JapOauth2Exception; import com.fujieid.jap.core.exception.JapOauth2Exception;
import com.fujieid.jap.core.exception.OidcException;
import com.fujieid.jap.http.JapHttpRequest; import com.fujieid.jap.http.JapHttpRequest;
import com.fujieid.jap.oauth2.pkce.PkceCodeChallengeMethod; import com.fujieid.jap.oauth2.pkce.PkceCodeChallengeMethod;
import com.xkcoding.http.HttpUtil; import com.xkcoding.http.HttpUtil;
@ -215,9 +216,17 @@ public class Oauth2Util {
SimpleHttpResponse res = null; SimpleHttpResponse res = null;
if (null == endpointMethodType || Oauth2EndpointMethodType.GET == endpointMethodType) { if (null == endpointMethodType || Oauth2EndpointMethodType.GET == endpointMethodType) {
res = HttpUtil.get(url, params, false).getBody(); res = HttpUtil.get(url, params, false);
} else { } else {
res = HttpUtil.post(url, params, false).getBody(); res = HttpUtil.post(url, params, false);
}
if (!res.isSuccess()) {
throw new OidcException("Cannot access url: " + url
+ " , method: " + endpointMethodType
+ " , params: " + params
+ " , error details: " + res.getError()
);
} }
return JsonUtil.parseKv(res.getBody()); return JsonUtil.parseKv(res.getBody());
} }

View File

@ -44,12 +44,11 @@ public class OidcUtil {
} }
String discoveryUrl = issuer.concat(DISCOVERY_URL); String discoveryUrl = issuer.concat(DISCOVERY_URL);
SimpleHttpResponse response = null; SimpleHttpResponse response = HttpUtil.get(discoveryUrl);
try { if(!response.isSuccess()) {
response = HttpUtil.get(discoveryUrl).getBody(); throw new OidcException("Cannot access discovery url: " + discoveryUrl + ", " + response.getError());
} catch (Exception e) {
throw new OidcException("Cannot access discovery url: " + discoveryUrl);
} }
Kv oidcDiscoveryInfo = JsonUtil.parseKv(response.getBody()); Kv oidcDiscoveryInfo = JsonUtil.parseKv(response.getBody());
if (CollectionUtil.isEmpty(oidcDiscoveryInfo)) { if (CollectionUtil.isEmpty(oidcDiscoveryInfo)) {
throw new OidcException("Unable to parse IDP service discovery configuration information."); throw new OidcException("Unable to parse IDP service discovery configuration information.");