Java library for Aserto services
Warning
0.31.1 is the latest version published to maven central. Versions starting with 1.0.z have been removed from maven central and are no longer available for download.
mvn clean install
- add the fallowing dependency to your
pom.xml
file
<dependency>
<groupId>com.aserto</groupId>
<artifactId>aserto-java</artifactId>
</dependency>
mvn clean test
In order to run integration tests we need to have topaz installed
go install github.com/topaz/cmd/topaz@latest
topaz install
The integration tests start topaz and configure it for testing. The tests will fail if topaz is not installed. If you have topaz configured, no worries, the tests will save the configuration and restore it after the integration tests are finished. To run the integration tests use the fallowing command:
mvn test -Pintegration
mvn clean deploy -Dgpg.passphrase="<gpg-passphrase>" -Pci-cd
Start topaz
// create a channel that has the connection details
ManagedChannel channel = new ChannelBuilder()
.withHost("localhost")
.withPort(8282)
.withInsecure(true)
.build();
// create authz client
AuthorizerClient authzClient = new AuthzClient(channel);
// identity context contains information abou the user that requests access to some resource
IdentityCtx identityCtx = new IdentityCtx("rick@the-citadel.com", IdentityType.IDENTITY_TYPE_SUB);
// contains information about the policy we want to check for the provided identity
PolicyCtx policyCtx = new PolicyCtx("todo", "todo", "todoApp.DELETE.todos.__id", new String[]{"allowed"});
// check if the identity is allowed to perform the action
List<Decision> decisions = authzClient.is(identityCtx, policyCtx);
authzClient.close();
decisions.forEach(decision -> {
String dec = decision.getDecision();
boolean isAllowed = decision.getIs();
System.out.println("For decision [" + dec + "] the answer was [" + isAllowed + "]");
});
For more examples have a look in the examples folder.