Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove generated code from git #172

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Makefile

This file was deleted.

80 changes: 70 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,72 @@
<version>3.0.0-alpha.1</version>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.1</version>
</extension>
</extensions>

<plugins>
<!-- grpc plugins -->
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<clearOutputDirectory>false</clearOutputDirectory>
<!-- Protobuf Compiler -->
<protocArtifact>com.google.protobuf:protoc:3.24.3:exe:${os.detected.classifier}</protocArtifact>
<!-- gRPC Compiler -->
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.57.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<!-- Execution for Message Classes -->
<execution>
<id>generate-protobuf-messages</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<includes>
<include>**/*.class</include>
<include>${project.build.directory}/generated-sources/**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-generated-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>test-jar</goal>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/gov/nist/csd/pm</source>
</sources>
</configuration>
</execution>
</executions>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -31,6 +85,7 @@
<configuration>
<source>21</source>
<target>21</target>
<generatedSourcesDirectory>${project.build.directory}/generated-sources</generatedSourcesDirectory>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -77,7 +132,7 @@
<version>${antlr.version}</version>
<configuration>
<sourceDirectory>src/main/java/gov/nist/csd/pm/pap/pml/antlr</sourceDirectory>
<outputDirectory>src/main/java/gov/nist/csd/pm/pap/pml/antlr</outputDirectory>
<outputDirectory>${project.build.directory}/generated-sources/gov/nist/csd/pm/pap/pml/antlr</outputDirectory>
<visitor>true</visitor>
<arguments>
<argument>-package</argument>
Expand All @@ -86,13 +141,20 @@
</configuration>
<executions>
<execution>
<id>generate-antlr-sources</id>
<goals>
<goal>antlr4</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/gov/nist/csd/pm/pap/pml/antlr</outputDirectory>
<sourceDirectory>src/main/java/gov/nist/csd/pm/pap/pml/antlr</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

</build>

<dependencies>
Expand Down Expand Up @@ -134,22 +196,20 @@
<version>8.5.13</version>
</dependency>

<!-- grpc deps -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.67.1</version>
<scope>runtime</scope>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.24.3</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.67.1</version>
<version>1.57.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.67.1</version>
<version>1.57.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/gov/nist/csd/pm/pap/obligation/EventContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,24 @@ public class EventContext {
private final String process;
private final String opName;
private final Map<String, Object> operands;
private final List<String> nodeOperands;

public EventContext(String user, String process, String opName, Map<String, Object> operands, List<String> nodeOperands) {
public EventContext(String user, String process, String opName, Map<String, Object> operands) {
this.user = user;
this.process = process;
this.opName = opName;
this.operands = operands;
this.nodeOperands = nodeOperands;
}

public EventContext(String user, String opName, Map<String, Object> operands, List<String> nodeOperands) {
this(user, null, opName, operands, nodeOperands);
public EventContext(String user, String opName, Map<String, Object> operands) {
this(user, null, opName, operands);
}

public EventContext(String user, String process, Operation<?> op, Map<String, Object> operands) {
this(user, process, op.getName(), operands, op.getNodeOperands());
this(user, process, op.getName(), operands);
}

public EventContext(String user, Operation<?> op, Map<String, Object> operands) {
this(user, null, op.getName(), operands, op.getNodeOperands());
}

public EventContext(String user, String opName, Map<String, Object> operands) {
this(user, null, opName, operands, List.of());
this(user, null, op.getName(), operands);
}

public String user() {
Expand All @@ -54,20 +48,16 @@ public Map<String, Object> operands() {
return operands;
}

public List<String> nodeOperands() {
return nodeOperands;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof EventContext that)) return false;
return Objects.equals(user, that.user) && Objects.equals(process, that.process) && Objects.equals(opName, that.opName) && Objects.equals(operands, that.operands) && Objects.equals(nodeOperands, that.nodeOperands);
return Objects.equals(user, that.user) && Objects.equals(process, that.process) && Objects.equals(opName, that.opName) && Objects.equals(operands, that.operands);
}

@Override
public int hashCode() {
return Objects.hash(user, process, opName, operands, nodeOperands);
return Objects.hash(user, process, opName, operands);
}

@Override
Expand All @@ -77,7 +67,6 @@ public String toString() {
", process='" + process + '\'' +
", opName='" + opName + '\'' +
", operands=" + operands +
", nodeOperands=" + nodeOperands +
'}';
}
}
17 changes: 15 additions & 2 deletions src/main/java/gov/nist/csd/pm/pap/obligation/EventPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gov.nist.csd.pm.pap.exception.PMException;
import gov.nist.csd.pm.pap.PAP;
import gov.nist.csd.pm.pap.op.Operation;
import gov.nist.csd.pm.pap.pml.pattern.OperationPattern;
import gov.nist.csd.pm.pap.pml.pattern.operand.OperandPatternExpression;
import gov.nist.csd.pm.pap.pml.pattern.subject.SubjectPattern;
Expand Down Expand Up @@ -60,7 +61,7 @@ public boolean matches(EventContext eventCtx, PAP pap) throws PMException {
return userMatches;
}

boolean operandsMatch = operandsMatch(eventCtx.operands(), eventCtx.nodeOperands(), pap);
boolean operandsMatch = operandsMatch(eventCtx.opName(), eventCtx.operands(), pap);

return userMatches && opMatches && operandsMatch;
}
Expand Down Expand Up @@ -97,7 +98,10 @@ private boolean operationMatches(String opName, PAP pap) throws PMException {
return operationPattern.matches(opName, pap);
}

private boolean operandsMatch(Map<String, Object> operands, List<String> nodeOperands, PAP pap) throws PMException {
private boolean operandsMatch(String opName, Map<String, Object> operands, PAP pap) throws PMException {
// get the operands of the operation that represent nodes
List<String> nodeOperands = getOperationNodeOperands(opName, pap);

// if more patterns than operands - false
// if no patterns - true (match everything)
if (operandPatterns.size() > operands.size()) {
Expand Down Expand Up @@ -137,4 +141,13 @@ private boolean operandsMatch(Map<String, Object> operands, List<String> nodeOpe

return true;
}

private List<String> getOperationNodeOperands(String opName, PAP pap) throws PMException {
if (pap.query().operations().getResourceOperations().contains(opName)) {
return List.of("target");
}

Operation<?> adminOperation = pap.query().operations().getAdminOperation(opName);
return adminOperation.getNodeOperands();
}
}
Loading