-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: dedicated class for default JwsSignerProvider
- Loading branch information
1 parent
7f51a3d
commit 0be4abb
Showing
3 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...common-lib/src/main/java/org/eclipse/edc/security/token/jwt/DefaultJwsSignerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.security.token.jwt; | ||
|
||
import com.nimbusds.jose.JWSSigner; | ||
import org.eclipse.edc.jwt.signer.spi.JwsSignerProvider; | ||
import org.eclipse.edc.keys.spi.PrivateKeyResolver; | ||
import org.eclipse.edc.spi.result.Result; | ||
|
||
/** | ||
* Provides a {@link JWSSigner} that is created based on a private key's algorithm. | ||
* Note that the private key will be held in memory for the duration of the instantiation of the {@link JWSSigner}. | ||
*/ | ||
public class DefaultJwsSignerProvider implements JwsSignerProvider { | ||
|
||
private final PrivateKeyResolver privateKeyResolver; | ||
|
||
public DefaultJwsSignerProvider(PrivateKeyResolver privateKeyResolver) { | ||
this.privateKeyResolver = privateKeyResolver; | ||
} | ||
|
||
@Override | ||
public Result<JWSSigner> createJwsSigner(String privateKeyId) { | ||
return privateKeyResolver.resolvePrivateKey(privateKeyId) | ||
.compose(pk -> Result.ofThrowable(() -> CryptoConverter.createSignerFor(pk))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters