OAuth: Simplify protocol implementation
Change-Id: Ia713593c57d9f68f6fcac8ff3978428052aee5fb
This commit is contained in:
@@ -86,10 +86,6 @@ class OAuthSession {
|
||||
|
||||
boolean login(HttpServletRequest request, HttpServletResponse response,
|
||||
OAuthServiceProvider oauth) throws IOException {
|
||||
if (isLoggedIn()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
log.debug("Login " + this);
|
||||
|
||||
if (isOAuthFinal(request)) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.httpd.HtmlDomUtil;
|
||||
import com.google.gerrit.httpd.LoginUrlToken;
|
||||
import com.google.gerrit.httpd.template.SiteHeaderFooter;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -48,7 +47,6 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@Singleton
|
||||
/* OAuth web filter uses active OAuth session to perform OAuth requests */
|
||||
@@ -56,7 +54,6 @@ class OAuthWebFilter implements Filter {
|
||||
static final String GERRIT_LOGIN = "/login";
|
||||
|
||||
private final Provider<String> urlProvider;
|
||||
private final Provider<CurrentUser> currentUserProvider;
|
||||
private final Provider<OAuthSession> oauthSessionProvider;
|
||||
private final DynamicMap<OAuthServiceProvider> oauthServiceProviders;
|
||||
private final SiteHeaderFooter header;
|
||||
@@ -64,12 +61,10 @@ class OAuthWebFilter implements Filter {
|
||||
|
||||
@Inject
|
||||
OAuthWebFilter(@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||
Provider<CurrentUser> currentUserProvider,
|
||||
DynamicMap<OAuthServiceProvider> oauthServiceProviders,
|
||||
Provider<OAuthSession> oauthSessionProvider,
|
||||
SiteHeaderFooter header) {
|
||||
this.urlProvider = urlProvider;
|
||||
this.currentUserProvider = currentUserProvider;
|
||||
this.oauthServiceProviders = oauthServiceProviders;
|
||||
this.oauthSessionProvider = oauthSessionProvider;
|
||||
this.header = header;
|
||||
@@ -88,35 +83,20 @@ class OAuthWebFilter implements Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
HttpSession httpSession = ((HttpServletRequest) request).getSession(false);
|
||||
OAuthSession oauthSession = oauthSessionProvider.get();
|
||||
boolean link = request.getParameter("link") != null;
|
||||
if (link) {
|
||||
oauthSession.setLinkMode(link);
|
||||
}
|
||||
if (!oauthSession.isLinkMode()
|
||||
&& currentUserProvider.get().isIdentifiedUser()) {
|
||||
if (httpSession != null) {
|
||||
httpSession.invalidate();
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
} else {
|
||||
if (oauthSession.isLoggedIn()) {
|
||||
oauthSession.logout();
|
||||
}
|
||||
}
|
||||
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
|
||||
OAuthSession oauthSession = oauthSessionProvider.get();
|
||||
if (request.getParameter("link") != null) {
|
||||
oauthSession.setLinkMode(true);
|
||||
oauthSession.setServiceProvider(null);
|
||||
}
|
||||
|
||||
String provider = httpRequest.getParameter("provider");
|
||||
OAuthServiceProvider service = ssoProvider == null
|
||||
? oauthSession.getServiceProvider()
|
||||
: ssoProvider;
|
||||
|
||||
if ((isGerritLogin(httpRequest)
|
||||
|| oauthSession.isOAuthFinal(httpRequest))
|
||||
&& !oauthSession.isLoggedIn()) {
|
||||
if (isGerritLogin(httpRequest) || oauthSession.isOAuthFinal(httpRequest)) {
|
||||
if (service == null && Strings.isNullOrEmpty(provider)) {
|
||||
selectProvider(httpRequest, httpResponse, null);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user