-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implementing Security Configuration and Role Management #10
Conversation
nklimovych
commented
May 10, 2024
- Added SecurityConfig class with PasswordEncoder and SecurityFilterChain beans
- Implemented UserDetails interface in the User class.
- Added the implementation for the UserDetailsService interface.
- Added Role entity.
- Added RoleRepository.
- Added roles field to the User entity.
- Added Liquibase changesets to insert roles into DB and assign roles for users.
…in beans. Implemented UserDetails interface in the User class. Added the implementation for UserDetailsService interface. Added Role entity. Added RoleRepository. Added roles field to the User entity. Added Liquibase changesets to insert roles into DB and assign roles for users.
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.
Just some very minor comments, good job!
|
||
@Column(nullable = false, unique = true) | ||
@Enumerated(EnumType.STRING) | ||
private RoleName role; |
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.
private RoleName role; | |
private RoleName name; |
@@ -26,6 +32,8 @@ public UserResponseDto save(UserRegistrationRequestDto requestDto) | |||
|
|||
User user = userMapper.toModel(requestDto); | |||
user.setEmail(email); | |||
user.setPassword(passwordEncoder.encode(user.getPassword())); | |||
user.setRoles(roleRepository.findAllByRoles(Set.of(RoleName.USER))); |
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.
If we have hardcoded only USER
role here why wrap it into a set and do a findAll...()
? Lets simplify it
user.setRoles(roleRepository.findAllByRoles(Set.of(RoleName.USER))); | |
user.setRoles(Collections.singleton(roleRepository.findByName(RoleName.USER))); |
|
||
public interface RoleRepository extends JpaRepository<Role, Long> { | ||
|
||
@Query("SELECT r FROM Role r WHERE r.role IN :roles") |
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.
I do not think @Querry
is necessary here
@Query("SELECT r FROM Role r WHERE r.role IN :roles") |
…or the new user in the 'save' method in UserService, and replace the 'findAllByRoles' method with the 'findByName' method.