Skip to content
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

Fixed fields validation bypass #3527

Merged
merged 2 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public Account create(AccountCreator accountCreator) throws KapuaException {
ArgumentValidator.notNull(accountCreator, "accountCreator");
ArgumentValidator.notNull(accountCreator.getScopeId(), "accountCreator.scopeId");
ArgumentValidator.notEmptyOrNull(accountCreator.getName(), "accountCreator.name");
ArgumentValidator.match(accountCreator.getName(), CommonsValidationRegex.NAME_REGEXP, "accountCreator.name");
ArgumentValidator.notEmptyOrNull(accountCreator.getOrganizationName(), "accountCreator.organizationName");
ArgumentValidator.notEmptyOrNull(accountCreator.getOrganizationEmail(), "accountCreator.organizationEmail");
ArgumentValidator.match(accountCreator.getOrganizationEmail(), CommonsValidationRegex.EMAIL_REGEXP, "accountCreator.organizationEmail");
Expand Down Expand Up @@ -154,6 +155,7 @@ public Account update(Account account) throws KapuaException {
// Argument validation
ArgumentValidator.notNull(account.getId(), "account.id");
ArgumentValidator.notEmptyOrNull(account.getName(), "account.name");
ArgumentValidator.match(account.getName(), CommonsValidationRegex.NAME_REGEXP, "account.name");
ArgumentValidator.notNull(account.getOrganization(), "account.organization");
ArgumentValidator.match(account.getOrganization().getEmail(), CommonsValidationRegex.EMAIL_REGEXP, "account.organization.email");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ public Credential update(Credential credential)
ArgumentValidator.notNull(credential.getCredentialType(), "credential.credentialType");
ArgumentValidator.notEmptyOrNull(credential.getCredentialKey(), "credential.credentialKey");

if (CredentialType.PASSWORD == credential.getCredentialType()) {
// Validate Password length
int minPasswordLength = getMinimumPasswordLength(credential.getScopeId());
if (credential.getCredentialKey().length() < minPasswordLength) {
throw new KapuaPasswordTooShortException(minPasswordLength);
}
if (credential.getCredentialKey().length() > SYSTEM_MAXIMUM_PASSWORD_LENGTH) {
throw new KapuaPasswordTooLongException(SYSTEM_MAXIMUM_PASSWORD_LENGTH);
}

//
// Validate Password regex
ArgumentValidator.match(credential.getCredentialKey(),
CommonsValidationRegex.PASSWORD_REGEXP, "credentialCreator.credentialKey");
}

//
// Check access
KapuaLocator locator = KapuaLocator.getInstance();
Expand Down