44. User authorities (#4 Section 6: User Registration)
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
package net.shyshkin.study.fullstack.supportportal.backend.constant;
|
||||
|
||||
public class Authority {
|
||||
|
||||
public static final String[] USER_AUTHORITIES = {"user:read"};
|
||||
public static final String[] HR_AUTHORITIES = {"user:read", "user:update"};
|
||||
public static final String[] MANAGER_AUTHORITIES = {"user:read", "user:update"};
|
||||
public static final String[] ADMIN_AUTHORITIES = {"user:read", "user:create", "user:update"};
|
||||
public static final String[] SUPER_ADMIN_AUTHORITIES = {"user:read", "user:create", "user:update", "user:delete"};
|
||||
|
||||
}
|
||||
@ -35,7 +35,7 @@ public class User implements Serializable {
|
||||
private LocalDateTime lastLoginDate;
|
||||
private LocalDateTime lastLoginDateDisplay;
|
||||
private LocalDateTime joinDate;
|
||||
private String[] roles; //ROLE_USER, ROLE_ADMIN
|
||||
private String role; //ROLE_USER, ROLE_ADMIN
|
||||
private String[] authorities;
|
||||
private boolean isActive;
|
||||
private boolean isNotLocked;
|
||||
|
||||
@ -19,11 +19,7 @@ public class UserPrincipal implements UserDetails {
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
|
||||
return Stream
|
||||
.concat(
|
||||
Stream.of(user.getRoles()),
|
||||
Stream.of(user.getAuthorities())
|
||||
)
|
||||
return Stream.of(user.getAuthorities())
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public abstract class BaseUserTest {
|
||||
.profileImageUrl("http://url_to_profile_img")
|
||||
.lastLoginDate(LocalDateTime.now())
|
||||
.lastLoginDateDisplay(LocalDateTime.now())
|
||||
.roles(new String[]{"ROLE_ADMIN", "ROLE_USER"})
|
||||
.role("ROLE_ADMIN")
|
||||
.authorities(new String[]{"user:delete", "user:read"})
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class UserPrincipalTest extends BaseUserTest {
|
||||
void displayUser() {
|
||||
//given
|
||||
Long id = user.getId();
|
||||
int expectedAuthoritiesLength = user.getAuthorities().length + user.getRoles().length;
|
||||
int expectedAuthoritiesLength = user.getAuthorities().length ;
|
||||
|
||||
//when
|
||||
Optional<User> savedUserOptional = userRepository.findById(id);
|
||||
|
||||
Reference in New Issue
Block a user