use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class AccountManager method unlink.
/**
* Unlink an authentication identity from an existing account.
*
* @param from account to unlink the identity from.
* @param who the identity to delete
* @return the result of unlinking the identity from the user.
* @throws AccountException the identity belongs to a different account, or it cannot be unlinked
* at this time.
*/
public AuthResult unlink(Account.Id from, AuthRequest who) throws AccountException, OrmException, IOException, ConfigInvalidException {
try (ReviewDb db = schema.open()) {
ExternalId extId = findExternalId(who.getExternalIdKey());
if (extId != null) {
if (!extId.accountId().equals(from)) {
throw new AccountException("Identity '" + who.getExternalIdKey().get() + "' in use by another account");
}
externalIdsUpdateFactory.create().delete(extId);
if (who.getEmailAddress() != null) {
Account a = db.accounts().get(from);
if (a.getPreferredEmail() != null && a.getPreferredEmail().equals(who.getEmailAddress())) {
a.setPreferredEmail(null);
db.accounts().update(Collections.singleton(a));
}
byEmailCache.evict(who.getEmailAddress());
byIdCache.evict(from);
}
} else {
throw new AccountException("Identity '" + who.getExternalIdKey().get() + "' not found");
}
return new AuthResult(from, who.getExternalIdKey(), false);
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class AccountManager method authenticate.
/**
* Authenticate the user, potentially creating a new account if they are new.
*
* @param who identity of the user, with any details we received about them.
* @return the result of authenticating the user.
* @throws AccountException the account does not exist, and cannot be created, or exists, but
* cannot be located, or is inactive.
*/
public AuthResult authenticate(AuthRequest who) throws AccountException, IOException {
who = realm.authenticate(who);
try {
try (ReviewDb db = schema.open()) {
ExternalId id = findExternalId(who.getExternalIdKey());
if (id == null) {
//
return create(db, who);
}
// Account exists
Account act = byIdCache.get(id.accountId()).getAccount();
if (!act.isActive()) {
throw new AccountException("Authentication error, account inactive");
}
// return the identity to the caller.
update(db, who, id);
return new AuthResult(id.accountId(), who.getExternalIdKey(), false);
}
} catch (OrmException | ConfigInvalidException e) {
throw new AccountException("Authentication error", e);
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class EventFactory method addSubmitRecordLabels.
private void addSubmitRecordLabels(SubmitRecord submitRecord, SubmitRecordAttribute sa) {
if (submitRecord.labels != null && !submitRecord.labels.isEmpty()) {
sa.labels = new ArrayList<>();
for (SubmitRecord.Label lbl : submitRecord.labels) {
SubmitLabelAttribute la = new SubmitLabelAttribute();
la.label = lbl.label;
la.status = lbl.status.name();
if (lbl.appliedBy != null) {
Account a = accountCache.get(lbl.appliedBy).getAccount();
la.by = asAccountAttribute(a);
}
sa.labels.add(la);
}
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class PatchScriptFactory method loadCommentsAndHistory.
private void loadCommentsAndHistory(ChangeNotes notes, ChangeType changeType, String oldName, String newName) throws OrmException {
Map<Patch.Key, Patch> byKey = new HashMap<>();
if (loadHistory) {
// This seems like a cheap trick. It doesn't properly account for a
// file that gets renamed between patch set 1 and patch set 2. We
// will wind up packing the wrong Patch object because we didn't do
// proper rename detection between the patch sets.
//
history = new ArrayList<>();
for (PatchSet ps : psUtil.byChange(db, notes)) {
if (!control.isPatchVisible(ps, db)) {
continue;
}
String name = fileName;
if (psa != null) {
switch(changeType) {
case COPIED:
case RENAMED:
if (ps.getId().equals(psa)) {
name = oldName;
}
break;
case MODIFIED:
case DELETED:
case ADDED:
case REWRITE:
break;
}
}
Patch p = new Patch(new Patch.Key(ps.getId(), name));
history.add(p);
byKey.put(p.getKey(), p);
}
if (edit != null && edit.isPresent()) {
Patch p = new Patch(new Patch.Key(new PatchSet.Id(psb.getParentKey(), 0), fileName));
history.add(p);
byKey.put(p.getKey(), p);
}
}
if (loadComments && edit == null) {
comments = new CommentDetail(psa, psb);
switch(changeType) {
case ADDED:
case MODIFIED:
loadPublished(byKey, newName);
break;
case DELETED:
loadPublished(byKey, newName);
break;
case COPIED:
case RENAMED:
if (psa != null) {
loadPublished(byKey, oldName);
}
loadPublished(byKey, newName);
break;
case REWRITE:
break;
}
CurrentUser user = control.getUser();
if (user.isIdentifiedUser()) {
Account.Id me = user.getAccountId();
switch(changeType) {
case ADDED:
case MODIFIED:
loadDrafts(byKey, me, newName);
break;
case DELETED:
loadDrafts(byKey, me, newName);
break;
case COPIED:
case RENAMED:
if (psa != null) {
loadDrafts(byKey, me, oldName);
}
loadDrafts(byKey, me, newName);
break;
case REWRITE:
break;
}
}
}
}
use of com.google.gerrit.reviewdb.client.Account 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