Package com.google.gerrit.server.account

Examples of com.google.gerrit.server.account.AccountState


    }
    return name;
  }

  public String getNameEmailFor(Account.Id accountId) {
    AccountState who = args.accountCache.get(accountId);
    String name = who.getAccount().getFullName();
    String email = who.getAccount().getPreferredEmail();

    if (name != null && email != null) {
      return name + " <" + email + ">";

    } else if (name != null) {
View Full Code Here


    return result;
  }

  private String formatUser(Account.Id who) {
    AccountState state = accountCache.get(who);
    if (state != null) {
      return formatUser(state.getAccount(), who);
    } else {
      return who.toString();
    }
  }
View Full Code Here

    }
    if (authConfig.isUserNameToLowerCase()) {
      username = username.toLowerCase(Locale.US);
    }

    final AccountState who = accountCache.getByUsername(username);
    if (who == null || !who.getAccount().isActive()) {
      log.warn("Authentication failed for " + username
          + ": account inactive or not provisioned in Gerrit");
      rsp.sendError(SC_UNAUTHORIZED);
      return false;
    }
View Full Code Here

    }

    public void doPatchsetCreatedHook(final Change change, final PatchSet patchSet,
          final ReviewDb db) throws OrmException {
        final PatchSetCreatedEvent event = new PatchSetCreatedEvent();
        final AccountState uploader = accountCache.get(patchSet.getUploader());

        event.change = eventFactory.asChangeAttribute(change);
        event.patchSet = eventFactory.asPatchSetAttribute(patchSet);
        event.uploader = eventFactory.asAccountAttribute(uploader.getAccount());
        fireEvent(change, event, db);

        final List<String> args = new ArrayList<String>();
        addArg(args, "--change", event.change.id);
        addArg(args, "--change-url", event.change.url);
        addArg(args, "--project", event.change.project);
        addArg(args, "--branch", event.change.branch);
        addArg(args, "--uploader", getDisplayName(uploader.getAccount()));
        addArg(args, "--commit", event.patchSet.revision);
        addArg(args, "--patchset", event.patchSet.number);

        runHook(change.getProject(), patchsetCreatedHook, args);
    }
View Full Code Here

    }

    public void doDraftPublishedHook(final Change change, final PatchSet patchSet,
          final ReviewDb db) throws OrmException {
        final DraftPublishedEvent event = new DraftPublishedEvent();
        final AccountState uploader = accountCache.get(patchSet.getUploader());

        event.change = eventFactory.asChangeAttribute(change);
        event.patchSet = eventFactory.asPatchSetAttribute(patchSet);
        event.uploader = eventFactory.asAccountAttribute(uploader.getAccount());
        fireEvent(change, event, db);

        final List<String> args = new ArrayList<String>();
        addArg(args, "--change", event.change.id);
        addArg(args, "--change-url", event.change.url);
        addArg(args, "--project", event.change.project);
        addArg(args, "--branch", event.change.branch);
        addArg(args, "--uploader", getDisplayName(uploader.getAccount()));
        addArg(args, "--commit", event.patchSet.revision);
        addArg(args, "--patchset", event.patchSet.number);

        runHook(change.getProject(), draftPublishedHook, args);
    }
View Full Code Here

    if (username != null) {
       if (config.getBoolean("auth", "userNameToLowerCase", false)) {
            username = username.toLowerCase(Locale.US);
        }
      log.debug("User name: " + username);
       AccountState who = accountCache.getByUsername(username);
       log.debug("AccountState " + who);
      if (who == null && username.matches("^([a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]|[a-zA-Z0-9])$")) {
        log.debug("User is not registered with Gerrit. Register now."); // This approach assumes an auth type of HTTP_LDAP
        final AuthRequest areq = AuthRequest.forUser(username);
        try {
          accountManager.authenticate(areq);
          who = accountCache.getByUsername(username);
          if (who == null) {
            log.warn("Unable to register user \"" + username
                + "\". Continue as anonymous.");
          } else {
            log.debug("User registered.");
          }
        } catch (AccountException e) {
          log.warn("Exception registering user \"" + username
              + "\". Continue as anonymous.", e);
        }
      }
       if (who != null && who.getAccount().isActive()) {
         log.debug("Not anonymous user");
         WebSession ws = session.get();
         ws.setUserAccountId(who.getAccount().getId());
         ws.setAccessPathOk(AccessPath.REST_API, true);
        } else {
          log.debug("Anonymous user");
        }
    }
View Full Code Here

    if (username != null) {
       if (config.getBoolean("auth", "userNameToLowerCase", false)) {
            username = username.toLowerCase(Locale.US);
        }
      log.debug("User name: " + username);
       AccountState who = accountCache.getByUsername(username);
       log.debug("AccountState " + who);
      if (who == null && username.matches("^([a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]|[a-zA-Z0-9])$")) {
        log.debug("User is not registered with Gerrit. Register now."); // This approach assumes an auth type of HTTP_LDAP
        final AuthRequest areq = AuthRequest.forUser(username);
        try {
          accountManager.authenticate(areq);
          who = accountCache.getByUsername(username);
          if (who == null) {
            log.warn("Unable to register user \"" + username
                + "\". Continue as anonymous.");
          } else {
            log.debug("User registered.");
          }
        } catch (AccountException e) {
          log.warn("Exception registering user \"" + username
              + "\". Continue as anonymous.", e);
        }
      }
       if (who != null && who.getAccount().isActive()) {
         log.debug("Not anonymous user");
         WebSession ws = session.get();
         ws.setUserAccountId(who.getAccount().getId());
         ws.setAccessPathOk(AccessPath.REST_API, true);
        } else {
          log.debug("Anonymous user");
        }
    }
View Full Code Here

  private AccountState makeUser(final String name, final String email) {
    final Account.Id userId = new Account.Id(42);
    final Account account = new Account(userId);
    account.setFullName(name);
    account.setPreferredEmail(email);
    final AccountState s =
        new AccountState(account, Collections.<AccountGroup.UUID> emptySet(),
            Collections.<AccountExternalId> emptySet());
    return s;
  }
View Full Code Here

    assertEquals("my.server@email.address", r.email);
    verify(accountCache);
  }

  private Account.Id user(final String name, final String email) {
    final AccountState s = makeUser(name, email);
    expect(accountCache.get(eq(s.getAccount().getId()))).andReturn(s);
    return s.getAccount().getId();
  }
View Full Code Here

    expect(accountCache.get(eq(s.getAccount().getId()))).andReturn(s);
    return s.getAccount().getId();
  }

  private Account.Id userNoLookup(final String name, final String email) {
    final AccountState s = makeUser(name, email);
    return s.getAccount().getId();
  }
View Full Code Here

TOP

Related Classes of com.google.gerrit.server.account.AccountState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.