-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inject the audience(DID) as additional property in the DataFlow…
…StartMessage for later verification in refresh token (#1187)
- Loading branch information
Showing
28 changed files
with
620 additions
and
54 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
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
42 changes: 42 additions & 0 deletions
42
...ient/src/main/java/org/eclipse/tractusx/edc/identity/mapper/BdrsClientAudienceMapper.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,42 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.identity.mapper; | ||
|
||
import org.eclipse.edc.spi.iam.AudienceResolver; | ||
import org.eclipse.edc.spi.types.domain.message.RemoteMessage; | ||
import org.eclipse.tractusx.edc.spi.identity.mapper.BdrsClient; | ||
|
||
/** | ||
* An incoming {@link RemoteMessage} is mapped to a DID by calling {@link BdrsClient#resolve(String)} with the {@link RemoteMessage#getCounterPartyId()} | ||
*/ | ||
class BdrsClientAudienceMapper implements AudienceResolver { | ||
|
||
private final BdrsClient client; | ||
|
||
BdrsClientAudienceMapper(BdrsClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public String resolve(RemoteMessage remoteMessage) { | ||
return client.resolve(remoteMessage.getCounterPartyId()); | ||
} | ||
|
||
} |
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
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
47 changes: 47 additions & 0 deletions
47
...ent/src/main/java/org/eclipse/tractusx/edc/identity/mapper/BdrsClientMapperExtension.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,47 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.identity.mapper; | ||
|
||
import org.eclipse.edc.runtime.metamodel.annotation.Extension; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Provider; | ||
import org.eclipse.edc.spi.iam.AudienceResolver; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.tractusx.edc.spi.identity.mapper.BdrsClient; | ||
|
||
import static org.eclipse.tractusx.edc.identity.mapper.BdrsClientExtension.NAME; | ||
|
||
@Extension(value = NAME) | ||
public class BdrsClientMapperExtension implements ServiceExtension { | ||
|
||
@Inject | ||
private BdrsClient bdrsClient; | ||
|
||
@Override | ||
public String name() { | ||
return NAME; | ||
} | ||
|
||
@Provider | ||
public AudienceResolver getBdrsAudienceResolver() { | ||
return new BdrsClientAudienceMapper(bdrsClient); | ||
} | ||
|
||
} |
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
74 changes: 74 additions & 0 deletions
74
.../src/test/java/org/eclipse/tractusx/edc/identity/mapper/BdrsClientAudienceMapperTest.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,74 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.identity.mapper; | ||
|
||
import org.eclipse.edc.spi.types.domain.message.RemoteMessage; | ||
import org.eclipse.tractusx.edc.spi.identity.mapper.BdrsClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class BdrsClientAudienceMapperTest { | ||
|
||
private final BdrsClient client = mock(); | ||
|
||
private final BdrsClientAudienceMapper clientAudienceMapper = new BdrsClientAudienceMapper(client); | ||
|
||
@Test | ||
void resolve() { | ||
|
||
when(client.resolve("bpn1")).thenReturn("did:web:did1"); | ||
|
||
var did = clientAudienceMapper.resolve(new TestMessage("bpn1")); | ||
|
||
assertThat(did).isEqualTo("did:web:did1"); | ||
|
||
} | ||
|
||
@Test | ||
void resolve_notFound() { | ||
|
||
when(client.resolve("bpn1")).thenReturn(null); | ||
|
||
var did = clientAudienceMapper.resolve(new TestMessage("bpn1")); | ||
|
||
assertThat(did).isNull(); | ||
|
||
} | ||
|
||
private record TestMessage(String bpn) implements RemoteMessage { | ||
@Override | ||
public String getProtocol() { | ||
return "test-proto"; | ||
} | ||
|
||
@Override | ||
public String getCounterPartyAddress() { | ||
return "http://bpn1"; | ||
} | ||
|
||
@Override | ||
public String getCounterPartyId() { | ||
return bpn; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.