Skip to content

Commit

Permalink
fix: oauth isn't a second factor, fixes backup codes not always being…
Browse files Browse the repository at this point in the history
… removed and fixes #1317
  • Loading branch information
MiniDigger committed Jan 26, 2024
1 parent 0d738d5 commit 6ed8222
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public interface UserCredentialDAO {
boolean update(long userId, JSONB credential, @EnumByOrdinal CredentialType type);

@EnumByOrdinal
@SqlQuery("SELECT type FROM user_credentials WHERE user_id = :userId AND type != :password AND (type != :webAuthn OR (credential ->> 'credentials' IS NOT NULL AND jsonb_array_length(credential -> 'credentials') > 0))")
List<CredentialType> getAll(long userId, @EnumByOrdinal CredentialType password, @EnumByOrdinal CredentialType webAuthn);
@SqlQuery("SELECT type FROM user_credentials WHERE user_id = :userId AND type != :password AND type != :oauth AND (type != :webAuthn OR (credential ->> 'credentials' IS NOT NULL AND jsonb_array_length(credential -> 'credentials') > 0))")
List<CredentialType> getAll(long userId, @EnumByOrdinal CredentialType password, @EnumByOrdinal CredentialType webAuthn, @EnumByOrdinal CredentialType oauth);

@UseStringTemplateEngine
@RegisterConstructorMapper(value = UserCredentialTable.class, prefix = "uc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean updateCredential(final long userId, final Credential credential)
}

public List<CredentialType> getCredentialTypes(final long userId) {
return this.userCredentialDAO.getAll(userId, CredentialType.PASSWORD, CredentialType.WEBAUTHN);
return this.userCredentialDAO.getAll(userId, CredentialType.PASSWORD, CredentialType.WEBAUTHN, CredentialType.OAUTH);
}

public void verifyPassword(final long userId, final String password) {
Expand Down Expand Up @@ -126,14 +126,14 @@ public void verifyBackupCode(final long userId, final String code) {

public void checkRemoveBackupCodes() {
final List<CredentialType> credentialTypes = this.getCredentialTypes(this.getHangarPrincipal().getUserId());
if (credentialTypes.size() == 1 && credentialTypes.get(0) == CredentialType.BACKUP_CODES) {
if (credentialTypes.size() == 1 && credentialTypes.getFirst() == CredentialType.BACKUP_CODES) {
this.removeCredential(this.getHangarPrincipal().getUserId(), CredentialType.BACKUP_CODES);
}
}

public int getAal(final UserTable userTable) {
final List<CredentialType> types = this.getCredentialTypes(userTable.getUserId());
if (types.isEmpty() || (types.size() == 1 && types.get(0) == CredentialType.BACKUP_CODES)) {
if (types.isEmpty() || (types.size() == 1 && types.getFirst() == CredentialType.BACKUP_CODES)) {
return userTable.isEmailVerified() ? 1 : 0;
} else {
return 2;
Expand Down

0 comments on commit 6ed8222

Please sign in to comment.