-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only show schema if user is schema owner or has table permissions
- Loading branch information
Showing
11 changed files
with
436 additions
and
8 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...lkit/src/main/java/io/prestosql/plugin/base/security/AnyCatalogSchemaPermissionsRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.prestosql.plugin.base.security; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
public class AnyCatalogSchemaPermissionsRule | ||
{ | ||
private final Optional<Pattern> userRegex; | ||
private final Optional<Pattern> groupRegex; | ||
private final Optional<Pattern> catalogRegex; | ||
private final Optional<Pattern> schemaRegex; | ||
|
||
public AnyCatalogSchemaPermissionsRule(Optional<Pattern> userRegex, Optional<Pattern> groupRegex, Optional<Pattern> catalogRegex, Optional<Pattern> schemaRegex) | ||
{ | ||
this.userRegex = userRegex; | ||
this.groupRegex = groupRegex; | ||
this.catalogRegex = catalogRegex; | ||
this.schemaRegex = schemaRegex; | ||
} | ||
|
||
public boolean match(String user, Set<String> groups, String catalogName, String schemaName) | ||
{ | ||
return userRegex.map(regex -> regex.matcher(user).matches()).orElse(true) && | ||
groupRegex.map(regex -> groups.stream().anyMatch(group -> regex.matcher(group).matches())).orElse(true) && | ||
catalogRegex.map(regex -> regex.matcher(catalogName).matches()).orElse(true) && | ||
schemaRegex.map(regex -> regex.matcher(schemaName).matches()).orElse(true); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AnyCatalogSchemaPermissionsRule that = (AnyCatalogSchemaPermissionsRule) o; | ||
return patternEquals(userRegex, that.userRegex) && | ||
patternEquals(groupRegex, that.groupRegex) && | ||
patternEquals(catalogRegex, that.catalogRegex) && | ||
patternEquals(schemaRegex, that.schemaRegex); | ||
} | ||
|
||
private static boolean patternEquals(Optional<Pattern> left, Optional<Pattern> right) | ||
{ | ||
if (left.isEmpty() || right.isEmpty()) { | ||
return left.isEmpty() == right.isEmpty(); | ||
} | ||
Pattern leftPattern = left.get(); | ||
Pattern rightPattern = right.get(); | ||
return leftPattern.pattern().equals(rightPattern.pattern()) && leftPattern.flags() == rightPattern.flags(); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(userRegex, groupRegex, catalogRegex, schemaRegex); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...gin-toolkit/src/main/java/io/prestosql/plugin/base/security/AnySchemaPermissionsRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.prestosql.plugin.base.security; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
public class AnySchemaPermissionsRule | ||
{ | ||
private final Optional<Pattern> userRegex; | ||
private final Optional<Pattern> groupRegex; | ||
private final Optional<Pattern> schemaRegex; | ||
|
||
public AnySchemaPermissionsRule(Optional<Pattern> userRegex, Optional<Pattern> groupRegex, Optional<Pattern> schemaRegex) | ||
{ | ||
this.userRegex = userRegex; | ||
this.groupRegex = groupRegex; | ||
this.schemaRegex = schemaRegex; | ||
} | ||
|
||
public boolean match(String user, Set<String> groups, String schemaName) | ||
{ | ||
return userRegex.map(regex -> regex.matcher(user).matches()).orElse(true) && | ||
groupRegex.map(regex -> groups.stream().anyMatch(group -> regex.matcher(group).matches())).orElse(true) && | ||
schemaRegex.map(regex -> regex.matcher(schemaName).matches()).orElse(true); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AnySchemaPermissionsRule that = (AnySchemaPermissionsRule) o; | ||
return patternEquals(userRegex, that.userRegex) && | ||
patternEquals(groupRegex, that.groupRegex) && | ||
patternEquals(schemaRegex, that.schemaRegex); | ||
} | ||
|
||
private static boolean patternEquals(Optional<Pattern> left, Optional<Pattern> right) | ||
{ | ||
if (left.isEmpty() || right.isEmpty()) { | ||
return left.isEmpty() == right.isEmpty(); | ||
} | ||
Pattern leftPattern = left.get(); | ||
Pattern rightPattern = right.get(); | ||
return leftPattern.pattern().equals(rightPattern.pattern()) && leftPattern.flags() == rightPattern.flags(); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(userRegex, groupRegex, schemaRegex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.