-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* CB-4491 password policy config api * CB-4491 move policy config to sm * CB-4491 cb config fix * CB-4264 add password policy * CB-4491 deserialization fix * CB-4491 deserialization fix * CB-4264 add title * CB-4264 rename params * CB-4264 fix naming * CB-4264 accept any language --------- Co-authored-by: naumov <[email protected]> Co-authored-by: Daria Marutkina <[email protected]>
- Loading branch information
1 parent
0544547
commit 8ba0eb6
Showing
31 changed files
with
326 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ver.service.security/src/io/cloudbeaver/service/security/PasswordPolicyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.cloudbeaver.service.security; | ||
|
||
import org.jkiss.dbeaver.model.meta.Property; | ||
|
||
public class PasswordPolicyConfiguration { | ||
private static final int DEFAULT_MIN_LENGTH = 8; | ||
private static final int DEFAULT_MIN_DIGITS = 1; | ||
private static final int DEFAULT_MIN_SPECIAL_CHARACTERS = 0; | ||
private static final boolean DEFAULT_REQUIRES_UPPER_LOWER_CASE = true; | ||
private int minLength = DEFAULT_MIN_LENGTH; | ||
private int minNumberCount = DEFAULT_MIN_DIGITS; | ||
private int minSymbolCount = DEFAULT_MIN_SPECIAL_CHARACTERS; | ||
private boolean requireMixedCase = DEFAULT_REQUIRES_UPPER_LOWER_CASE; | ||
|
||
@Property | ||
public int getMinLength() { | ||
return minLength; | ||
} | ||
|
||
@Property | ||
public int getMinNumberCount() { | ||
return minNumberCount; | ||
} | ||
|
||
@Property | ||
public int getMinSymbolCount() { | ||
return minSymbolCount; | ||
} | ||
|
||
@Property | ||
public boolean isRequireMixedCase() { | ||
return requireMixedCase; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
webapp/packages/core-authentication/src/PasswordPolicyService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { computed, makeObservable } from 'mobx'; | ||
|
||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { LocalizationService } from '@cloudbeaver/core-localization'; | ||
import { ServerConfigResource } from '@cloudbeaver/core-root'; | ||
import type { PasswordPolicyConfig } from '@cloudbeaver/core-sdk'; | ||
|
||
const DEFAULT_PASSWORD_POLICY: PasswordPolicyConfig = { | ||
minLength: 8, | ||
minNumberCount: 0, | ||
minSymbolCount: 0, | ||
requireMixedCase: false, | ||
}; | ||
|
||
type ValidationResult = { isValid: true; errorMessage: null } | { isValid: false; errorMessage: string }; | ||
|
||
@injectable() | ||
export class PasswordPolicyService { | ||
get config(): PasswordPolicyConfig { | ||
return { | ||
minLength: this.serverConfigResource.data?.passwordPolicyConfiguration?.minLength || DEFAULT_PASSWORD_POLICY.minLength, | ||
minNumberCount: this.serverConfigResource.data?.passwordPolicyConfiguration?.minNumberCount || DEFAULT_PASSWORD_POLICY.minNumberCount, | ||
minSymbolCount: this.serverConfigResource.data?.passwordPolicyConfiguration?.minSymbolCount || DEFAULT_PASSWORD_POLICY.minSymbolCount, | ||
requireMixedCase: this.serverConfigResource.data?.passwordPolicyConfiguration?.requireMixedCase || DEFAULT_PASSWORD_POLICY.requireMixedCase, | ||
}; | ||
} | ||
|
||
constructor(private readonly serverConfigResource: ServerConfigResource, private readonly localizationService: LocalizationService) { | ||
makeObservable(this, { | ||
config: computed, | ||
}); | ||
} | ||
|
||
validatePassword(password: string): ValidationResult { | ||
const trimmedPassword = password.trim(); | ||
|
||
if (trimmedPassword.length < this.config.minLength) { | ||
return { | ||
isValid: false, | ||
errorMessage: this.localizationService.translate('core_authentication_password_policy_min_length', undefined, { min: this.config.minLength }), | ||
}; | ||
} | ||
|
||
if (this.config.requireMixedCase && !(/\p{Ll}/u.test(trimmedPassword) && /\p{Lu}/u.test(trimmedPassword))) { | ||
return { isValid: false, errorMessage: this.localizationService.translate('core_authentication_password_policy_upper_lower_case') }; | ||
} | ||
|
||
if ((trimmedPassword.match(/\d/g) || []).length < this.config.minNumberCount) { | ||
return { | ||
isValid: false, | ||
errorMessage: this.localizationService.translate('core_authentication_password_policy_min_digits', undefined, { | ||
min: this.config.minNumberCount, | ||
}), | ||
}; | ||
} | ||
|
||
if ((trimmedPassword.match(/[!@#$%^&*(),.?":{}|<>]/g) || []).length < this.config.minSymbolCount) { | ||
return { | ||
isValid: false, | ||
errorMessage: this.localizationService.translate('core_authentication_password_policy_min_special_characters', undefined, { | ||
min: this.config.minSymbolCount, | ||
}), | ||
}; | ||
} | ||
|
||
return { isValid: true, errorMessage: null }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
webapp/packages/core-authentication/src/usePasswordPolicy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { useCustomInputValidation } from '@cloudbeaver/core-blocks'; | ||
import { useService } from '@cloudbeaver/core-di'; | ||
|
||
import { PasswordPolicyService } from './PasswordPolicyService'; | ||
|
||
export function usePasswordPolicy() { | ||
const passwordPolicyService = useService(PasswordPolicyService); | ||
|
||
const ref = useCustomInputValidation<string>(value => { | ||
const validation = passwordPolicyService.validatePassword(value); | ||
return validation.isValid ? null : validation.errorMessage; | ||
}); | ||
|
||
return ref; | ||
} |
Oops, something went wrong.