mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-29 02:22:16 +00:00
feat: provide option to limit (T)OTP checks (#7693)
* feat: provide option to limit (T)OTP checks * fix requests in console * update errors pkg * cleanup * cleanup * improve naming of existing config
This commit is contained in:
+35
-3
@@ -17,17 +17,49 @@
|
||||
<div class="lockout-content">
|
||||
<div class="row">
|
||||
<div class="length-wrapper">
|
||||
<button [disabled]="(['policy.write'] | hasRole | async) === false" mat-icon-button (click)="decrementMaxAttempts()">
|
||||
<button
|
||||
[disabled]="(['policy.write'] | hasRole | async) === false"
|
||||
mat-icon-button
|
||||
(click)="decrementPasswordMaxAttempts()"
|
||||
>
|
||||
<mat-icon>remove</mat-icon>
|
||||
</button>
|
||||
<span>{{ lockoutData.maxPasswordAttempts }}</span>
|
||||
<button [disabled]="(['policy.write'] | hasRole | async) === false" mat-icon-button (click)="incrementMaxAttempts()">
|
||||
<button
|
||||
[disabled]="(['policy.write'] | hasRole | async) === false"
|
||||
mat-icon-button
|
||||
(click)="incrementPasswordMaxAttempts()"
|
||||
>
|
||||
<mat-icon>add</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="number-toggle-row">
|
||||
<span class="left-desc">{{ 'POLICY.DATA.MAXATTEMPTS' | translate }}</span>
|
||||
<span class="left-desc">{{ 'POLICY.DATA.MAXPASSWORDATTEMPTS' | translate }}</span>
|
||||
<span class="fill-space"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="length-wrapper">
|
||||
<button
|
||||
[disabled]="(['policy.write'] | hasRole | async) === false"
|
||||
mat-icon-button
|
||||
(click)="decrementOTPMaxAttempts()"
|
||||
>
|
||||
<mat-icon>remove</mat-icon>
|
||||
</button>
|
||||
<span>{{ lockoutData.maxOtpAttempts }}</span>
|
||||
<button
|
||||
[disabled]="(['policy.write'] | hasRole | async) === false"
|
||||
mat-icon-button
|
||||
(click)="incrementOTPMaxAttempts()"
|
||||
>
|
||||
<mat-icon>add</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="number-toggle-row">
|
||||
<span class="left-desc">{{ 'POLICY.DATA.MAXOTPATTEMPTS' | translate }}</span>
|
||||
<span class="fill-space"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+17
-5
@@ -91,24 +91,36 @@ export class PasswordLockoutPolicyComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
public incrementMaxAttempts(): void {
|
||||
public incrementPasswordMaxAttempts(): void {
|
||||
if (this.lockoutData?.maxPasswordAttempts !== undefined) {
|
||||
this.lockoutData.maxPasswordAttempts++;
|
||||
}
|
||||
}
|
||||
|
||||
public decrementMaxAttempts(): void {
|
||||
public decrementPasswordMaxAttempts(): void {
|
||||
if (this.lockoutData?.maxPasswordAttempts && this.lockoutData?.maxPasswordAttempts > 0) {
|
||||
this.lockoutData.maxPasswordAttempts--;
|
||||
}
|
||||
}
|
||||
|
||||
public incrementOTPMaxAttempts(): void {
|
||||
if (this.lockoutData?.maxOtpAttempts !== undefined) {
|
||||
this.lockoutData.maxOtpAttempts++;
|
||||
}
|
||||
}
|
||||
|
||||
public decrementOTPMaxAttempts(): void {
|
||||
if (this.lockoutData?.maxOtpAttempts && this.lockoutData?.maxOtpAttempts > 0) {
|
||||
this.lockoutData.maxOtpAttempts--;
|
||||
}
|
||||
}
|
||||
|
||||
public savePolicy(): void {
|
||||
let promise: Promise<any>;
|
||||
if (this.lockoutData) {
|
||||
if (this.service instanceof AdminService) {
|
||||
promise = this.service
|
||||
.updateLockoutPolicy(this.lockoutData.maxPasswordAttempts)
|
||||
.updateLockoutPolicy(this.lockoutData.maxPasswordAttempts, this.lockoutData.maxOtpAttempts)
|
||||
.then(() => {
|
||||
this.toast.showInfo('POLICY.TOAST.SET', true);
|
||||
this.fetchData();
|
||||
@@ -119,7 +131,7 @@ export class PasswordLockoutPolicyComponent implements OnInit {
|
||||
} else {
|
||||
if ((this.lockoutData as LockoutPolicy.AsObject).isDefault) {
|
||||
promise = (this.service as ManagementService)
|
||||
.addCustomLockoutPolicy(this.lockoutData.maxPasswordAttempts)
|
||||
.addCustomLockoutPolicy(this.lockoutData.maxPasswordAttempts, this.lockoutData.maxOtpAttempts)
|
||||
.then(() => {
|
||||
this.toast.showInfo('POLICY.TOAST.SET', true);
|
||||
this.fetchData();
|
||||
@@ -129,7 +141,7 @@ export class PasswordLockoutPolicyComponent implements OnInit {
|
||||
});
|
||||
} else {
|
||||
promise = (this.service as ManagementService)
|
||||
.updateCustomLockoutPolicy(this.lockoutData.maxPasswordAttempts)
|
||||
.updateCustomLockoutPolicy(this.lockoutData.maxPasswordAttempts, this.lockoutData.maxOtpAttempts)
|
||||
.then(() => {
|
||||
this.toast.showInfo('POLICY.TOAST.SET', true);
|
||||
this.fetchData();
|
||||
|
||||
@@ -957,9 +957,13 @@ export class AdminService {
|
||||
return this.grpcService.admin.getLockoutPolicy(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
|
||||
public updateLockoutPolicy(maxAttempts: number): Promise<UpdateLockoutPolicyResponse.AsObject> {
|
||||
public updateLockoutPolicy(
|
||||
maxPasswordAttempts: number,
|
||||
maxOTPAttempts: number,
|
||||
): Promise<UpdateLockoutPolicyResponse.AsObject> {
|
||||
const req = new UpdateLockoutPolicyRequest();
|
||||
req.setMaxPasswordAttempts(maxAttempts);
|
||||
req.setMaxPasswordAttempts(maxPasswordAttempts);
|
||||
req.setMaxOtpAttempts(maxOTPAttempts);
|
||||
|
||||
return this.grpcService.admin.updateLockoutPolicy(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
|
||||
@@ -1587,9 +1587,13 @@ export class ManagementService {
|
||||
return this.grpcService.mgmt.getLockoutPolicy(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
|
||||
public addCustomLockoutPolicy(maxAttempts: number): Promise<AddCustomLockoutPolicyResponse.AsObject> {
|
||||
public addCustomLockoutPolicy(
|
||||
maxPasswordAttempts: number,
|
||||
maxOTPAttempts: number,
|
||||
): Promise<AddCustomLockoutPolicyResponse.AsObject> {
|
||||
const req = new AddCustomLockoutPolicyRequest();
|
||||
req.setMaxPasswordAttempts(maxAttempts);
|
||||
req.setMaxPasswordAttempts(maxPasswordAttempts);
|
||||
req.setMaxOtpAttempts(maxOTPAttempts);
|
||||
|
||||
return this.grpcService.mgmt.addCustomLockoutPolicy(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
@@ -1599,9 +1603,13 @@ export class ManagementService {
|
||||
return this.grpcService.mgmt.resetLockoutPolicyToDefault(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
|
||||
public updateCustomLockoutPolicy(maxAttempts: number): Promise<UpdateCustomLockoutPolicyResponse.AsObject> {
|
||||
public updateCustomLockoutPolicy(
|
||||
maxPasswordAttempts: number,
|
||||
maxOTPAttempts: number,
|
||||
): Promise<UpdateCustomLockoutPolicyResponse.AsObject> {
|
||||
const req = new UpdateCustomLockoutPolicyRequest();
|
||||
req.setMaxPasswordAttempts(maxAttempts);
|
||||
req.setMaxPasswordAttempts(maxPasswordAttempts);
|
||||
req.setMaxOtpAttempts(maxOTPAttempts);
|
||||
|
||||
return this.grpcService.mgmt.updateCustomLockoutPolicy(req, null).then((resp) => resp.toObject());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user