1212 *
1313 */
1414
15- package org .eclipse .edc .identity . extension ;
15+ package org .eclipse .edc .identity ;
1616
17+ import org .eclipse .edc .identity .api .IamIdentityApiController ;
18+ import org .eclipse .edc .identity .load .FileParticipantIdentityLoader ;
19+ import org .eclipse .edc .identity .load .ParticipantIdentityLoader ;
1720import org .eclipse .edc .runtime .metamodel .annotation .Extension ;
1821import org .eclipse .edc .runtime .metamodel .annotation .Inject ;
1922import org .eclipse .edc .runtime .metamodel .annotation .Provider ;
2427import org .eclipse .edc .spi .system .ServiceExtension ;
2528import org .eclipse .edc .spi .system .ServiceExtensionContext ;
2629import org .eclipse .edc .spi .types .TypeManager ;
30+ import org .eclipse .edc .web .spi .WebService ;
2731
2832import java .security .PrivateKey ;
2933import java .security .PublicKey ;
3034import java .util .Base64 ;
35+ import java .util .Map ;
3136
3237/**
3338 * The {@code IamIdentityExtension} class is a service extension that integrates an IAM-based
@@ -71,31 +76,39 @@ public void initialize(ServiceExtensionContext context) {
7176 var monitor = context .getMonitor ();
7277 monitor .info ("Initializing iam-identity extension" );
7378
74- var claimsPath = context .getConfig ().getString ("edc.participant.claims" );
75- var participantPrivateKeyPath = context .getConfig ().getString ("edc.participant.private.key" );
76- var participantPublicKeyPath = context .getConfig ().getString ("edc.participant.public.key" );
77- var participantRegistryUrl = context .getConfig ().getString ("edc.participant.registry.url" );
78- var participantId = context .getParticipantId ();
79-
80- ParticipantIdentityLoader loader = new FileParticipantIdentityLoader (monitor , typeManager .getMapper ());
81- var claims = loader .loadClaims (claimsPath );
8279
80+ var claimsPath = context .getConfig ().getString ("edc.participant.claims" , null );
81+ var participantPrivateKeyPath = context .getConfig ().getString ("edc.participant.private.key" , null );
82+ var participantPublicKeyPath = context .getConfig ().getString ("edc.participant.public.key" , null );
83+ var participantRegistryUrl = context .getConfig ().getString ("edc.participant.registry.url" , null );
84+ var participantId = context .getParticipantId ();
8385
84- PrivateKey participantPrivateKey = loader .loadPrivateKey (participantPrivateKeyPath );
85- PublicKey participantPublicKey = loader .loadPublicKey (participantPublicKeyPath );
86- String base64PublicKey = Base64 .getEncoder ().encodeToString (participantPublicKey .getEncoded ());
87- String signedClaims = loader .signClaims (claims , participantPrivateKey , monitor );
88- boolean publicKeyMatchesPrivateKey = loader .publicKeyMatchesPrivateKey (participantPublicKey , participantPrivateKey );
8986
90- if (publicKeyMatchesPrivateKey ) {
91- monitor .info ("Private && Public keys has been successfully validated!" );
92- monitor .info ("Claims has been successfully signed: " + signedClaims );
93- monitor .info ("Claims: " + claims );
94- monitor .info ("Public key: " + base64PublicKey );
95- monitor .info ("Participant registry url: " + participantRegistryUrl );
87+ ParticipantIdentityLoader loader = new FileParticipantIdentityLoader (monitor , typeManager .getMapper ());
88+ boolean checkConfiguration = loader .checkConfigurations (claimsPath , participantRegistryUrl , participantPrivateKeyPath , participantPublicKeyPath );
89+
90+ Map <String , Object > claims = Map .of ();
91+ String signedClaims = null ;
92+ if (checkConfiguration ) {
93+ claims = loader .loadClaims (claimsPath );
94+ PrivateKey participantPrivateKey = loader .loadPrivateKey (participantPrivateKeyPath );
95+ PublicKey participantPublicKey = loader .loadPublicKey (participantPublicKeyPath );
96+ String base64PublicKey = Base64 .getEncoder ().encodeToString (participantPublicKey .getEncoded ());
97+ signedClaims = loader .signClaims (claims , participantPrivateKey , monitor );
98+ boolean publicKeyMatchesPrivateKey = loader .publicKeyMatchesPrivateKey (participantPublicKey , participantPrivateKey );
99+
100+ if (publicKeyMatchesPrivateKey ) {
101+ monitor .info ("Private && Public keys has been successfully validated!" );
102+ monitor .info ("Claims has been successfully signed: " + signedClaims );
103+ monitor .info ("Claims: " + claims );
104+ monitor .info ("Public key: " + base64PublicKey );
105+ monitor .info ("Participant registry url: " + participantRegistryUrl );
106+ }
96107 }
97108
98109
110+ webService .registerResource (new IamIdentityApiController (context .getMonitor ()));
111+
99112 context .registerService (
100113 IdentityService .class ,
101114 new IamIdentityService (typeManager , claims , participantId , signedClaims ));
@@ -110,4 +123,9 @@ public void initialize(ServiceExtensionContext context) {
110123 public AudienceResolver audienceResolver () {
111124 return (msg ) -> Result .success (msg .getCounterPartyAddress ());
112125 }
126+
127+ @ Inject
128+ WebService webService ;
129+
130+
113131}
0 commit comments