48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package de.tavolio.oidc;
|
|
|
|
import de.tavolio.realm.RealmEntity;
|
|
import de.tavolio.realm.RealmRepo;
|
|
import de.tavolio.realm.key.KeypairEntity;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Path("/realms/{realm-key}/oidc/keys")
|
|
public class JwksService
|
|
{
|
|
@Inject
|
|
RealmRepo realmRepo;
|
|
|
|
@GET
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
public Map<String, Object> get(@PathParam("realm-key") String realmKey)
|
|
{
|
|
RealmEntity realm = realmRepo.findByKey(realmKey);
|
|
if (realm != null)
|
|
{
|
|
List<Map<String, String>> result = new LinkedList<>();
|
|
for (KeypairEntity keypair : realm.getKeys())
|
|
{
|
|
if ("EC".equals(keypair.getType()))
|
|
{
|
|
result.add(Map.ofEntries(
|
|
Map.entry("kty", "EC"),
|
|
Map.entry("alg", keypair.getAlg()),
|
|
Map.entry("use", keypair.getUse()),
|
|
Map.entry("crv", keypair.getCrv()),
|
|
Map.entry("kid", keypair.getId()),
|
|
Map.entry("x", keypair.getX()),
|
|
Map.entry("y", keypair.getY())
|
|
));
|
|
}
|
|
}
|
|
return Map.ofEntries(Map.entry("keys", result));
|
|
}
|
|
throw new NotFoundException();
|
|
}
|
|
}
|