-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CB-4264 password policy configuration #2301
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eace7bd
CB-4491 password policy config api
yagudin10 d183040
CB-4491 move policy config to sm
yagudin10 08aaf8d
CB-4491 cb config fix
yagudin10 1da6948
Merge remote-tracking branch 'origin/devel' into CB-4264-password-policy
yagudin10 49dc68d
CB-4264 add password policy
devnaumov 504b989
CB-4491 deserialization fix
yagudin10 486d7b6
Merge remote-tracking branch 'origin/CB-4264-password-policy' into CB…
yagudin10 452aafc
CB-4491 deserialization fix
yagudin10 8f809cd
CB-4264 add title
devnaumov e1e38f4
Merge branch 'CB-4264-password-policy' of https://github.com/dbeaver/…
devnaumov 10bed18
Merge branch 'devel' into CB-4264-password-policy
dariamarutkina 2973133
Merge branch 'devel' into CB-4264-password-policy
dariamarutkina 58ad8a6
CB-4264 rename params
yagudin10 f36dcf3
CB-4264 fix naming
devnaumov 04637ba
CB-4264 accept any language
devnaumov 6a6b281
Merge branch 'devel' into CB-4264-password-policy
dariamarutkina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not to use:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is no message if the status is valid
if(isValid) {message is null here}