[KEYCLOAK-6164] - Authorization services client doesn't work with JDK7
This commit is contained in:
parent
a5f675d693
commit
bda57d00df
11 changed files with 43 additions and 39 deletions
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
|
@ -46,7 +46,14 @@ public class AdminAlbumService {
|
|||
List<Album> result = this.entityManager.createQuery("from Album").getResultList();
|
||||
|
||||
for (Album album : result) {
|
||||
albums.computeIfAbsent(album.getUserId(), key -> new ArrayList<>()).add(album);
|
||||
List<Album> userAlbums = albums.get(album.getUserId());
|
||||
|
||||
if (userAlbums == null) {
|
||||
userAlbums = new ArrayList<>();
|
||||
albums.put(album.getUserId(), userAlbums);
|
||||
}
|
||||
|
||||
userAlbums.add(album);
|
||||
}
|
||||
|
||||
return Response.ok(albums).build();
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.security.Principal;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("/album")
|
||||
@Transaction
|
||||
|
@ -47,6 +48,7 @@ public class AlbumService {
|
|||
public Response create(Album newAlbum) {
|
||||
Principal userPrincipal = request.getUserPrincipal();
|
||||
|
||||
newAlbum.setId(UUID.randomUUID().toString());
|
||||
newAlbum.setUserId(userPrincipal.getName());
|
||||
|
||||
Query queryDuplicatedAlbum = this.entityManager.createQuery("from Album where name = :name and userId = :userId");
|
||||
|
@ -68,7 +70,7 @@ public class AlbumService {
|
|||
@Path("{id}")
|
||||
@DELETE
|
||||
public Response delete(@PathParam("id") String id) {
|
||||
Album album = this.entityManager.find(Album.class, Long.valueOf(id));
|
||||
Album album = this.entityManager.find(Album.class, id);
|
||||
|
||||
try {
|
||||
deleteProtectedResource(album);
|
||||
|
@ -90,7 +92,7 @@ public class AlbumService {
|
|||
@Path("{id}")
|
||||
@Produces("application/json")
|
||||
public Response findById(@PathParam("id") String id) {
|
||||
List result = this.entityManager.createQuery("from Album where id = :id").setParameter("id", Long.valueOf(id)).getResultList();
|
||||
List result = this.entityManager.createQuery("from Album where id = :id").setParameter("id", id).getResultList();
|
||||
|
||||
if (result.isEmpty()) {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.keycloak.example.photoz.entity;
|
|||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,8 +32,7 @@ import java.util.List;
|
|||
public class Album {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
@ -45,11 +43,11 @@ public class Album {
|
|||
@Column(nullable = false)
|
||||
private String userId;
|
||||
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
<description/>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
|
Loading…
Reference in a new issue