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

added security #6

Merged
merged 3 commits into from
Sep 8, 2023
Merged

added security #6

merged 3 commits into from
Sep 8, 2023

Conversation

fmIst0
Copy link
Owner

@fmIst0 fmIst0 commented Sep 4, 2023

Added User entity,
Added Role entity,
Added the required DTOs and mapper,
Added AuthenticationController with the following methods:

  • public UserLoginResponseDto login(UserLoginRequestDto request)
  • public UserResponseDto register(UserRegistrationRequestDto request) throws RegistrationException,
    Added FieldMatch annotation for checking that password and repeatPassword field in the UserRegistrationRequestDto are the same
    RegistrationException and EntityNotFoundException handled using the GlobalExceptionHandler,
    Addedthe JWT support to your application

Comment on lines 24 to 25
@NotBlank
@Size(min = 6, max = 100)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@NotBlank
@Size(min = 6, max = 100)

@Data
public class UserLoginRequestDto {
@Email(message = "Email is not valid",
regexp = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this regexp?

@SQLDelete(sql = "UPDATE roles SET is_deleted=true WHERE id=?")
@Where(clause = "is_deleted=false")
@Table(name = "roles")
public class Role {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add equals/hashCode

Comment on lines 9 to 12
@Query("FROM User u JOIN FETCH u.roles r "
+ "WHERE u.email = :email "
+ "AND u.isDeleted=FALSE "
+ "AND r.isDeleted=FALSE")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Query("FROM User u JOIN FETCH u.roles r "
+ "WHERE u.email = :email "
+ "AND u.isDeleted=FALSE "
+ "AND r.isDeleted=FALSE")
@EntityGraph(attributePaths = "roles")

Comment on lines 42 to 48
Role adminRole = roleRepository.findRoleByName(Role.RoleName.ADMIN)
.orElseThrow(() -> new RegistrationException("Can't find role by name"));
Set<Role> roles = new HashSet<>();
if (user.getEmail().startsWith("admin")) {
roles.add(userRole);
roles.add(adminRole);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Role adminRole = roleRepository.findRoleByName(Role.RoleName.ADMIN)
.orElseThrow(() -> new RegistrationException("Can't find role by name"));
Set<Role> roles = new HashSet<>();
if (user.getEmail().startsWith("admin")) {
roles.add(userRole);
roles.add(adminRole);
}

@fmIst0 fmIst0 requested a review from Rommelua September 5, 2023 10:55
@fmIst0 fmIst0 merged commit 299a3cc into master Sep 8, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants