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

v3 Directory client #20

Merged
merged 26 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0625d62
Add DirectoryClient interface.
BogdanIrimie Nov 10, 2023
89522b6
Add Interfaces for directory clients.
BogdanIrimie Nov 15, 2023
0a296d2
Add getGraph to the directory api.
BogdanIrimie Nov 16, 2023
64064d6
Rename ClientManifest interface to ClientModel.
BogdanIrimie Nov 16, 2023
83b7460
Add async model client for setManifest
BogdanIrimie Nov 16, 2023
10c39ff
Add message chunking to setManifest.
BogdanIrimie Nov 17, 2023
2ece1cf
Implement import and export interfaces,
BogdanIrimie Nov 17, 2023
06cec08
Add authorizer and directory packages
BogdanIrimie Nov 19, 2023
888c915
Add directory client example skeleton project.
BogdanIrimie Nov 19, 2023
2a2a9c3
Make ObjectIdentifierList a standalone class.
BogdanIrimie Nov 20, 2023
7f5436a
Add DirectoryExamples for get user and get users.
BogdanIrimie Nov 20, 2023
a73897b
Return GetObjectManyResponse from getObjectManyRequest
BogdanIrimie Nov 20, 2023
827d6c8
Use a builder pattern for getRelations as all the arguments are optio…
BogdanIrimie Nov 20, 2023
de60454
Add automation to start Topaz for integration tests.
BogdanIrimie Nov 22, 2023
b13ceb7
Bump to java 17
BogdanIrimie Nov 22, 2023
e7b3058
Add the v3 namespace for directory.
BogdanIrimie Nov 22, 2023
f44cd56
FIx the exporter interface and clean commented out code.
BogdanIrimie Nov 22, 2023
c29a2b0
Use a builder pattern for getGraph api.
BogdanIrimie Nov 22, 2023
2602cc9
Add more unit tests for the directory reader api.
BogdanIrimie Nov 22, 2023
5a0053b
Set manifest after topaz is started.
BogdanIrimie Nov 23, 2023
ab279d9
Add setObjectTest. Update the setObject interface with optional fields.
BogdanIrimie Nov 23, 2023
ba8a6f0
Remove set manifest ad import data from extension.
BogdanIrimie Nov 24, 2023
d0fc13b
Use citadel users instead of generic ones in integration tests.
BogdanIrimie Nov 24, 2023
ef30768
Fix linting errors.
BogdanIrimie Nov 27, 2023
f811ad5
Add factory for directory objects, relations and object identifiers.
BogdanIrimie Nov 27, 2023
3880274
Rename Factory to Directory
BogdanIrimie Nov 28, 2023
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
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ jobs:
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: 8
java-version: 17
distribution: temurin

- name: Run tests
run: mvn clean test
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Install topaz
run: brew tap aserto-dev/tap && brew install aserto-dev/tap/topaz && topaz install

- name: Run all tests
run: mvn clean test -Pintegration
release:
runs-on: ubuntu-latest
needs: build
Expand Down
38 changes: 38 additions & 0 deletions examples/directory-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
54 changes: 54 additions & 0 deletions examples/directory-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>directory-example</artifactId>
<version>0.0.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.aserto</groupId>
<artifactId>aserto-java</artifactId>
<version>0.20.10</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.DirectoryExample</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.example;

import com.aserto.ChannelBuilder;
import com.aserto.directory.v3.DirectoryClient;
import com.aserto.directory.common.v3.ObjectIdentifier;
import com.aserto.directory.reader.v3.GetObjectManyResponse;
import com.aserto.directory.reader.v3.GetObjectResponse;
import com.aserto.directory.reader.v3.GetObjectsResponse;
import com.aserto.directory.v3.Directory;
import io.grpc.ManagedChannel;

import javax.net.ssl.SSLException;
import java.util.List;

