use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class ProjectWatch method getWatchers.
/** Returns all watchers that are relevant */
public final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig) throws OrmException {
Watchers matching = new Watchers();
Set<Account.Id> projectWatchers = new HashSet<>();
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
Account.Id accountId = a.getAccount().getId();
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
if (project.equals(e.getKey().project()) && add(matching, accountId, e.getKey(), e.getValue(), type)) {
// We only want to prevent matching All-Projects if this filter hits
projectWatchers.add(accountId);
}
}
}
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(args.allProjectsName)) {
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
if (args.allProjectsName.equals(e.getKey().project())) {
Account.Id accountId = a.getAccount().getId();
if (!projectWatchers.contains(accountId)) {
add(matching, accountId, e.getKey(), e.getValue(), type);
}
}
}
}
if (!includeWatchersFromNotifyConfig) {
return matching;
}
for (ProjectState state : projectState.tree()) {
for (NotifyConfig nc : state.getConfig().getNotifyConfigs()) {
if (nc.isNotify(type)) {
try {
add(matching, nc);
} catch (QueryParseException e) {
log.warn("Project {} has invalid notify {} filter \"{}\": {}", state.getProject().getName(), nc.getName(), nc.getFilter(), e.getMessage());
}
}
}
}
return matching;
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class InternalAuthBackend method authenticate.
// TODO(gerritcodereview-team): This function has no coverage.
@Override
public AuthUser authenticate(AuthRequest req) throws MissingCredentialsException, InvalidCredentialsException, UnknownUserException, UserNotAllowedException, AuthException {
if (Strings.isNullOrEmpty(req.getUsername()) || Strings.isNullOrEmpty(req.getPassword())) {
throw new MissingCredentialsException();
}
String username;
if (authConfig.isUserNameToLowerCase()) {
username = req.getUsername().toLowerCase(Locale.US);
} else {
username = req.getUsername();
}
final AccountState who = accountCache.getByUsername(username);
if (who == null) {
throw new UnknownUserException();
} else if (!who.getAccount().isActive()) {
throw new UserNotAllowedException("Authentication failed for " + username + ": account inactive or not provisioned in Gerrit");
}
if (!who.checkPassword(req.getPassword(), username)) {
throw new InvalidCredentialsException();
}
return new AuthUser(AuthUser.UUID.create(username), username);
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class FromAddressGeneratorProviderTest method user.
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();
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class FromAddressGeneratorProviderTest method makeUser.
private AccountState makeUser(final String name, final String email) {
final Account.Id userId = new Account.Id(42);
final Account account = new Account(userId, TimeUtil.nowTs());
account.setFullName(name);
account.setPreferredEmail(email);
return new AccountState(account, Collections.emptySet(), Collections.emptySet(), new HashMap<>());
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class GerritGSSAuthenticator method validateIdentity.
@Override
public boolean validateIdentity(final ServerSession session, final String identity) {
final SshSession sd = session.getAttribute(SshSession.KEY);
int at = identity.indexOf('@');
String username;
if (at == -1) {
username = identity;
} else {
username = identity.substring(0, at);
}
if (config.getBoolean("auth", "userNameToLowerCase", false)) {
username = username.toLowerCase(Locale.US);
}
AccountState state = accounts.getByUsername(username);
Account account = state == null ? null : state.getAccount();
boolean active = account != null && account.isActive();
if (active) {
return SshUtil.success(username, session, sshScope, sshLog, sd, SshUtil.createUser(sd, userFactory, account.getId()));
}
return false;
}
Aggregations