Skip to content

Commit c5aeb66

Browse files
author
Asaf Cohen
authored
Merge pull request #18 from permitio/asaf/cto-147-salt-urgent-help-with-production-deployment
More accurate exceptions + get user tenants from the PDP
2 parents c388a80 + 6682587 commit c5aeb66

7 files changed

Lines changed: 286 additions & 216 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For [Maven](https://maven.apache.org/) projects, use:
1414
<dependency>
1515
<groupId>io.permit</groupId>
1616
<artifactId>permit-sdk-java</artifactId>
17-
<version>1.4.0</version>
17+
<version>2.0.0</version>
1818
</dependency>
1919
```
2020

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

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

149149
## Javadoc reference
150150

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

153-
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.
153+
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.

src/main/java/io/permit/sdk/Permit.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.gson.GsonBuilder;
55
import io.permit.sdk.api.ApiClient;
66
import io.permit.sdk.api.ElementsApi;
7+
import io.permit.sdk.api.PermitApiError;
78
import io.permit.sdk.enforcement.*;
89
import io.permit.sdk.util.Context;
910

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

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

129132
@Override
130-
public boolean checkUrl(User user, String httpMethod, String url, String tenant, Context context) throws IOException {
133+
public boolean checkUrl(User user, String httpMethod, String url, String tenant, Context context) throws IOException, PermitApiError {
131134
return this.enforcer.checkUrl(user, httpMethod, url, tenant, context);
132135
}
133136

134137
@Override
135-
public boolean checkUrl(User user, String httpMethod, String url, String tenant) throws IOException {
138+
public boolean checkUrl(User user, String httpMethod, String url, String tenant) throws IOException, PermitApiError {
136139
return this.enforcer.checkUrl(user, httpMethod, url, tenant);
137140
}
138141

139142
@Override
140-
public boolean[] bulkCheck(List<CheckQuery> checks) throws IOException {
143+
public boolean[] bulkCheck(List<CheckQuery> checks) throws IOException, PermitApiError {
141144
return this.enforcer.bulkCheck(checks);
142145
}
143146

144147
@Override
145-
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource, Context context) throws IOException {
148+
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource, Context context) throws IOException, PermitApiError {
146149
return this.enforcer.checkInAllTenants(user, action, resource, context);
147150
}
148151

149152
@Override
150-
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource) throws IOException {
153+
public List<TenantDetails> checkInAllTenants(User user, String action, Resource resource) throws IOException, PermitApiError {
151154
return this.enforcer.checkInAllTenants(user, action, resource);
152155
}
153156

154157
@Override
155-
public UserPermissions getUserPermissions(GetUserPermissionsQuery input) throws IOException {
158+
public UserPermissions getUserPermissions(GetUserPermissionsQuery input) throws IOException, PermitApiError {
156159
return this.enforcer.getUserPermissions(input);
157160
}
161+
162+
@Override
163+
public List<TenantDetails> getUserTenants(User user, Context context) throws IOException, PermitApiError {
164+
return this.enforcer.getUserTenants(user, context);
165+
}
166+
167+
@Override
168+
public List<TenantDetails> getUserTenants(User user) throws IOException, PermitApiError {
169+
return this.enforcer.getUserTenants(user);
170+
}
158171
}

0 commit comments

Comments
 (0)