-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permission visitor normalization (#2035)
* add normalization vistior for permission expression * Change PermissionToFilterPredicate to work on normalized expression * add copyright * fix checkstyle * add comments Co-authored-by: Chandrasekar Rajasekar <[email protected]> Co-authored-by: Aaron Klish <[email protected]>
- Loading branch information
1 parent
53b2333
commit e64bd8e
Showing
14 changed files
with
372 additions
and
38 deletions.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
...rc/main/java/com/yahoo/elide/core/security/permissions/expressions/ExpressionVisitor.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,19 @@ | ||
/* | ||
* Copyright 2021, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
|
||
package com.yahoo.elide.core.security.permissions.expressions; | ||
|
||
/** | ||
* Visitor which walks the permission expression abstract syntax tree. | ||
* @param <T> The return type of the visitor | ||
*/ | ||
public interface ExpressionVisitor<T> { | ||
T visitExpression(Expression expression); | ||
T visitCheckExpression(CheckExpression checkExpression); | ||
T visitAndExpression(AndExpression andExpression); | ||
T visitOrExpression(OrExpression orExpression); | ||
T visitNotExpression(NotExpression notExpression); | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...java/com/yahoo/elide/core/security/visitors/PermissionExpressionNormalizationVisitor.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,65 @@ | ||
/* | ||
* Copyright 2021, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
|
||
package com.yahoo.elide.core.security.visitors; | ||
|
||
import com.yahoo.elide.core.security.permissions.expressions.AndExpression; | ||
import com.yahoo.elide.core.security.permissions.expressions.CheckExpression; | ||
import com.yahoo.elide.core.security.permissions.expressions.Expression; | ||
import com.yahoo.elide.core.security.permissions.expressions.ExpressionVisitor; | ||
import com.yahoo.elide.core.security.permissions.expressions.NotExpression; | ||
import com.yahoo.elide.core.security.permissions.expressions.OrExpression; | ||
|
||
/** | ||
* Expression Visitor to normalize Permission expression. | ||
*/ | ||
public class PermissionExpressionNormalizationVisitor implements ExpressionVisitor<Expression> { | ||
@Override | ||
public Expression visitExpression(Expression expression) { | ||
return expression; | ||
} | ||
|
||
@Override | ||
public Expression visitCheckExpression(CheckExpression checkExpression) { | ||
return checkExpression; | ||
} | ||
|
||
@Override | ||
public Expression visitAndExpression(AndExpression andExpression) { | ||
Expression left = andExpression.getLeft(); | ||
Expression right = andExpression.getRight(); | ||
return new AndExpression(left.accept(this), right.accept(this)); | ||
} | ||
|
||
@Override | ||
public Expression visitOrExpression(OrExpression orExpression) { | ||
Expression left = orExpression.getLeft(); | ||
Expression right = orExpression.getRight(); | ||
return new OrExpression(left.accept(this), right.accept(this)); | ||
} | ||
|
||
@Override | ||
public Expression visitNotExpression(NotExpression notExpression) { | ||
Expression inner = notExpression.getLogical(); | ||
if (inner instanceof AndExpression) { | ||
AndExpression and = (AndExpression) inner; | ||
Expression left = new NotExpression(and.getLeft()).accept(this); | ||
Expression right = new NotExpression(and.getRight()).accept(this); | ||
return new OrExpression(left, right); | ||
} | ||
if (inner instanceof OrExpression) { | ||
OrExpression or = (OrExpression) inner; | ||
Expression left = new NotExpression(or.getLeft()).accept(this); | ||
Expression right = new NotExpression(or.getRight()).accept(this); | ||
return new AndExpression(left, right); | ||
} | ||
if (inner instanceof NotExpression) { | ||
NotExpression not = (NotExpression) inner; | ||
return (not.getLogical()).accept(this); | ||
} | ||
return notExpression; | ||
} | ||
} |
Oops, something went wrong.