Skip to content

Commit 06b4100

Browse files
committed
Fix exception handlling
Both types of topt failures are now thown correctly
1 parent e98bc42 commit 06b4100

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/io/cos/cas/osf/authentication/handler/support/OsfPostgresAuthenticationHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ protected final AuthenticationHandlerExecutionResult authenticateOsfPostgresInte
165165
if (oneTimePassword == null) {
166166
throw new OneTimePasswordRequiredException("2FA TOTP required for user [" + username + "]");
167167
}
168+
final long transformedOneTimePassword = Long.parseLong(oneTimePassword);
169+
boolean checkPassed;
168170
try {
169-
final long transformedOneTimePassword = Long.parseLong(oneTimePassword);
170-
if (!TotpUtils.checkCode(osfTotp.getTotpSecretBase32(), transformedOneTimePassword)) {
171-
throw new InvalidOneTimePasswordException("Invalid 2FA TOTP for user [" + username + "] (Type 1)");
172-
}
173-
} catch (final Exception e) {
171+
checkPassed = TotpUtils.checkCode(osfTotp.getTotpSecretBase32(), transformedOneTimePassword);
172+
} catch (final Exception e){
174173
throw new InvalidOneTimePasswordException("Invalid 2FA TOTP for user [" + username + "] (Type 2)");
175174
}
175+
if (!checkPassed) {
176+
throw new InvalidOneTimePasswordException("Invalid 2FA TOTP for user [" + username + "] (Type 1)");
177+
}
176178
}
177179

178180
if (!osfUser.isTermsOfServiceAccepted() && !isTermsOfServiceChecked) {

0 commit comments

Comments
 (0)