Commit c0d25a19 by Jan Hrabal

x

parent 15e1a975
package com.jh.boot.security; package com.jh.boot.security;
import java.util.Set;
import java.util.stream.Collectors;
import com.jh.boot.security.model.AppRole;
import com.jh.boot.security.model.AppUser; import com.jh.boot.security.model.AppUser;
public class SecurityHelper { public class SecurityHelper {
public static final String ADMIN_ROLE = "ROLE_ADMIM";
private SecurityHelper() { private SecurityHelper() {
} }
public boolean hasRole(AppUser user, String...roles) { public boolean hasAnyRole(AppUser user, String...roles) {
if (user == null || user.getRoles() == null || roles == null || roles.length == 0) {
return false;
}
Set<String> set = user.getRoles().stream().map(AppRole::getName).collect(Collectors.toSet());
if (set.contains(ADMIN_ROLE)) {
return true;
}
for (String role : roles) {
if (set.contains(role)) {
return true; return true;
} }
}
return false;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment