com.github.angdx.gs.voter.PrefixRoleVoter Maven / Gradle / Ivy
package com.github.angdx.gs.voter;
import com.github.angdx.gs.configattr.RoleGrantAttribute;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.FilterInvocation;
import java.util.Collection;
public class PrefixRoleVoter implements RBACAccessDecisionVoter {
@Override
public boolean supports(ConfigAttribute attribute) {
return (attribute.getAttribute() != null)
&& attribute.getAttribute().startsWith(RoleGrantAttribute.PREFIX);
}
@Override
public boolean supports(Class> clazz) {
return true;
}
@Override
public int vote(Authentication authentication, FilterInvocation object, Collection attributes) {
if(authentication == null) {
return ACCESS_DENIED;
}
int result = ACCESS_DENIED;
Collection extends GrantedAuthority> authorities = extractAuthorities(authentication);
for (ConfigAttribute attribute : attributes) {
if (this.supports(attribute)) {
// result = ACCESS_DENIED;
for (GrantedAuthority authority : authorities) {
if (attribute.getAttribute().equals(authority.getAuthority())) {
return ACCESS_GRANTED;
}
}
}
}
return result;
}
private Collection extends GrantedAuthority> extractAuthorities(
Authentication authentication) {
return authentication.getAuthorities();
}
@Override
public boolean passGreenChannel() {
return false;
}
@Override
public boolean denyGreenChannel() {
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy