Skip to content

Commit

Permalink
v3 Directory client
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie authored Nov 28, 2023
1 parent fe2074c commit 1fe4fd4
Show file tree
Hide file tree
Showing 25 changed files with 1,592 additions and 122 deletions.
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

0 comments on commit 1fe4fd4

Please sign in to comment.