Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
wistefan committed Dec 14, 2023
1 parent 8155c20 commit f46ce75
Show file tree
Hide file tree
Showing 59 changed files with 153 additions and 139 deletions.
2 changes: 1 addition & 1 deletion services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
<configuration>
<inputSpec>${project.basedir}/src/api/oidc4vci-api.yaml</inputSpec>
<strictSpec>true</strictSpec>
<modelPackage>org.keycloak.protocol.oid4vp.model</modelPackage>
<modelPackage>org.keycloak.protocol.oid4vc.model</modelPackage>
<generateAliasAsModel>true</generateAliasAsModel>
<generatorName>jaxrs-spec</generatorName>
<!-- the generated interfaces cannot be used, since there class level annotations clash with the spi. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.core.UriInfo;
import org.keycloak.models.KeycloakContext;
import org.keycloak.models.KeycloakSession;
import org.keycloak.protocol.oid4vp.model.Format;
import org.keycloak.protocol.oid4vp.model.SupportedCredential;
import org.keycloak.protocol.oid4vc.model.Format;
import org.keycloak.protocol.oid4vc.model.SupportedCredential;
import org.keycloak.services.Urls;
import org.keycloak.urls.UrlType;
import org.keycloak.wellknown.WellKnownProvider;
Expand All @@ -16,7 +16,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;
import static org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;

