Skip to content

Commit db94b25

Browse files
AYS-903 Resolve SonarQube Issues (#482)
1 parent 84c411e commit db94b25

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/main/java/org/ays/auth/service/impl/AysPermissionServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.stereotype.Service;
99

1010
import java.util.List;
11-
import java.util.stream.Collectors;
1211

1312
/**
1413
* Service implementation for managing permissions.
@@ -22,7 +21,6 @@ class AysPermissionServiceImpl implements AysPermissionService {
2221

2322
private final AysIdentity identity;
2423

25-
2624
/**
2725
* Retrieves a filtered list of permissions based on the user's identity.
2826
* <p>
@@ -39,12 +37,12 @@ public List<AysPermission> findAll() {
3937
if (identity.isSuperAdmin()) {
4038
return permissionReadPort.findAll().stream()
4139
.filter(permission -> !"landing:page".equals(permission.getName()))
42-
.collect(Collectors.toList());
40+
.toList();
4341
}
4442

4543
return permissionReadPort.findAllByIsSuperFalse().stream()
4644
.filter(permission -> !"landing:page".equals(permission.getName()))
47-
.collect(Collectors.toList());
45+
.toList();
4846
}
4947

5048
}

src/main/java/org/ays/common/util/AysRandomUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static String generateUUID() {
6060
/**
6161
* Utility method to generate a random alphabetic string of the specified length.
6262
* <p>
63-
* This method uses the {@link RandomStringUtils#randomAlphabetic(int)} to generate a string
63+
* This method uses the {@link RandomStringUtils#secure().nextAlphabetic(int)} to generate a string
6464
* containing random alphabetic characters (a-z, A-Z). The length of the generated string is
6565
* determined by the input parameter.
6666
* </p>
@@ -70,7 +70,7 @@ public static String generateUUID() {
7070
* @throws IllegalArgumentException if the specified length is negative
7171
*/
7272
public static String generateText(int length) {
73-
return RandomStringUtils.randomAlphabetic(length);
73+
return RandomStringUtils.secure().nextAlphabetic(length);
7474
}
7575

7676
}

src/main/java/org/ays/common/util/validation/NameValidator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ class NameValidator implements ConstraintValidator<Name, String> {
2222
* </ul>
2323
* It also avoids strings that start with special characters
2424
* </p>
25+
*
26+
* Regex for validating names.
27+
* Note: The "+" before the end anchor "$" is a possessive quantifier (*+).
28+
* It behaves like "*" but disallows backtracking, which prevents
29+
* catastrophic backtracking and improves performance.
30+
* The accepted matches remain the same, only execution is safer and faster.
2531
*/
26-
private static final String NAME_REGEX = "^(?!.*[ ,.'-]{2})[a-zA-ZÇçĞğİıÖöŞşÜü]+(?:[ ,.'-](?![ ,.'-])[a-zA-ZÇçĞğİıÖöŞşÜü]+)*$";
32+
private static final String NAME_REGEX = "^(?!.*[ ,.'-]{2})[a-zA-ZÇçĞğİıÖöŞşÜü]+(?:[ ,.'-](?![ ,.'-])[a-zA-ZÇçĞğİıÖöŞşÜü]+)*+$";
2733

2834
/**
2935
* Checks whether the given value is a valid name or not.

src/test/java/org/ays/auth/model/AysUserBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public AysUserBuilder withValidValues() {
2727
return this
2828
.withId(AysRandomUtil.generateUUID())
2929
.withInstitution(institution)
30-
.withEmailAddress(RandomStringUtils.randomAlphabetic(8).concat("@afetyonetimsistemi.org"))
30+
.withEmailAddress(RandomStringUtils.secure().nextAlphabetic(8).concat("@afetyonetimsistemi.org"))
3131
.withPhoneNumber(new AysPhoneNumberBuilder().withValidValues().build())
3232
.withStatus(AysUserStatus.ACTIVE)
3333
.withPassword(null)

0 commit comments

Comments
 (0)