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 lastLoginDate;
|
||||||
private LocalDateTime lastLoginDateDisplay;
|
private LocalDateTime lastLoginDateDisplay;
|
||||||
private LocalDateTime joinDate;
|
private LocalDateTime joinDate;
|
||||||
private String[] roles; //ROLE_USER, ROLE_ADMIN
|
private String role; //ROLE_USER, ROLE_ADMIN
|
||||||
private String[] authorities;
|
private String[] authorities;
|
||||||
private boolean isActive;
|
private boolean isActive;
|
||||||
private boolean isNotLocked;
|
private boolean isNotLocked;
|
||||||
|
|||||||
@ -19,11 +19,7 @@ public class UserPrincipal implements UserDetails {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
|
||||||
return Stream
|
return Stream.of(user.getAuthorities())
|
||||||
.concat(
|
|
||||||
Stream.of(user.getRoles()),
|
|
||||||
Stream.of(user.getAuthorities())
|
|
||||||
)
|
|
||||||
.map(SimpleGrantedAuthority::new)
|
.map(SimpleGrantedAuthority::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public abstract class BaseUserTest {
|
|||||||
.profileImageUrl("http://url_to_profile_img")
|
.profileImageUrl("http://url_to_profile_img")
|
||||||
.lastLoginDate(LocalDateTime.now())
|
.lastLoginDate(LocalDateTime.now())
|
||||||
.lastLoginDateDisplay(LocalDateTime.now())
|
.lastLoginDateDisplay(LocalDateTime.now())
|
||||||
.roles(new String[]{"ROLE_ADMIN", "ROLE_USER"})
|
.role("ROLE_ADMIN")
|
||||||
.authorities(new String[]{"user:delete", "user:read"})
|
.authorities(new String[]{"user:delete", "user:read"})
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class UserPrincipalTest extends BaseUserTest {
|
|||||||
void displayUser() {
|
void displayUser() {
|
||||||
//given
|
//given
|
||||||
Long id = user.getId();
|
Long id = user.getId();
|
||||||
int expectedAuthoritiesLength = user.getAuthorities().length + user.getRoles().length;
|
int expectedAuthoritiesLength = user.getAuthorities().length ;
|
||||||
|
|
||||||
//when
|
//when
|
||||||
Optional<User> savedUserOptional = userRepository.findById(id);
|
Optional<User> savedUserOptional = userRepository.findById(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user