public abstract class OIDC4VPAbstractWellKnownProvider implements WellKnownProvider {

Expand All @@ -39,7 +39,7 @@ public static List<SupportedCredential> getSupportedCredentials(KeycloakContext

}

protected List<SupportedCredential> mapAttributeEntryToSc(Map.Entry<String, String> typesEntry) {
public List<SupportedCredential> mapAttributeEntryToSc(Map.Entry<String, String> typesEntry) {
String type = typesEntry.getKey().replaceFirst(VC_TYPES_PREFIX, "");
Set<Format> supportedFormats = getFormatsFromString(typesEntry.getValue());
return supportedFormats.stream().map(formatVO -> {
Expand All @@ -51,7 +51,7 @@ protected List<SupportedCredential> mapAttributeEntryToSc(Map.Entry<String, Stri
.toList();
}

protected static List<SupportedCredential> mapAttributeEntryToScVO(Map.Entry<String, String> typesEntry) {
public static List<SupportedCredential> mapAttributeEntryToScVO(Map.Entry<String, String> typesEntry) {
String type = typesEntry.getKey().replaceFirst(VC_TYPES_PREFIX, "");
Set<Format> supportedFormats = getFormatsFromString(typesEntry.getValue());
return supportedFormats.stream().map(formatVO -> {
Expand All @@ -66,23 +66,23 @@ protected static List<SupportedCredential> mapAttributeEntryToScVO(Map.Entry<Str
).toList();
}

protected static Set<Format> getFormatsFromString(String formatString) {
public static Set<Format> getFormatsFromString(String formatString) {
return Arrays.stream(formatString.split(",")).map(Format::fromString).collect(Collectors.toSet());
}

protected static String buildIdFromType(Format formatVO, String type) {
public static String buildIdFromType(Format formatVO, String type) {
return String.format("%s_%s", type, formatVO.toString());
}

protected static String getIssuer(KeycloakContext context) {
public static String getIssuer(KeycloakContext context) {
UriInfo frontendUriInfo = context.getUri(UrlType.FRONTEND);

return Urls.realmIssuer(frontendUriInfo.getBaseUri(),
context.getRealm().getName());

}

protected static String getCredentialsEndpoint(KeycloakContext context) {
public static String getCredentialsEndpoint(KeycloakContext context) {
return getIssuer(context) + "/protocol/" + OIDC4VPLoginProtocolFactory.PROTOCOL_ID + "/credential";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import org.keycloak.protocol.oid4vp.model.SupportedCredential;
import org.keycloak.protocol.oid4vc.model.SupportedCredential;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import org.keycloak.models.ClientModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import org.keycloak.models.KeycloakSession;
import org.keycloak.representations.idm.ClientRepresentation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.jboss.logging.Logger;
Expand All @@ -13,9 +13,11 @@
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.protocol.LoginProtocol;
import org.keycloak.protocol.LoginProtocolFactory;
import org.keycloak.protocol.oid4vp.mappers.OIDC4VPSubjectIdMapper;
import org.keycloak.protocol.oid4vp.mappers.OIDC4VPTargetRoleMapper;
import org.keycloak.protocol.oid4vp.mappers.OIDC4VPUserAttributeMapper;
import org.keycloak.protocol.oid4vc.issuance.OIDC4VPIssuerEndpoint;
import org.keycloak.protocol.oid4vc.issuance.VCIssuerException;
import org.keycloak.protocol.oid4vc.issuance.mappers.OIDC4VPSubjectIdMapper;
import org.keycloak.protocol.oid4vc.issuance.mappers.OIDC4VPTargetRoleMapper;
import org.keycloak.protocol.oid4vc.issuance.mappers.OIDC4VPUserAttributeMapper;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.services.managers.AppAuthManager;

Expand Down Expand Up @@ -49,7 +51,7 @@ public class OIDC4VPLoginProtocolFactory implements LoginProtocolFactory {

@Override
public void init(Config.Scope config) {
LOGGER.info("Initiate the protocol factory");
LOGGER.infof("Initiate the protocol factory. Config is %s", config);
builtins.put(CLIENT_ROLES_MAPPER,
OIDC4VPTargetRoleMapper.create("id", "client roles"));
builtins.put(SUBJECT_ID_MAPPER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -12,22 +12,25 @@
import org.keycloak.common.util.Time;
import org.keycloak.events.EventBuilder;
import org.keycloak.models.*;
import org.keycloak.protocol.oid4vc.OIDC4VPAbstractWellKnownProvider;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProvider;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oidc.utils.OAuth2Code;
import org.keycloak.protocol.oidc.utils.OAuth2CodeParser;
import org.keycloak.protocol.oid4vp.mappers.OIDC4VPMapper;
import org.keycloak.protocol.oid4vp.mappers.OIDC4VPMapperFactory;
import org.keycloak.protocol.oid4vp.model.*;
import org.keycloak.protocol.oid4vp.model.CredentialOfferURI;
import org.keycloak.protocol.oid4vp.model.CredentialRequest;
import org.keycloak.protocol.oid4vp.model.CredentialResponse;
import org.keycloak.protocol.oid4vp.model.CredentialsOffer;
import org.keycloak.protocol.oid4vp.model.ErrorResponse;
import org.keycloak.protocol.oid4vp.model.Format;
import org.keycloak.protocol.oid4vp.model.PreAuthorized;
import org.keycloak.protocol.oid4vp.model.PreAuthorizedGrant;
import org.keycloak.protocol.oid4vp.model.SupportedCredential;
import org.keycloak.protocol.oid4vp.model.vcdm.LdProof;
import org.keycloak.protocol.oid4vp.signing.*;
import org.keycloak.protocol.oid4vc.issuance.mappers.OIDC4VPMapper;
import org.keycloak.protocol.oid4vc.issuance.mappers.OIDC4VPMapperFactory;
import org.keycloak.protocol.oid4vc.model.*;
import org.keycloak.protocol.oid4vc.model.CredentialOfferURI;
import org.keycloak.protocol.oid4vc.model.CredentialRequest;
import org.keycloak.protocol.oid4vc.model.CredentialResponse;
import org.keycloak.protocol.oid4vc.model.CredentialsOffer;
import org.keycloak.protocol.oid4vc.model.ErrorResponse;
import org.keycloak.protocol.oid4vc.model.Format;
import org.keycloak.protocol.oid4vc.model.PreAuthorized;
import org.keycloak.protocol.oid4vc.model.PreAuthorizedGrant;
import org.keycloak.protocol.oid4vc.model.SupportedCredential;
import org.keycloak.protocol.oid4vc.model.vcdm.LdProof;
import org.keycloak.protocol.oid4vc.signing.*;
import org.keycloak.representations.JsonWebToken;
import org.keycloak.services.managers.AppAuthManager;
import org.keycloak.services.managers.AuthenticationManager;
Expand All @@ -37,8 +40,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;
import static org.keycloak.protocol.oid4vp.model.Format.*;
import static org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;
import static org.keycloak.protocol.oid4vc.model.Format.*;

/**
* Realm-Resource to provide functionality for issuing VerifiableCredentials to users, depending on their roles in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.keycloak.models.KeycloakSession;
import org.keycloak.protocol.oid4vp.model.CredentialIssuer;
import org.keycloak.protocol.oid4vc.OIDC4VPAbstractWellKnownProvider;
import org.keycloak.protocol.oid4vc.model.CredentialIssuer;

public class OIDC4VPIssuerWellKnownProvider extends OIDC4VPAbstractWellKnownProvider {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.jboss.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.protocol.oid4vc.OIDC4VPAbstractWellKnownProvider;
import org.keycloak.protocol.oidc.OIDCWellKnownProvider;
import org.keycloak.protocol.oid4vp.model.SupportedCredential;
import org.keycloak.protocol.oid4vc.model.SupportedCredential;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,8 +15,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;
import static org.keycloak.protocol.oid4vp.OIDC4VPIssuerEndpoint.GRANT_TYPE_PRE_AUTHORIZED_CODE;
import static org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProvider.VC_TYPES_PREFIX;
import static org.keycloak.protocol.oid4vc.issuance.OIDC4VPIssuerEndpoint.GRANT_TYPE_PRE_AUTHORIZED_CODE;

public class OIDC4VPWellKnownProvider extends OIDC4VPAbstractWellKnownProvider {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.jboss.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp;
package org.keycloak.protocol.oid4vc.issuance;

public class VCIssuerException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.ProtocolMapper;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

public class OIDC4VPMapperException extends RuntimeException {
public OIDC4VPMapperException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.models.ProtocolMapperModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.constraints.NotNull;
Expand All @@ -7,9 +7,9 @@
import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.Role;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.Role;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.keycloak.protocol.oid4vp.mappers;
package org.keycloak.protocol.oid4vc.issuance.mappers;

import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.protocol.oid4vp.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.OIDC4VPClientRegistrationProviderFactory;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp.signing;
package org.keycloak.protocol.oid4vc.signing;

import org.jboss.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.keycloak.protocol.oid4vp.signing;
package org.keycloak.protocol.oid4vc.signing;


import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
Expand All @@ -8,8 +8,8 @@
import org.keycloak.common.util.KeyUtils;
import org.keycloak.crypto.*;
import org.keycloak.jose.jws.JWSBuilder;
import org.keycloak.protocol.oid4vp.model.VerifiableCredential;
import org.keycloak.protocol.oid4vp.signing.jwt_vc.EdDSASignatureSignerContext;
import org.keycloak.protocol.oid4vc.model.VerifiableCredential;
import org.keycloak.protocol.oid4vc.signing.jwt_vc.EdDSASignatureSignerContext;
import org.keycloak.representations.JsonWebToken;

import java.io.IOException;
Expand All @@ -25,7 +25,7 @@
import java.util.Optional;
import java.util.UUID;

import static org.keycloak.protocol.oid4vp.signing.jwt_vc.EdDSASignatureSignerContext.ED_25519;
import static org.keycloak.protocol.oid4vc.signing.jwt_vc.EdDSASignatureSignerContext.ED_25519;

public class JwtSigningService extends SigningService<String> {

Expand Down
Loading

0 comments on commit f46ce75

Please sign in to comment.