Commit 0d6622ec authored by Quxl's avatar Quxl

x

parent c0b2cc21
...@@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletRequest; ...@@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.oltu.oauth2.client.OAuthClient; import org.apache.oltu.oauth2.client.OAuthClient;
import org.apache.oltu.oauth2.client.URLConnectionClient; import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest; import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
...@@ -23,6 +25,8 @@ import com.alibaba.fastjson.JSONObject; ...@@ -23,6 +25,8 @@ import com.alibaba.fastjson.JSONObject;
public interface OAuthApi { public interface OAuthApi {
Log logger = LogFactory.getLog(OAuthApi.class);
OAuthConfig getOAuthConfig(); OAuthConfig getOAuthConfig();
HttpServletRequest getHttpServletRequest(); HttpServletRequest getHttpServletRequest();
...@@ -42,9 +46,8 @@ public interface OAuthApi { ...@@ -42,9 +46,8 @@ public interface OAuthApi {
return token; return token;
} }
default void toLogin() { default String getOAuthPath() {
try { try {
HttpServletResponse response = this.getHttpServletResponse();
OAuthConfig config = this.getOAuthConfig(); OAuthConfig config = this.getOAuthConfig();
AuthenticationRequestBuilder builder = OAuthClientRequest.authorizationLocation(config.getAuthorizeUrl()); AuthenticationRequestBuilder builder = OAuthClientRequest.authorizationLocation(config.getAuthorizeUrl());
builder.setResponseType(OAuth.OAUTH_CODE); builder.setResponseType(OAuth.OAUTH_CODE);
...@@ -55,14 +58,14 @@ public interface OAuthApi { ...@@ -55,14 +58,14 @@ public interface OAuthApi {
OAuthClientRequest oauthResponse = builder.buildQueryMessage(); OAuthClientRequest oauthResponse = builder.buildQueryMessage();
String redirectUrl = oauthResponse.getLocationUri(); String redirectUrl = oauthResponse.getLocationUri();
redirectUrl = redirectUrl.replaceAll("\\+", "%20"); redirectUrl = redirectUrl.replaceAll("\\+", "%20");
System.out.println("redirect:" + redirectUrl); logger.debug("redirect:" + redirectUrl);
response.sendRedirect(redirectUrl); return redirectUrl;
} catch (Exception e) { } catch (Exception e) {
throw new OAuthApiException(e.getMessage(), e); throw new OAuthApiException(e.getMessage(), e);
} }
} }
default void doLogin() { default void doOAuthCallback() {
try { try {
HttpServletRequest request = this.getHttpServletRequest(); HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession(); HttpSession session = request.getSession();
......
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