Skip to content

Commit

Permalink
refactor: variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cdk8s-zelda committed Nov 13, 2019
1 parent ef214fa commit 495ec2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,25 @@ public String authorize(final HttpServletRequest request, ModelMap model, OauthA

String userInfoRedisKey = oauthCheckParamService.checkCookieTgc(request.getHeader(GlobalVariable.HTTP_HEADER_USER_AGENT), IPUtil.getIp(request), tgcCookieValue);

String redirectUrl;
String finalRedirectUrl;
String redirectUri = oAuthAuthorizeParam.getRedirectUri();
if (StringUtil.equalsIgnoreCase(oAuthAuthorizeParam.getResponseType(), GlobalVariable.OAUTH_TOKEN_RESPONSE_TYPE)) {
// 简化模式
OauthUserInfoToRedisBO oauthUserInfoToRedisBO = userInfoRedisService.get(userInfoRedisKey);

OauthToken oauthTokenInfoByCodePO = oauthGenerateService.generateOauthTokenInfoBO(true);
oauthSaveService.saveAccessToken(oauthTokenInfoByCodePO.getAccessToken(), oauthUserInfoToRedisBO.getUserAttribute(), oAuthAuthorizeParam.getClientId(), GlobalVariable.OAUTH_TOKEN_GRANT_TYPE);
oauthSaveService.saveRefreshToken(oauthTokenInfoByCodePO.getRefreshToken(), oauthUserInfoToRedisBO.getUserAttribute(), oAuthAuthorizeParam.getClientId(), GlobalVariable.OAUTH_TOKEN_GRANT_TYPE);
redirectUrl = getRedirectUrlWithAccessToken(oAuthAuthorizeParam.getRedirectUri(), oauthTokenInfoByCodePO);
finalRedirectUrl = getRedirectUrlWithAccessToken(redirectUri, oauthTokenInfoByCodePO);
} else {
// 授权码模式
String code = oauthGenerateService.generateCode();
oauthSaveService.saveCodeToRedis(code, tgcCookieValue, userInfoRedisKey, oAuthAuthorizeParam.getClientId());
redirectUrl = getRedirectUrlWithCode(oAuthAuthorizeParam.getRedirectUri(), oAuthAuthorizeParam.getState(), code);
finalRedirectUrl = getRedirectUrlWithCode(redirectUri, oAuthAuthorizeParam.getState(), code);
}

oauthSaveService.updateTgcAndUserInfoRedisKeyExpire(tgcCookieValue, userInfoRedisKey);
return GlobalVariable.REDIRECT_URI_PREFIX + redirectUrl;
return GlobalVariable.REDIRECT_URI_PREFIX + finalRedirectUrl;
}

/**
Expand Down Expand Up @@ -150,21 +151,22 @@ public String formLogin(final HttpServletRequest request, final HttpServletRespo

oauthSaveService.saveTgcToRedisAndCookie(tgc, maxTimeToLiveInSeconds, userInfoRedisKey, userAgent, requestIp, isRememberMe);

String redirectUrl;
String finalRedirectUrl;
String redirectUri = oauthFormLoginParam.getRedirectUri();
if (StringUtil.equalsIgnoreCase(oauthFormLoginParam.getResponseType(), GlobalVariable.OAUTH_TOKEN_RESPONSE_TYPE)) {
// 简化模式
OauthToken oauthToken = oauthGenerateService.generateOauthTokenInfoBO(true);
oauthSaveService.saveAccessToken(oauthToken.getAccessToken(), oauthUserAttribute, oauthFormLoginParam.getClientId(), GlobalVariable.OAUTH_TOKEN_GRANT_TYPE);
oauthSaveService.saveRefreshToken(oauthToken.getRefreshToken(), oauthUserAttribute, oauthFormLoginParam.getClientId(), GlobalVariable.OAUTH_TOKEN_GRANT_TYPE);
redirectUrl = getRedirectUrlWithAccessToken(oauthFormLoginParam.getRedirectUri(), oauthToken);
finalRedirectUrl = getRedirectUrlWithAccessToken(redirectUri, oauthToken);
} else {
// 授权码模式
String code = oauthGenerateService.generateCode();
oauthSaveService.saveCodeToRedis(code, tgc, userInfoRedisKey, oauthFormLoginParam.getClientId());
redirectUrl = getRedirectUrlWithCode(oauthFormLoginParam.getRedirectUri(), oauthFormLoginParam.getState(), code);
finalRedirectUrl = getRedirectUrlWithCode(redirectUri, oauthFormLoginParam.getState(), code);
}

return GlobalVariable.REDIRECT_URI_PREFIX + redirectUrl;
return GlobalVariable.REDIRECT_URI_PREFIX + finalRedirectUrl;

}

Expand Down Expand Up @@ -352,7 +354,7 @@ private void resolveRequestHeader(HttpServletRequest request, OauthClientParam o
String replaceIgnoreCase = StringUtil.replaceIgnoreCase(authorizationHeader, GlobalVariable.BASIC_AUTH_UPPER_PREFIX, GlobalVariable.BASIC_AUTH_LOWER_PREFIX);
authorizationHeader = StringUtil.substringAfter(replaceIgnoreCase, GlobalVariable.BASIC_AUTH_LOWER_PREFIX);
}
String basic = CodecUtil.base64ToString(authorizationHeader);
String basic = CodecUtil.base64DecodeBySafe(authorizationHeader);
List<String> stringList = StringUtil.split(basic, ":");
if (stringList.size() < 2) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cdk8s/tkey/server/util/CodecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Slf4j
public final class CodecUtil {

public static String base64ToString(final String base64String) {
public static String base64DecodeBySafe(final String base64String) {
return new String(Base64.decodeBase64(base64String));
}

Expand Down

0 comments on commit 495ec2b

Please sign in to comment.