From d83ce91b2e04b131ef3a83983bbd79331be6cac9 Mon Sep 17 00:00:00 2001 From: andreibogus Date: Mon, 12 Feb 2024 16:08:49 +0100 Subject: [PATCH] feat: add JWT verification and extend tests --- .../utils/CompositDidResolver.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CompositDidResolver.java diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CompositDidResolver.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CompositDidResolver.java new file mode 100644 index 000000000..49c645d7c --- /dev/null +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CompositDidResolver.java @@ -0,0 +1,71 @@ +/* + * ******************************************************************************* + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * 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.managedidentitywallets.utils; + +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolverException; +import org.eclipse.tractusx.ssi.lib.model.did.Did; +import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; +import org.springframework.stereotype.Component; + +import java.util.Arrays; + +@Component +public class CompositDidResolver implements DidResolver { + DidResolver[] didResolvers; + + public CompositDidResolver(DidResolver... didResolvers) { + this.didResolvers = didResolvers; + } + + public DidDocument resolve(Did did) throws DidResolverException { + DidResolver[] var2 = this.didResolvers; + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + DidResolver didResolver = var2[var4]; + if (didResolver.isResolvable(did)) { + try { + DidDocument result = didResolver.resolve(did); + if (result != null) { + return result; + } + } catch (DidResolverException var7) { + throw var7; + } catch (Throwable var8) { + throw new DidResolverException(String.format("Unrecognized exception: %s", var8.getClass().getName()), var8); + } + } + } + + return null; + } + + public boolean isResolvable(Did did) { + return Arrays.stream(this.didResolvers).anyMatch((resolver) -> resolver.isResolvable(did)); + } + + public static org.eclipse.tractusx.ssi.lib.did.resolver.CompositeDidResolver append(DidResolver target, DidResolver toBeAppended) { + return new org.eclipse.tractusx.ssi.lib.did.resolver.CompositeDidResolver(target, toBeAppended); + } +} +