[KEYCLOAK-6164] - Authorization services client doesn't work with JDK7

This commit is contained in:
pedroigor committed 2018-01-31 13:42:30 -02:00
1 parent a5f675d693
commit bda57d00df
11 files changed
+43 -39

No files matched your search

-2
View File
@@ -18,8 +18,6 @@
<description>KeyCloak AuthZ: Client API</description>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<keycloak.osgi.export>
org.keycloak.authorization.client.*
</keycloak.osgi.export>
@@ -30,7 +30,7 @@ import org.keycloak.util.JsonSerialization;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.function.Supplier;
import java.util.concurrent.Callable;
/**
* <p>This is class serves as an entry point for clients looking for access to Keycloak Authorization Services.
@@ -40,7 +40,7 @@ import java.util.function.Supplier;
public class AuthzClient {
private final Http http;
private Supplier<String> patSupplier;
private Callable<String> patSupplier;
public static AuthzClient create() {
InputStream configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("keycloak.json");
@@ -141,13 +141,13 @@ public class AuthzClient {
return this.deployment;
}
private Supplier<String> createPatSupplier() {
private Callable<String> createPatSupplier() {
if (patSupplier == null) {
patSupplier = new Supplier<String>() {
patSupplier = new Callable<String>() {
AccessTokenResponse clientToken = obtainAccessToken();
@Override
public String get() {
public String call() {
String token = clientToken.getToken();
try {
@@ -19,7 +19,7 @@ package org.keycloak.authorization.client.resource;
import static org.keycloak.authorization.client.util.Throwables.handleAndWrapException;
import java.util.function.Supplier;
import java.util.concurrent.Callable;
import org.keycloak.authorization.client.representation.PermissionRequest;
import org.keycloak.authorization.client.representation.PermissionResponse;
@@ -32,9 +32,9 @@ import org.keycloak.util.JsonSerialization;
public class PermissionResource {
private final Http http;
private final Supplier<String> pat;
private final Callable<String> pat;
public PermissionResource(Http http, Supplier<String> pat) {
public PermissionResource(Http http, Callable<String> pat) {
this.http = http;
this.pat = pat;
}
@@ -42,7 +42,7 @@ public class PermissionResource {
public PermissionResponse forResource(PermissionRequest request) {
try {
return this.http.<PermissionResponse>post("/authz/protection/permission")
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.json(JsonSerialization.writeValueAsBytes(request))
.response().json(PermissionResponse.class).execute();
} catch (Exception cause) {
@@ -20,7 +20,7 @@ package org.keycloak.authorization.client.resource;
import static org.keycloak.authorization.client.util.Throwables.handleAndWrapException;
import java.util.Set;
import java.util.function.Supplier;
import java.util.concurrent.Callable;
import org.keycloak.authorization.client.representation.RegistrationResponse;
import org.keycloak.authorization.client.representation.ResourceRepresentation;
@@ -33,9 +33,9 @@ import org.keycloak.util.JsonSerialization;
public class ProtectedResource {
private final Http http;
private final Supplier<String> pat;
private final Callable<String> pat;
public ProtectedResource(Http http, Supplier<String> pat) {
public ProtectedResource(Http http, Callable<String> pat) {
this.http = http;
this.pat = pat;
}
@@ -43,7 +43,7 @@ public class ProtectedResource {
public RegistrationResponse create(ResourceRepresentation resource) {
try {
return this.http.<RegistrationResponse>post("/authz/protection/resource_set")
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.json(JsonSerialization.writeValueAsBytes(resource))
.response().json(RegistrationResponse.class).execute();
} catch (Exception cause) {
@@ -54,7 +54,7 @@ public class ProtectedResource {
public void update(ResourceRepresentation resource) {
try {
this.http.<RegistrationResponse>put("/authz/protection/resource_set/" + resource.getId())
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.json(JsonSerialization.writeValueAsBytes(resource)).execute();
} catch (Exception cause) {
throw handleAndWrapException("Could not update resource", cause);
@@ -64,7 +64,7 @@ public class ProtectedResource {
public RegistrationResponse findById(String id) {
try {
return this.http.<RegistrationResponse>get("/authz/protection/resource_set/" + id)
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.response().json(RegistrationResponse.class).execute();
} catch (Exception cause) {
throw handleAndWrapException("Could not find resource", cause);
@@ -74,7 +74,7 @@ public class ProtectedResource {
public Set<String> findByFilter(String filter) {
try {
return this.http.<Set>get("/authz/protection/resource_set")
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.param("filter", filter)
.response().json(Set.class).execute();
} catch (Exception cause) {
@@ -85,7 +85,7 @@ public class ProtectedResource {
public Set<String> findAll() {
try {
return this.http.<Set>get("/authz/protection/resource_set")
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.response().json(Set.class).execute();
} catch (Exception cause) {
throw handleAndWrapException("Could not find resource", cause);
@@ -95,7 +95,7 @@ public class ProtectedResource {
public void delete(String id) {
try {
this.http.delete("/authz/protection/resource_set/" + id)
.authorizationBearer(this.pat.get())
.authorizationBearer(this.pat.call())
.execute();
} catch (Exception cause) {
throw handleAndWrapException("Could not delete resource", cause);
@@ -17,7 +17,7 @@
*/
package org.keycloak.authorization.client.resource;
import java.util.function.Supplier;
import java.util.concurrent.Callable;
import org.keycloak.authorization.client.representation.TokenIntrospectionResponse;
import org.keycloak.authorization.client.util.Http;
@@ -27,10 +27,10 @@ import org.keycloak.authorization.client.util.Http;
*/
public class ProtectionResource {
private final Supplier<String> pat;
private final Callable<String> pat;
private final Http http;
public ProtectionResource(Http http, Supplier<String> pat) {
public ProtectionResource(Http http, Callable<String> pat) {
if (pat == null) {
throw new RuntimeException("No access token was provided when creating client for Protection API.");
}
+5
View File
@@ -17,6 +17,11 @@
<name>KeyCloak AuthZ: Provider Parent</name>
<description>KeyCloak AuthZ: Provider Parent</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>common</module>
<module>drools</module>
-6
View File
@@ -21,10 +21,4 @@
<module>policy</module>
<module>client</module>
</modules>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>