当前位置: 首页>>代码示例>>Java>>正文


Java OAuthServiceProvider类代码示例

本文整理汇总了Java中com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider的典型用法代码示例。如果您正苦于以下问题:Java OAuthServiceProvider类的具体用法?Java OAuthServiceProvider怎么用?Java OAuthServiceProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OAuthServiceProvider类属于com.google.gerrit.extensions.auth.oauth包,在下文中一共展示了OAuthServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilter

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  HttpServletResponse httpResponse = (HttpServletResponse) response;

  OAuthSessionOverOpenID oauthSession = oauthSessionProvider.get();
  OAuthServiceProvider service =
      ssoProvider == null ? oauthSession.getServiceProvider() : ssoProvider;

  if (isGerritLogin(httpRequest) || oauthSession.isOAuthFinal(httpRequest)) {
    if (service == null) {
      throw new IllegalStateException("service is unknown");
    }
    oauthSession.setServiceProvider(service);
    oauthSession.login(httpRequest, httpResponse, service);
  } else {
    chain.doFilter(httpRequest, response);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:OAuthWebFilterOverOpenID.java

示例2: login

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
boolean login(
    HttpServletRequest request, HttpServletResponse response, OAuthServiceProvider oauth)
    throws IOException {
  log.debug("Login " + this);

  if (isOAuthFinal(request)) {
    if (!checkState(request)) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return false;
    }

    log.debug("Login-Retrieve-User " + this);
    token = oauth.getAccessToken(new OAuthVerifier(request.getParameter("code")));
    user = oauth.getUserInfo(token);

    if (isLoggedIn()) {
      log.debug("Login-SUCCESS " + this);
      authenticateAndRedirect(request, response);
      return true;
    }
    response.sendError(SC_UNAUTHORIZED);
    return false;
  }
  log.debug("Login-PHASE1 " + this);
  redirectToken = LoginUrlToken.getToken(request);
  response.sendRedirect(oauth.getAuthorizationUrl() + "&state=" + state);
  return false;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:29,代码来源:OAuthSessionOverOpenID.java

示例3: LoginForm

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Inject
LoginForm(
    @CanonicalWebUrl @Nullable Provider<String> urlProvider,
    @GerritServerConfig Config config,
    AuthConfig authConfig,
    OpenIdServiceImpl impl,
    SiteHeaderFooter header,
    Provider<OAuthSessionOverOpenID> oauthSessionProvider,
    Provider<CurrentUser> currentUserProvider,
    DynamicMap<OAuthServiceProvider> oauthServiceProviders) {
  this.urlProvider = urlProvider;
  this.impl = impl;
  this.header = header;
  this.maxRedirectUrlLength = config.getInt("openid", "maxRedirectUrlLength", 10);
  this.oauthSessionProvider = oauthSessionProvider;
  this.currentUserProvider = currentUserProvider;
  this.oauthServiceProviders = oauthServiceProviders;

  if (urlProvider == null || Strings.isNullOrEmpty(urlProvider.get())) {
    log.error("gerrit.canonicalWebUrl must be set in gerrit.config");
  }

  if (authConfig.getAuthType() == AuthType.OPENID_SSO) {
    suggestProviders = ImmutableSet.of();
    ssoUrl = authConfig.getOpenIdSsoUrl();
  } else {
    Set<String> providers = new HashSet<>();
    for (Map.Entry<String, String> e : ALL_PROVIDERS.entrySet()) {
      if (impl.isAllowedOpenID(e.getValue())) {
        providers.add(e.getKey());
      }
    }
    suggestProviders = ImmutableSet.copyOf(providers);
    ssoUrl = null;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:LoginForm.java

示例4: lookupOAuthServiceProvider

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
private OAuthServiceProvider lookupOAuthServiceProvider(String providerId) {
  if (providerId.startsWith("http://")) {
    providerId = providerId.substring("http://".length());
  }
  Set<String> plugins = oauthServiceProviders.plugins();
  for (String pluginName : plugins) {
    Map<String, Provider<OAuthServiceProvider>> m = oauthServiceProviders.byPlugin(pluginName);
    for (Map.Entry<String, Provider<OAuthServiceProvider>> e : m.entrySet()) {
      if (providerId.equals(String.format("%s_%s", pluginName, e.getKey()))) {
        return e.getValue().get();
      }
    }
  }
  return null;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:16,代码来源:LoginForm.java

示例5: configureServlets

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Override
protected void configureServlets() {
  serve("/login", "/login/*").with(LoginForm.class);
  serve("/logout").with(OAuthOverOpenIDLogoutServlet.class);
  filter("/oauth").through(OAuthWebFilterOverOpenID.class);
  serve("/" + OpenIdServiceImpl.RETURN_URL).with(OpenIdLoginServlet.class);
  serve("/" + XrdsServlet.LOCATION).with(XrdsServlet.class);
  filter("/").through(XrdsFilter.class);
  bind(OpenIdServiceImpl.class);
  DynamicMap.mapOf(binder(), OAuthServiceProvider.class);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:12,代码来源:OpenIdModule.java

示例6: OAuthWebFilterOverOpenID

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Inject
OAuthWebFilterOverOpenID(
    DynamicMap<OAuthServiceProvider> oauthServiceProviders,
    Provider<OAuthSessionOverOpenID> oauthSessionProvider) {
  this.oauthServiceProviders = oauthServiceProviders;
  this.oauthSessionProvider = oauthSessionProvider;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:8,代码来源:OAuthWebFilterOverOpenID.java

示例7: pickSSOServiceProvider

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
private void pickSSOServiceProvider() {
  SortedSet<String> plugins = oauthServiceProviders.plugins();
  if (plugins.size() == 1) {
    SortedMap<String, Provider<OAuthServiceProvider>> services =
        oauthServiceProviders.byPlugin(Iterables.getOnlyElement(plugins));
    if (services.size() == 1) {
      ssoProvider = Iterables.getOnlyElement(services.values()).get();
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:11,代码来源:OAuthWebFilterOverOpenID.java

示例8: OAuthWebFilter

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Inject
OAuthWebFilter(
    @CanonicalWebUrl @Nullable Provider<String> urlProvider,
    DynamicMap<OAuthServiceProvider> oauthServiceProviders,
    Provider<OAuthSession> oauthSessionProvider,
    SiteHeaderFooter header) {
  this.urlProvider = urlProvider;
  this.oauthServiceProviders = oauthServiceProviders;
  this.oauthSessionProvider = oauthSessionProvider;
  this.header = header;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:12,代码来源:OAuthWebFilter.java

示例9: doFilter

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  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)) {
    if (service == null && Strings.isNullOrEmpty(provider)) {
      selectProvider(httpRequest, httpResponse, null);
      return;
    }
    if (service == null) {
      service = findService(provider);
    }
    oauthSession.setServiceProvider(service);
    oauthSession.login(httpRequest, httpResponse, service);
  } else {
    chain.doFilter(httpRequest, response);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:31,代码来源:OAuthWebFilter.java

示例10: findService

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
private OAuthServiceProvider findService(String providerId) throws ServletException {
  Set<String> plugins = oauthServiceProviders.plugins();
  for (String pluginName : plugins) {
    Map<String, Provider<OAuthServiceProvider>> m = oauthServiceProviders.byPlugin(pluginName);
    for (Map.Entry<String, Provider<OAuthServiceProvider>> e : m.entrySet()) {
      if (providerId.equals(String.format("%s_%s", pluginName, e.getKey()))) {
        return e.getValue().get();
      }
    }
  }
  throw new ServletException("No provider found for: " + providerId);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:13,代码来源:OAuthWebFilter.java

示例11: selectProvider

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
private void selectProvider(
    HttpServletRequest req, HttpServletResponse res, @Nullable String errorMessage)
    throws IOException {
  String self = req.getRequestURI();
  String cancel = MoreObjects.firstNonNull(urlProvider != null ? urlProvider.get() : "/", "/");
  cancel += LoginUrlToken.getToken(req);

  Document doc = header.parse(OAuthWebFilter.class, "LoginForm.html");
  HtmlDomUtil.find(doc, "hostName").setTextContent(req.getServerName());
  HtmlDomUtil.find(doc, "login_form").setAttribute("action", self);
  HtmlDomUtil.find(doc, "cancel_link").setAttribute("href", cancel);

  Element emsg = HtmlDomUtil.find(doc, "error_message");
  if (Strings.isNullOrEmpty(errorMessage)) {
    emsg.getParentNode().removeChild(emsg);
  } else {
    emsg.setTextContent(errorMessage);
  }

  Element providers = HtmlDomUtil.find(doc, "providers");

  Set<String> plugins = oauthServiceProviders.plugins();
  for (String pluginName : plugins) {
    Map<String, Provider<OAuthServiceProvider>> m = oauthServiceProviders.byPlugin(pluginName);
    for (Map.Entry<String, Provider<OAuthServiceProvider>> e : m.entrySet()) {
      addProvider(providers, pluginName, e.getKey(), e.getValue().get().getName());
    }
  }

  sendHtml(res, doc);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:32,代码来源:OAuthWebFilter.java

示例12: pickSSOServiceProvider

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
private void pickSSOServiceProvider() throws ServletException {
  SortedSet<String> plugins = oauthServiceProviders.plugins();
  if (plugins.isEmpty()) {
    throw new ServletException("OAuth service provider wasn't installed");
  }
  if (plugins.size() == 1) {
    SortedMap<String, Provider<OAuthServiceProvider>> services =
        oauthServiceProviders.byPlugin(Iterables.getOnlyElement(plugins));
    if (services.size() == 1) {
      ssoProvider = Iterables.getOnlyElement(services.values()).get();
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:OAuthWebFilter.java

示例13: configureServlets

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Override
protected void configureServlets() {
  filter("/login", "/login/*", "/oauth").through(OAuthWebFilter.class);
  // This is needed to invalidate OAuth session during logout
  serve("/logout").with(OAuthLogoutServlet.class);
  DynamicMap.mapOf(binder(), OAuthServiceProvider.class);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:8,代码来源:OAuthModule.java

示例14: login

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
boolean login(
    HttpServletRequest request, HttpServletResponse response, OAuthServiceProvider oauth)
    throws IOException {
  log.debug("Login " + this);

  if (isOAuthFinal(request)) {
    if (!checkState(request)) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return false;
    }

    log.debug("Login-Retrieve-User " + this);
    OAuthToken token = oauth.getAccessToken(new OAuthVerifier(request.getParameter("code")));
    user = oauth.getUserInfo(token);

    if (isLoggedIn()) {
      log.debug("Login-SUCCESS " + this);
      authenticateAndRedirect(request, response, token);
      return true;
    }
    response.sendError(SC_UNAUTHORIZED);
    return false;
  }
  log.debug("Login-PHASE1 " + this);
  redirectToken = request.getRequestURI();
  // We are here in content of filter.
  // Due to this Jetty limitation:
  // https://bz.apache.org/bugzilla/show_bug.cgi?id=28323
  // we cannot use LoginUrlToken.getToken() method,
  // because it relies on getPathInfo() and it is always null here.
  redirectToken = redirectToken.substring(request.getContextPath().length());
  response.sendRedirect(oauth.getAuthorizationUrl() + "&state=" + state);
  return false;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:35,代码来源:OAuthSession.java

示例15: configureServlets

import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider; //导入依赖的package包/类
@Override
protected void configureServlets() {
  PluginConfig cfg =
      cfgFactory.getFromGerritConfig(pluginName + GoogleOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(GoogleOAuthService.CONFIG_SUFFIX))
        .to(GoogleOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + GitHubOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(GitHubOAuthService.CONFIG_SUFFIX))
        .to(GitHubOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + BitbucketOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(BitbucketOAuthService.CONFIG_SUFFIX))
        .to(BitbucketOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + CasOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(CasOAuthService.CONFIG_SUFFIX))
        .to(CasOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + FacebookOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(FacebookOAuthService.CONFIG_SUFFIX))
        .to(FacebookOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + GitLabOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(GitLabOAuthService.CONFIG_SUFFIX))
        .to(GitLabOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + DexOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(DexOAuthService.CONFIG_SUFFIX))
        .to(DexOAuthService.class);
  }

  cfg = cfgFactory.getFromGerritConfig(pluginName + KeycloakOAuthService.CONFIG_SUFFIX);
  if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
    bind(OAuthServiceProvider.class)
        .annotatedWith(Exports.named(KeycloakOAuthService.CONFIG_SUFFIX))
        .to(KeycloakOAuthService.class);
  }
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:60,代码来源:HttpModule.java


注:本文中的com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。