public BasicAuthorizerPermission( ResourceAction resourceAction ) { this.resourceAction = resourceAction; try { this.resourceNamePattern = Pattern.compile(resourceAction.getResource().getName()); } catch (PatternSyntaxException pse) { throw new BasicSecurityDBResourceException( pse, "Invalid permission, resource name regex[%s] does not compile.", resourceAction.getResource().getName() ); } }
private boolean permissionCheck(Resource resource, Action action, BasicAuthorizerPermission permission) { if (action != permission.getResourceAction().getAction()) { return false; } Resource permissionResource = permission.getResourceAction().getResource(); if (permissionResource.getType() != resource.getType()) { return false; } Pattern resourceNamePattern = permission.getResourceNamePattern(); Matcher resourceNameMatcher = resourceNamePattern.matcher(resource.getName()); return resourceNameMatcher.matches(); }
@Override public Authorizer getAuthorizer(String name) { return (authenticationResult, resource, action) -> { if (authenticationResult.getIdentity().equals("druid")) { return Access.OK; } else { if (resource.getName().equals("datasource2")) { return new Access(false, "not authorized."); } else { return Access.OK; } } }; } }
@Override public Authorizer getAuthorizer(String name) { return (authenticationResult, resource, action) -> { if (authenticationResult.getIdentity().equals(TEST_SUPERUSER_NAME)) { return Access.OK; } if (resource.getType() == ResourceType.DATASOURCE && resource.getName().equals(FORBIDDEN_DATASOURCE)) { return new Access(false); } else { return Access.OK; } }; } };
public BasicAuthorizerPermission( ResourceAction resourceAction ) { this.resourceAction = resourceAction; try { this.resourceNamePattern = Pattern.compile(resourceAction.getResource().getName()); } catch (PatternSyntaxException pse) { throw new BasicSecurityDBResourceException( pse, "Invalid permission, resource name regex[%s] does not compile.", resourceAction.getResource().getName() ); } }
private boolean permissionCheck(Resource resource, Action action, BasicAuthorizerPermission permission) { if (action != permission.getResourceAction().getAction()) { return false; } Resource permissionResource = permission.getResourceAction().getResource(); if (permissionResource.getType() != resource.getType()) { return false; } Pattern resourceNamePattern = permission.getResourceNamePattern(); Matcher resourceNameMatcher = resourceNamePattern.matcher(resource.getName()); return resourceNameMatcher.matches(); }