Commit 45ec31fe authored by Quxl's avatar Quxl

x

parent 0d6622ec
......@@ -40,10 +40,28 @@ public interface OAuthApi {
}
default OAuthToken getOAuthToken() {
try {
HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession();
OAuthToken token = (OAuthToken)session.getAttribute(OAUTH_TOKEN_SESSION);
return token;
} catch (OAuthApiException e) {
throw e;
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
default void doOAuthLogin() {
try {
String redirectUrl = this.getOAuthPath();
HttpServletResponse response = this.getHttpServletResponse();
response.sendRedirect(redirectUrl);
} catch (OAuthApiException e) {
throw e;
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
default String getOAuthPath() {
......@@ -60,6 +78,8 @@ public interface OAuthApi {
redirectUrl = redirectUrl.replaceAll("\\+", "%20");
logger.debug("redirect:" + redirectUrl);
return redirectUrl;
} catch (OAuthApiException e) {
throw e;
} catch (Exception e) {
throw new OAuthApiException(e.getMessage(), e);
}
......@@ -93,16 +113,24 @@ public interface OAuthApi {
} else {
throw new OAuthApiException("OAuthToken already exists");
}
} catch (Exception e) {
} catch (OAuthApiException e) {
throw e;
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
default void doLogout() {
try {
HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession();
session.removeAttribute(OAUTH_TOKEN_SESSION);
session.invalidate();
} catch (OAuthApiException e) {
throw e;
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
default void refresh() {
......@@ -126,7 +154,9 @@ public interface OAuthApi {
String tokenType = oAuthResponse.getTokenType();
OAuthToken newToken = new OAuthToken(accessToken, refreshToken, idToken, tokenType, expiresIn);
session.setAttribute(OAUTH_TOKEN_SESSION, newToken);
} catch (Exception e) {
} catch (OAuthApiException e) {
throw e;
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
......@@ -154,10 +184,12 @@ public interface OAuthApi {
OAuthResourceResponse resourceResponse = oAuthClient.resource(clientRequest, "POST", OAuthResourceResponse.class);
String resBody = resourceResponse.getBody();
return resBody;
} catch (OAuthApiException e) {
throw e;
} catch (OAuthProblemException e) {
this.refresh();
return doPost(url, headers, data);
} catch (Exception e) {
} catch (Throwable e) {
throw new OAuthApiException(e.getMessage(), e);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment