use of org.apache.druid.security.basic.authorization.entity.BasicAuthorizerPermission in project druid by druid-io.
the class BasicRoleBasedAuthorizer method authorize.
@Override
@SuppressWarnings("unchecked")
public Access authorize(AuthenticationResult authenticationResult, Resource resource, Action action) {
if (authenticationResult == null) {
throw new IAE("authenticationResult is null where it should never be.");
}
Set<String> roleNames = new HashSet<>(roleProvider.getRoles(name, authenticationResult));
Map<String, BasicAuthorizerRole> roleMap = roleProvider.getRoleMap(name);
if (roleNames.isEmpty()) {
return new Access(false);
}
if (roleMap == null) {
throw new IAE("Could not load roleMap for authorizer [%s]", name);
}
for (String roleName : roleNames) {
BasicAuthorizerRole role = roleMap.get(roleName);
if (role != null) {
for (BasicAuthorizerPermission permission : role.getPermissions()) {
if (permissionCheck(resource, action, permission)) {
return new Access(true);
}
}
}
}
return new Access(false);
}
Aggregations