Skip to content

Commit

Permalink
remove wallet key repository from secure token issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
PManaras committed Apr 15, 2024
1 parent bb645b1 commit 9969c3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.JtiRecord;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.WalletKey;
import org.eclipse.tractusx.managedidentitywallets.dao.repository.JtiRepository;
import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletKeyRepository;
import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletRepository;
Expand All @@ -51,17 +50,15 @@
@RequiredArgsConstructor
public class LocalSecureTokenService implements SecureTokenService {

private final WalletKeyRepository walletKeyRepository;

private final WalletRepository walletRepository;

private final SecureTokenIssuer tokenIssuer;
// Autowired by name!!!
private final SecureTokenIssuer localSecureTokenIssuer;

private final SecureTokenConfigurationProperties properties;

private final JtiRepository jtiRepository;

// TODO abstract issue token into signing service

@Override
public JWT issueToken(final DID self, final DID partner, final Set<String> scopes, KeyProvider keyProvider) {
Expand All @@ -70,9 +67,9 @@ public JWT issueToken(final DID self, final DID partner, final Set<String> scope
// IMPORTANT: we re-use the expiration time intentionally to mitigate any kind of timing attacks,
// as we're signing two tokens.
Instant expirationTime = Instant.now().plus(properties.tokenDuration());
JWT accessToken = this.tokenIssuer.createAccessToken(keyPair, self, partner, expirationTime, scopes);
JWT accessToken = this.localSecureTokenIssuer.createAccessToken(keyPair, self, partner, expirationTime, scopes);
checkAndStoreJti(accessToken);
return this.tokenIssuer.createIdToken(keyPair, self, partner, expirationTime, accessToken);
return this.localSecureTokenIssuer.createIdToken(keyPair, self, partner, expirationTime, accessToken);
}

@Override
Expand All @@ -81,7 +78,7 @@ public JWT issueToken(DID self, DID partner, JWT accessToken, KeyProvider keyPro
KeyPair keyPair = keyProvider.getKeyPair(self);
Instant expirationTime = Instant.now().plus(properties.tokenDuration());
checkAndStoreJti(accessToken);
return this.tokenIssuer.createIdToken(keyPair, self, partner, expirationTime, accessToken);
return this.localSecureTokenIssuer.createIdToken(keyPair, self, partner, expirationTime, accessToken);
}

private void checkAndStoreJti(JWT accessToken) {
Expand All @@ -107,8 +104,8 @@ public JWT issueToken(BusinessPartnerNumber self, BusinessPartnerNumber partner,
// IMPORTANT: we re-use the expiration time intentionally to mitigate any kind of timing attacks,
// as we're signing two tokens.
Instant expirationTime = Instant.now().plus(properties.tokenDuration());
JWT accessToken = this.tokenIssuer.createAccessToken(keyPair, selfDid, partnerDid, expirationTime, scopes);
return this.tokenIssuer.createIdToken(keyPair, selfDid, partnerDid, expirationTime, accessToken);
JWT accessToken = this.localSecureTokenIssuer.createAccessToken(keyPair, selfDid, partnerDid, expirationTime, scopes);
return this.localSecureTokenIssuer.createIdToken(keyPair, selfDid, partnerDid, expirationTime, accessToken);
}

@Override
Expand All @@ -123,6 +120,6 @@ public JWT issueToken(BusinessPartnerNumber self, BusinessPartnerNumber partner,
.orElseThrow(() -> new UnknownBusinessPartnerNumberException(String.format("The provided BPN '%s' is unknown", partner)))
.getDid());
Instant expirationTime = Instant.now().plus(properties.tokenDuration());
return this.tokenIssuer.createIdToken(keyPair, selfDid, partnerDid, expirationTime, accessToken);
return this.localSecureTokenIssuer.createIdToken(keyPair, selfDid, partnerDid, expirationTime, accessToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.tractusx.managedidentitywallets.domain.DID;
import org.eclipse.tractusx.managedidentitywallets.domain.KeyPair;
import org.eclipse.tractusx.managedidentitywallets.interfaces.SecureTokenIssuer;
import org.eclipse.tractusx.managedidentitywallets.utils.EncryptionUtils;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
import org.eclipse.tractusx.ssi.lib.crypt.x21559.x21559PrivateKey;
import org.springframework.stereotype.Component;
Expand All @@ -53,9 +52,7 @@
@Slf4j
@Component
@RequiredArgsConstructor
public class SecureTokenIssuerImpl implements SecureTokenIssuer {

private final EncryptionUtils encryptionUtils;
public class LocalSecureTokenIssuer implements SecureTokenIssuer {

@Override
public JWT createIdToken(KeyPair keyPair, DID self, DID partner, Instant expirationTime, JWT accessToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public class SecureTokenBeanConfig {

@Bean
public SecureTokenService secureTokenService(
WalletKeyRepository keyRepository,
WalletRepository walletRepository,
SecureTokenIssuer issuer,
SecureTokenConfigurationProperties properties,
JtiRepository jtiRepository
) {
return new LocalSecureTokenService(keyRepository, walletRepository, issuer, properties, jtiRepository);
return new LocalSecureTokenService(walletRepository, issuer, properties, jtiRepository);
}

}

0 comments on commit 9969c3e

Please sign in to comment.