public class DirectoryExample {
public static void main(String[] args) throws SSLException {
// create a channel that has the connection details
ManagedChannel channel = new ChannelBuilder()
.withHost("localhost")
.withPort(9292)
.withInsecure(true)
.build();

// create a directory client that wil be used to interact with the directory
DirectoryClient directoryClient = new DirectoryClient(channel);

getUserExample(directoryClient);
getUsersExample(directoryClient);
getObjectManyRequest(directoryClient);
}

public static void getUserExample(DirectoryClient directoryClient) {
System.out.println("------ Get user example ------");
GetObjectResponse getObjectResponse = directoryClient.getObject("user", "[email protected]", false);
System.out.println(getObjectResponse);
}

public static void getUsersExample(DirectoryClient directoryClient) {
System.out.println("------ Get users example ------");
GetObjectsResponse getObjectsResponse = directoryClient.getObjects("user", 100, "");
System.out.println(getObjectsResponse);
}

public static void getObjectManyRequest(DirectoryClient directoryClient) {
System.out.println("------ Get object many example ------");
List<ObjectIdentifier> objects = List.of(
Directory.buildObjectIdentifier("user", "[email protected]"),
Directory.buildObjectIdentifier("user", "[email protected]"));

GetObjectManyResponse getObjectManyRequest = directoryClient.getObjectManyRequest(objects);
System.out.println(getObjectManyRequest);
}
}
34 changes: 23 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.aserto</groupId>
<artifactId>aserto-java</artifactId>
<version>0.20.9</version>
<version>0.20.10</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Java SDK to interact with aserto services</description>
Expand Down Expand Up @@ -37,37 +37,37 @@
</scm>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<grpc.version>1.58.0</grpc.version>
<grpc.version>1.59.0</grpc.version>
<exclude-tests>IntegrationTest</exclude-tests>
</properties>

<dependencies>
<dependency>
<groupId>com.aserto</groupId>
<artifactId>java-authorizer</artifactId>
<version>0.20.6</version>
<version>0.20.7</version>
</dependency>
<dependency>
<groupId>com.aserto</groupId>
<artifactId>java-directory</artifactId>
<version>0.0.1</version>
<version>0.30.1</version>
</dependency>

<!-- Used for unit testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.10.0</version>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -83,6 +83,18 @@
<version>3.12.4</version>
<scope>test</scope>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.21.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.21.1</version>
</dependency>
</dependencies>

<profiles>
Expand Down Expand Up @@ -174,7 +186,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.2</version>
<configuration>
<excludedGroups>${exclude-tests}</excludedGroups>
</configuration>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/aserto/ChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public ManagedChannel build() throws SSLException {
.intercept(MetadataUtils.newAttachHeadersInterceptor(metadata));

boolean insecure = cfg.getInsecure();
boolean caSpecified = !cfg.getCaCertPath().isEmpty();

boolean caSpecified = true;
if (cfg.getCaCertPath() == null || cfg.getCaCertPath().isEmpty()) {
caSpecified = false;
}

if (insecure) {
SslContext context = GrpcSslContexts.forClient()
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/com/aserto/DirectoryClient.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aserto;
package com.aserto.authorizer;

import com.aserto.AuthorizerClient;
import com.aserto.authorizer.v2.*;
import com.aserto.authorizer.v2.Decision;
import com.aserto.authorizer.v2.api.*;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/aserto/directory/v3/Directory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.aserto.directory.v3;

import com.aserto.directory.common.v3.Object;
import com.aserto.directory.common.v3.ObjectIdentifier;
import com.aserto.directory.common.v3.Relation;

public class Directory {

public static Object buildObject(String type, String id) {
return Object.newBuilder().setType(type).setId(id).build();
}

public static ObjectIdentifier buildObjectIdentifier(String type, String id) {
return ObjectIdentifier.newBuilder().setObjectType(type).setObjectId(id).build();
}

public static Relation buildRelation(String objectType, String objectId, String relation, String subjectType, String subjectId) {
return Relation.newBuilder()
.setObjectType(objectType)
.setObjectId(objectId)
.setRelation(relation)
.setSubjectType(subjectType)
.setSubjectId(subjectId)
.build();
}
}
Loading