Skip to content

Commit

Permalink
Merge pull request #18 from permitio/asaf/cto-147-salt-urgent-help-wi…
Browse files Browse the repository at this point in the history
…th-production-deployment

More accurate exceptions + get user tenants from the PDP
  • Loading branch information
Asaf Cohen authored Nov 7, 2023
2 parents c388a80 + 6682587 commit c5aeb66
Showing 7 changed files with 286 additions and 216 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ For [Maven](https://maven.apache.org/) projects, use:
<dependency>
<groupId>io.permit</groupId>
<artifactId>permit-sdk-java</artifactId>
<version>1.4.0</version>
<version>2.0.0</version>
</dependency>
```

@@ -24,7 +24,7 @@ For [Gradle](https://gradle.org/) projects, configure `permit-sdk-java` as a dep
dependencies {
// ...
implementation 'io.permit:permit-sdk-java:1.4.0'
implementation 'io.permit:permit-sdk-java:2.0.0'
}
```

@@ -148,6 +148,6 @@ CreateOrUpdateResult<UserRead> result = permit.api.users.sync(new UserCreate("[U

## Javadoc reference

To view the javadoc reference, [click here](https://javadoc.io/doc/io.permit/permit-sdk-java/1.4.0/index.html).
To view the javadoc reference, [click here](https://javadoc.io/doc/io.permit/permit-sdk-java/2.0.0/index.html).

It's easiest to start with the root [Permit](https://javadoc.io/static/io.permit/permit-sdk-java/1.4.0/io/permit/sdk/Permit.html) class.
It's easiest to start with the root [Permit](https://javadoc.io/static/io.permit/permit-sdk-java/2.0.0/io/permit/sdk/Permit.html) class.
33 changes: 23 additions & 10 deletions src/main/java/io/permit/sdk/Permit.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import com.google.gson.GsonBuilder;
import io.permit.sdk.api.ApiClient;
import io.permit.sdk.api.ElementsApi;
import io.permit.sdk.api.PermitApiError;
import io.permit.sdk.enforcement.*;
import io.permit.sdk.util.Context;

@@ -104,10 +105,11 @@ public Permit(PermitConfig config) {
* @param resource The resource object representing the resource.
* @param context The context object representing the context in which the action is performed.
* @return {@code true} if the user is authorized, {@code false} otherwise.
* @throws IOException if an error occurs while checking the authorization.
* @throws PermitApiError if an error occurs while sending the authorization request to the PDP.
* @throws IOException if could not read the content of the returned http response.
*/
@Override
public boolean check(User user, String action, Resource resource, Context context) throws IOException {
public boolean check(User user, String action, Resource resource, Context context) throws IOException, PermitApiError {
return this.enforcer.check(user, action, resource, context);
}

@@ -119,40 +121,51 @@ public boolean check(User user, String action, Resource resource, Context contex
* @param action The action to be performed on the resource.
* @param resource The resource object representing the resource.
* @return {@code true} if the user is authorized, {@code false} otherwise.
* @throws IOException if an error occurs while checking the authorization.
* @throws PermitApiError if an error occurs while sending the authorization request to the PDP.
* @throws IOException if could not read the content of the returned http response.
*/
@Override
public boolean check(User user, String action, Resource resource) throws IOException {
public boolean check(User user, String action, Resource resource) throws IOException, PermitApiError {
return this.enforcer.check(user, action, resource);
}

@Override
public boolean checkUrl(User user, String httpMethod, String url, String tenant, Context context) throws IOException {
public boolean checkUrl(User user, String httpMethod, String url, String tenant, Context context) throws IOException, PermitApiError {
return this.enforcer.checkUrl(user, httpMethod, url, tenant, context);
}

@Override
public boolean checkUrl(User user, String httpMethod, String url, String tenant) throws IOException {
public boolean checkUrl(User user, String httpMethod, String url, String tenant) throws IOException, PermitApiError {
return this.enforcer.checkUrl(user, httpMethod, url, tenant);
}

@Override
public boolean[] bulkCheck(List<CheckQuery> checks) throws IOException {
public boolean[] bulkCheck(List<CheckQuery> checks) throws IOException, PermitApiError {
return this.enforcer.bulkCheck(checks);
}

@Override
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource, Context context) throws IOException {
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource, Context context) throws IOException, PermitApiError {
return this.enforcer.checkInAllTenants(user, action, resource, context);
}

@Override
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource) throws IOException {
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource) throws IOException, PermitApiError {
return this.enforcer.checkInAllTenants(user, action, resource);
}

@Override
public UserPermissions getUserPermissions(GetUserPermissionsQuery input) throws IOException {
public UserPermissions getUserPermissions(GetUserPermissionsQuery input) throws IOException, PermitApiError {
return this.enforcer.getUserPermissions(input);
}

@Override
public List<TenantDetails> getUserTenants(User user, Context context) throws IOException, PermitApiError {
return this.enforcer.getUserTenants(user, context);
}

@Override
public List<TenantDetails> getUserTenants(User user) throws IOException, PermitApiError {
return this.enforcer.getUserTenants(user);
}
}
Loading

0 comments on commit c5aeb66

Please sign in to comment.