Пример #1
0
  public RootDispatcher(IGitblit gitblit, SshDaemonClient client, String cmdLine) {
    super();
    setContext(new SshCommandContext(gitblit, client, cmdLine));

    UserModel user = client.getUser();
    register(user, VersionCommand.class);
    register(user, GitDispatcher.class);
    register(user, KeysDispatcher.class);
    register(user, PluginDispatcher.class);

    List<DispatchCommand> exts = gitblit.getExtensions(DispatchCommand.class);
    for (DispatchCommand ext : exts) {
      Class<? extends DispatchCommand> extClass = ext.getClass();
      PluginWrapper wrapper = gitblit.whichPlugin(extClass);
      String plugin = wrapper.getDescriptor().getPluginId();
      CommandMetaData meta = extClass.getAnnotation(CommandMetaData.class);
      log.debug("Dispatcher {} is loaded from plugin {}", meta.name(), plugin);
      register(user, ext);
    }
  }
  /**
   * Returns the user making the request, if the user has authenticated.
   *
   * @param httpRequest
   * @return user
   */
  public UserModel getUser(HttpServletRequest httpRequest) {
    UserModel user = null;
    String username = (String) httpRequest.getAttribute("gerrit-username");
    String token = (String) httpRequest.getAttribute("gerrit-token");

    if (token == null || username == null) {
      return null;
    }

    user =
        gitBlit.authenticate(
            username, (GerritToGitBlitUserService.SESSIONAUTH + token).toCharArray(), null);
    if (user != null) {
      return user;
    }

    return null;
  }