diff --git a/gravitee-am-authdevice-notifier/gravitee-am-authdevice-notifier-api/src/main/java/io/gravitee/am/authdevice/notifier/api/AuthenticationDeviceNotifierProvider.java b/gravitee-am-authdevice-notifier/gravitee-am-authdevice-notifier-api/src/main/java/io/gravitee/am/authdevice/notifier/api/AuthenticationDeviceNotifierProvider.java index ddc4d679150..203b0a3d6a7 100644 --- a/gravitee-am-authdevice-notifier/gravitee-am-authdevice-notifier-api/src/main/java/io/gravitee/am/authdevice/notifier/api/AuthenticationDeviceNotifierProvider.java +++ b/gravitee-am-authdevice-notifier/gravitee-am-authdevice-notifier-api/src/main/java/io/gravitee/am/authdevice/notifier/api/AuthenticationDeviceNotifierProvider.java @@ -19,6 +19,7 @@ import io.gravitee.am.authdevice.notifier.api.model.ADNotificationRequest; import io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse; import io.gravitee.am.authdevice.notifier.api.model.ADUserResponse; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.common.component.Lifecycle; import io.gravitee.common.service.Service; import io.reactivex.rxjava3.core.Single; @@ -29,7 +30,7 @@ * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public interface AuthenticationDeviceNotifierProvider extends Service { +public interface AuthenticationDeviceNotifierProvider extends Service, AmPluginProvider { @Override default Lifecycle.State lifecycleState() { diff --git a/gravitee-am-botdetection/gravitee-am-botdetection-api/src/main/java/io/gravitee/am/botdetection/api/BotDetectionProvider.java b/gravitee-am-botdetection/gravitee-am-botdetection-api/src/main/java/io/gravitee/am/botdetection/api/BotDetectionProvider.java index bce28968200..724216f9fc4 100644 --- a/gravitee-am-botdetection/gravitee-am-botdetection-api/src/main/java/io/gravitee/am/botdetection/api/BotDetectionProvider.java +++ b/gravitee-am-botdetection/gravitee-am-botdetection-api/src/main/java/io/gravitee/am/botdetection/api/BotDetectionProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.botdetection.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.common.component.Lifecycle; import io.gravitee.common.service.Service; import io.reactivex.rxjava3.core.Single; @@ -23,7 +24,7 @@ * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public interface BotDetectionProvider extends Service { +public interface BotDetectionProvider extends Service, AmPluginProvider { @Override default Lifecycle.State lifecycleState() { return Lifecycle.State.INITIALIZED; diff --git a/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProvider.java b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProvider.java index ccb07ddcbf0..fdf6012a64c 100644 --- a/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProvider.java +++ b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.certificate.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.am.model.jose.JWK; import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; @@ -30,7 +31,7 @@ * @author GraviteeSource Team */ -public interface CertificateProvider { +public interface CertificateProvider extends AmPluginProvider { Optional getExpirationDate(); @@ -54,6 +55,4 @@ default Single> publicKeys() { return Single.just(Collections.emptyList()); } - default void unregister() { } - } diff --git a/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProviders.java b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProviders.java new file mode 100644 index 00000000000..a87bcc264a2 --- /dev/null +++ b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProviders.java @@ -0,0 +1,83 @@ +/** + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ +package io.gravitee.am.certificate.api; + +import io.gravitee.am.common.jwt.SignatureAlgorithm; +import io.gravitee.am.model.jose.JWK; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; +import lombok.experimental.UtilityClass; + +import java.security.InvalidKeyException; +import java.util.Collections; +import java.util.Date; +import java.util.Optional; + +@UtilityClass +public class CertificateProviders { + + public static CertificateProvider createNoneCertificateProvider(){ + return new NoneCertificateProvider(); + } + + public static CertificateProvider createShaCertificateProvider(String singingKeyId, String signingKeySecret) throws InvalidKeyException { + byte[] keySecretBytes = signingKeySecret.getBytes(); + java.security.Key key = Keys.hmacShaKeyFor(keySecretBytes); + SignatureAlgorithm signatureAlgorithm = Keys.hmacShaSignatureAlgorithmFor(keySecretBytes); + io.gravitee.am.certificate.api.Key certificateKey = new DefaultKey(singingKeyId, key); + + // create default certificate provider + CertificateMetadata certificateMetadata = new CertificateMetadata(); + certificateMetadata.setMetadata(Collections.singletonMap(CertificateMetadata.DIGEST_ALGORITHM_NAME, signatureAlgorithm.getDigestName())); + + return new io.gravitee.am.certificate.api.CertificateProvider() { + @Override + public Optional getExpirationDate() { + return Optional.empty(); + } + + @Override + public Single key() { + return Single.just(certificateKey); + } + + @Override + public Flowable privateKey() { + return null; + } + + @Override + public Single publicKey() { + return null; + } + + @Override + public Flowable keys() { + return null; + } + + @Override + public String signatureAlgorithm() { + return signatureAlgorithm.getValue(); + } + + @Override + public CertificateMetadata certificateMetadata() { + return certificateMetadata; + } + }; + } +} diff --git a/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/NoneCertificateProvider.java b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/NoneCertificateProvider.java new file mode 100644 index 00000000000..784acb76086 --- /dev/null +++ b/gravitee-am-certificate/gravitee-am-certificate-api/src/main/java/io/gravitee/am/certificate/api/NoneCertificateProvider.java @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ +package io.gravitee.am.certificate.api; + +import io.gravitee.am.common.jwt.SignatureAlgorithm; +import io.gravitee.am.model.jose.JWK; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; + +import java.util.Collections; +import java.util.Date; +import java.util.Optional; + +class NoneCertificateProvider implements CertificateProvider { + private final CertificateMetadata metadata; + + NoneCertificateProvider() { + this.metadata = new CertificateMetadata(); + metadata.setMetadata(Collections.singletonMap(CertificateMetadata.DIGEST_ALGORITHM_NAME, SignatureAlgorithm.NONE.getValue())); + } + + @Override + public Optional getExpirationDate() { + return Optional.empty(); + } + + @Override + public Flowable privateKey() { + throw new UnsupportedOperationException("No private key for \"none\" algorithm"); + } + + @Override + public Single key() { + throw new UnsupportedOperationException("No key for \"none\" algorithm"); + } + + @Override + public Single publicKey() { + throw new UnsupportedOperationException("No public key for \"none\" algorithm"); + } + + @Override + public Flowable keys() { + throw new UnsupportedOperationException("No keys for \"none\" algorithm"); + } + + @Override + public String signatureAlgorithm() { + return SignatureAlgorithm.NONE.getValue(); + } + + @Override + public CertificateMetadata certificateMetadata() { + return metadata; + } +} diff --git a/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/JavaKeyStore.java b/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/JavaKeyStore.java index 4e8240e8884..9631c7f0369 100644 --- a/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/JavaKeyStore.java +++ b/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/JavaKeyStore.java @@ -17,6 +17,7 @@ import io.gravitee.am.certificate.api.Certificate; import io.gravitee.am.certificate.javakeystore.provider.JavaKeyStoreProvider; + /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team @@ -32,4 +33,5 @@ public Class configuration() { public Class provider() { return JavaKeyStoreProvider.class; } + } diff --git a/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/provider/JavaKeyStoreProvider.java b/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/provider/JavaKeyStoreProvider.java index b392c4cf5ca..8fa2f239772 100644 --- a/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/provider/JavaKeyStoreProvider.java +++ b/gravitee-am-certificate/gravitee-am-certificate-javakeystore/src/main/java/io/gravitee/am/certificate/javakeystore/provider/JavaKeyStoreProvider.java @@ -18,18 +18,27 @@ import io.gravitee.am.certificate.api.AbstractCertificateProvider; import io.gravitee.am.certificate.api.CertificateMetadata; import io.gravitee.am.certificate.javakeystore.JavaKeyStoreConfiguration; +import io.gravitee.am.common.plugin.ValidationResult; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import java.security.KeyStore; import java.security.KeyStoreException; +import java.time.Instant; +import java.util.Date; +import java.util.Map; import java.util.Set; +import static io.gravitee.am.common.plugin.ValidationResult.invalid; +import static io.gravitee.am.common.plugin.ValidationResult.valid; + /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ + public class JavaKeyStoreProvider extends AbstractCertificateProvider implements InitializingBean { + @Autowired private JavaKeyStoreConfiguration configuration; @@ -77,4 +86,16 @@ protected Set getUse() { protected String getAlgorithm() { return configuration.getAlgorithm(); } + + @Override + public ValidationResult validate() { + Date expDate = getExpirationDate().orElse(null); + if(expDate == null) { + return invalid("The certificate you uploaded lacks expiration date."); + } + if (Instant.now().isAfter(expDate.toInstant())) { + return invalid("The certificate you uploaded has already expired. Please select a different certificate to upload."); + } + return valid(Map.of("expDate", expDate)); + } } diff --git a/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/AmPluginProvider.java b/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/AmPluginProvider.java new file mode 100644 index 00000000000..d2a58df3363 --- /dev/null +++ b/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/AmPluginProvider.java @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ +package io.gravitee.am.common.plugin; + +import java.io.Closeable; +import java.io.IOException; + +public interface AmPluginProvider extends Closeable { + + default ValidationResult validate() { + return ValidationResult.SUCCEEDED; + } + + default void unregister() {} + + @Override + default void close() throws IOException { + unregister(); + } + +} diff --git a/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/ValidationResult.java b/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/ValidationResult.java new file mode 100644 index 00000000000..0ccaa0b6e2f --- /dev/null +++ b/gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/ValidationResult.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ +package io.gravitee.am.common.plugin; + +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; +import java.util.Optional; + +@Slf4j +public record ValidationResult(boolean succeeded, String failedMessage, Map additionalInformation){ + public static final ValidationResult SUCCEEDED = new ValidationResult(true, null, Map.of()); + public boolean failed(){ + return !succeeded; + } + + public Optional getAdditionalInformation(String key, Class clazz){ + try { + return Optional.ofNullable(clazz.cast(additionalInformation.get(key))); + } catch (Exception e){ + log.error("Incorrect clazz for key {}: {}", key, clazz); + return Optional.empty(); + } + } + + public static ValidationResult valid(Map additionalInformation){ + return new ValidationResult(true, null, additionalInformation); + } + + public static ValidationResult valid(){ + return valid(Map.of()); + } + + public static ValidationResult invalid(String message){ + return new ValidationResult(false, message, Map.of()); + } +} diff --git a/gravitee-am-deviceidentifier/gravitee-am-deviceidentifier-api/src/main/java/io/gravitee/am/deviceidentifier/api/DeviceIdentifierProvider.java b/gravitee-am-deviceidentifier/gravitee-am-deviceidentifier-api/src/main/java/io/gravitee/am/deviceidentifier/api/DeviceIdentifierProvider.java index 5bb7cbba43e..7b453e7880f 100644 --- a/gravitee-am-deviceidentifier/gravitee-am-deviceidentifier-api/src/main/java/io/gravitee/am/deviceidentifier/api/DeviceIdentifierProvider.java +++ b/gravitee-am-deviceidentifier/gravitee-am-deviceidentifier-api/src/main/java/io/gravitee/am/deviceidentifier/api/DeviceIdentifierProvider.java @@ -15,13 +15,15 @@ */ package io.gravitee.am.deviceidentifier.api; +import io.gravitee.am.common.plugin.AmPluginProvider; + import java.util.Map; /** * @author Rémi Sultan (remi.sultan at graviteesource.com) * @author GraviteeSource Team */ -public interface DeviceIdentifierProvider { +public interface DeviceIdentifierProvider extends AmPluginProvider { void addConfigurationVariables(Map variables, String configuration); diff --git a/gravitee-am-extensiongrant/gravitee-am-extensiongrant-api/src/main/java/io/gravitee/am/extensiongrant/api/ExtensionGrantProvider.java b/gravitee-am-extensiongrant/gravitee-am-extensiongrant-api/src/main/java/io/gravitee/am/extensiongrant/api/ExtensionGrantProvider.java index f24fa5ba035..31bf89ca275 100644 --- a/gravitee-am-extensiongrant/gravitee-am-extensiongrant-api/src/main/java/io/gravitee/am/extensiongrant/api/ExtensionGrantProvider.java +++ b/gravitee-am-extensiongrant/gravitee-am-extensiongrant-api/src/main/java/io/gravitee/am/extensiongrant/api/ExtensionGrantProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.extensiongrant.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.am.identityprovider.api.User; import io.gravitee.am.repository.oauth2.model.request.TokenRequest; import io.reactivex.rxjava3.core.Maybe; @@ -23,7 +24,7 @@ * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public interface ExtensionGrantProvider { +public interface ExtensionGrantProvider extends AmPluginProvider { /** * Grant OAuth2 access tokens by validating the assertion stored inside the incoming token request diff --git a/gravitee-am-factor/gravitee-am-factor-api/src/main/java/io/gravitee/am/factor/api/FactorProvider.java b/gravitee-am-factor/gravitee-am-factor-api/src/main/java/io/gravitee/am/factor/api/FactorProvider.java index 377261811ca..3434ff80e84 100644 --- a/gravitee-am-factor/gravitee-am-factor-api/src/main/java/io/gravitee/am/factor/api/FactorProvider.java +++ b/gravitee-am-factor/gravitee-am-factor-api/src/main/java/io/gravitee/am/factor/api/FactorProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.factor.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.am.model.User; import io.gravitee.am.model.factor.EnrolledFactor; import io.reactivex.rxjava3.core.Completable; @@ -25,7 +26,7 @@ * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public interface FactorProvider { +public interface FactorProvider extends AmPluginProvider { Completable verify(FactorContext context); diff --git a/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-api/src/main/java/io/gravitee/am/gateway/handler/api/ProtocolProvider.java b/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-api/src/main/java/io/gravitee/am/gateway/handler/api/ProtocolProvider.java index 3c17229293d..dacc9abe5a7 100644 --- a/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-api/src/main/java/io/gravitee/am/gateway/handler/api/ProtocolProvider.java +++ b/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-api/src/main/java/io/gravitee/am/gateway/handler/api/ProtocolProvider.java @@ -15,13 +15,14 @@ */ package io.gravitee.am.gateway.handler.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.common.service.Service; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public interface ProtocolProvider extends Service { +public interface ProtocolProvider extends Service, AmPluginProvider { String path(); } diff --git a/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-common/src/main/java/io/gravitee/am/gateway/handler/common/certificate/impl/CertificateManagerImpl.java b/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-common/src/main/java/io/gravitee/am/gateway/handler/common/certificate/impl/CertificateManagerImpl.java index 100c0709390..1f6d93eb9fa 100644 --- a/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-common/src/main/java/io/gravitee/am/gateway/handler/common/certificate/impl/CertificateManagerImpl.java +++ b/gravitee-am-gateway/gravitee-am-gateway-handler/gravitee-am-gateway-handler-common/src/main/java/io/gravitee/am/gateway/handler/common/certificate/impl/CertificateManagerImpl.java @@ -15,12 +15,9 @@ */ package io.gravitee.am.gateway.handler.common.certificate.impl; -import io.gravitee.am.certificate.api.CertificateMetadata; -import io.gravitee.am.certificate.api.DefaultKey; -import io.gravitee.am.certificate.api.Keys; +import io.gravitee.am.certificate.api.CertificateProviders; import io.gravitee.am.common.event.CertificateEvent; import io.gravitee.am.common.event.EventManager; -import io.gravitee.am.common.jwt.SignatureAlgorithm; import io.gravitee.am.gateway.certificate.CertificateProvider; import io.gravitee.am.gateway.certificate.CertificateProviderManager; import io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderCertificateReloader; @@ -29,25 +26,19 @@ import io.gravitee.am.model.Domain; import io.gravitee.am.model.ReferenceType; import io.gravitee.am.model.common.event.Payload; -import io.gravitee.am.model.jose.JWK; import io.gravitee.am.repository.management.api.CertificateRepository; import io.gravitee.common.event.Event; import io.gravitee.common.event.EventListener; import io.gravitee.common.service.AbstractService; import io.gravitee.node.api.configuration.Configuration; -import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Maybe; -import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.schedulers.Schedulers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import java.security.InvalidKeyException; -import java.security.Key; import java.util.Collection; -import java.util.Collections; -import java.util.Date; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -237,96 +228,11 @@ private void removeCertificate(String certificateId) { } private void initDefaultCertificateProvider() throws InvalidKeyException { - // create default signing HMAC key - byte[] keySecretBytes = signingKeySecret().getBytes(); - Key key = Keys.hmacShaKeyFor(keySecretBytes); - SignatureAlgorithm signatureAlgorithm = Keys.hmacShaSignatureAlgorithmFor(keySecretBytes); - io.gravitee.am.certificate.api.Key certificateKey = new DefaultKey(signingKeyId(), key); - - // create default certificate provider - CertificateMetadata certificateMetadata = new CertificateMetadata(); - certificateMetadata.setMetadata(Collections.singletonMap(CertificateMetadata.DIGEST_ALGORITHM_NAME, signatureAlgorithm.getDigestName())); - - io.gravitee.am.certificate.api.CertificateProvider defaultProvider = new io.gravitee.am.certificate.api.CertificateProvider() { - @Override - public Optional getExpirationDate() { - return Optional.empty(); - } - - @Override - public Single key() { - return Single.just(certificateKey); - } - - @Override - public Flowable privateKey() { - return null; - } - - @Override - public Single publicKey() { - return null; - } - - @Override - public Flowable keys() { - return null; - } - - @Override - public String signatureAlgorithm() { - return signatureAlgorithm.getValue(); - } - - @Override - public CertificateMetadata certificateMetadata() { - return certificateMetadata; - } - }; - this.defaultCertificateProvider = certificateProviderManager.create(defaultProvider); + this.defaultCertificateProvider = certificateProviderManager.create(CertificateProviders.createShaCertificateProvider(signingKeyId(), signingKeySecret())); } private void initNoneAlgorithmCertificateProvider() { - CertificateMetadata certificateMetadata = new CertificateMetadata(); - certificateMetadata.setMetadata(Collections.singletonMap(CertificateMetadata.DIGEST_ALGORITHM_NAME, SignatureAlgorithm.NONE.getValue())); - - io.gravitee.am.certificate.api.CertificateProvider noneProvider = new io.gravitee.am.certificate.api.CertificateProvider() { - @Override - public Optional getExpirationDate() { - return Optional.empty(); - } - - @Override - public Flowable privateKey() { - throw new UnsupportedOperationException("No private key for \"none\" algorithm"); - } - - @Override - public Single key() { - throw new UnsupportedOperationException("No key for \"none\" algorithm"); - } - - @Override - public Single publicKey() { - throw new UnsupportedOperationException("No public key for \"none\" algorithm"); - } - - @Override - public Flowable keys() { - throw new UnsupportedOperationException("No keys for \"none\" algorithm"); - } - - @Override - public String signatureAlgorithm() { - return SignatureAlgorithm.NONE.getValue(); - } - - @Override - public CertificateMetadata certificateMetadata() { - return certificateMetadata; - } - }; - this.noneAlgorithmCertificateProvider = certificateProviderManager.create(noneProvider); + this.noneAlgorithmCertificateProvider = certificateProviderManager.create(CertificateProviders.createNoneCertificateProvider()); } private String signingKeySecret() { diff --git a/gravitee-am-gateway/gravitee-am-gateway-standalone/gravitee-am-gateway-standalone-container/src/main/java/io/gravitee/am/gateway/spring/StandaloneConfiguration.java b/gravitee-am-gateway/gravitee-am-gateway-standalone/gravitee-am-gateway-standalone-container/src/main/java/io/gravitee/am/gateway/spring/StandaloneConfiguration.java index b1042de6da0..07d0df48c2d 100644 --- a/gravitee-am-gateway/gravitee-am-gateway-standalone/gravitee-am-gateway-standalone-container/src/main/java/io/gravitee/am/gateway/spring/StandaloneConfiguration.java +++ b/gravitee-am-gateway/gravitee-am-gateway-standalone/gravitee-am-gateway-standalone-container/src/main/java/io/gravitee/am/gateway/spring/StandaloneConfiguration.java @@ -33,6 +33,7 @@ import io.gravitee.am.plugins.deviceidentifier.spring.DeviceIdentifierSpringConfiguration; import io.gravitee.am.plugins.extensiongrant.spring.ExtensionGrantSpringConfiguration; import io.gravitee.am.plugins.factor.spring.FactorSpringConfiguration; +import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.plugins.idp.spring.IdentityProviderSpringConfiguration; import io.gravitee.am.plugins.policy.spring.PolicySpringConfiguration; import io.gravitee.am.plugins.protocol.spring.ProtocolSpringConfiguration; @@ -139,4 +140,9 @@ public PropertySourceFallbackConfigurer propertySourceFallbackConfigurer(Environ public RepositoriesEnvironment repositoriesEnvironment(Environment environment){ return new RepositoriesEnvironment(environment); } + + @Bean + public PluginConfigurationValidatorsRegistry pluginConfigurationValidatorsRegistry(){ + return new PluginConfigurationValidatorsRegistry(); + } } diff --git a/gravitee-am-identityprovider/gravitee-am-identityprovider-api/src/main/java/io/gravitee/am/identityprovider/api/AuthenticationProvider.java b/gravitee-am-identityprovider/gravitee-am-identityprovider-api/src/main/java/io/gravitee/am/identityprovider/api/AuthenticationProvider.java index 1743b711a40..2974cb59df0 100644 --- a/gravitee-am-identityprovider/gravitee-am-identityprovider-api/src/main/java/io/gravitee/am/identityprovider/api/AuthenticationProvider.java +++ b/gravitee-am-identityprovider/gravitee-am-identityprovider-api/src/main/java/io/gravitee/am/identityprovider/api/AuthenticationProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.identityprovider.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.common.component.Lifecycle; import io.gravitee.common.service.Service; import io.reactivex.rxjava3.core.Maybe; @@ -24,7 +25,7 @@ * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public interface AuthenticationProvider extends Service { +public interface AuthenticationProvider extends Service, AmPluginProvider { String ACTUAL_USERNAME = "actual_username"; diff --git a/gravitee-am-management-api/gravitee-am-management-api-rest/src/test/java/io/gravitee/am/management/handlers/management/api/JerseySpringTest.java b/gravitee-am-management-api/gravitee-am-management-api-rest/src/test/java/io/gravitee/am/management/handlers/management/api/JerseySpringTest.java index eba2fea5e3b..3dd890a8582 100644 --- a/gravitee-am-management-api/gravitee-am-management-api-rest/src/test/java/io/gravitee/am/management/handlers/management/api/JerseySpringTest.java +++ b/gravitee-am-management-api/gravitee-am-management-api-rest/src/test/java/io/gravitee/am/management/handlers/management/api/JerseySpringTest.java @@ -48,6 +48,7 @@ import io.gravitee.am.management.service.TagService; import io.gravitee.am.management.service.permissions.PermissionAcls; import io.gravitee.am.plugins.handlers.api.core.AmPluginManager; +import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.service.ApplicationService; import io.gravitee.am.service.AuditService; import io.gravitee.am.service.BotDetectionService; @@ -82,7 +83,6 @@ import io.gravitee.am.service.validators.email.UserEmailConstraintValidator; import io.gravitee.am.service.validators.email.resource.EmailTemplateValidator; import io.gravitee.am.service.validators.flow.FlowValidator; -import io.gravitee.am.service.validators.jsonstring.JsonStringValidator; import io.gravitee.am.service.validators.plugincfg.PluginJsonFormValidator; import io.gravitee.am.service.validators.user.UserValidator; import io.reactivex.rxjava3.core.Completable; @@ -308,12 +308,7 @@ public UserEmailConstraintValidator userEmailConstraintValidator(){ @Bean public PluginJsonFormValidator pluginJsonFormValidator(){ - return new PluginJsonFormValidator(List.of()); - } - - @Bean - public JsonStringValidator jsonStringValidator(ObjectMapper objectMapper){ - return new JsonStringValidator(objectMapper); + return new PluginJsonFormValidator(new PluginConfigurationValidatorsRegistry()); } @Bean diff --git a/gravitee-am-management-api/gravitee-am-management-api-standalone/gravitee-am-management-api-standalone-container/src/main/java/io/gravitee/am/management/standalone/spring/StandaloneConfiguration.java b/gravitee-am-management-api/gravitee-am-management-api-standalone/gravitee-am-management-api-standalone-container/src/main/java/io/gravitee/am/management/standalone/spring/StandaloneConfiguration.java index a65a3f9ba2f..82884b8510d 100644 --- a/gravitee-am-management-api/gravitee-am-management-api-standalone/gravitee-am-management-api-standalone-container/src/main/java/io/gravitee/am/management/standalone/spring/StandaloneConfiguration.java +++ b/gravitee-am-management-api/gravitee-am-management-api-standalone/gravitee-am-management-api-standalone-container/src/main/java/io/gravitee/am/management/standalone/spring/StandaloneConfiguration.java @@ -28,6 +28,7 @@ import io.gravitee.am.plugins.deviceidentifier.spring.DeviceIdentifierSpringConfiguration; import io.gravitee.am.plugins.extensiongrant.spring.ExtensionGrantSpringConfiguration; import io.gravitee.am.plugins.factor.spring.FactorSpringConfiguration; +import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.plugins.idp.spring.IdentityProviderSpringConfiguration; import io.gravitee.am.plugins.notifier.spring.NotifierConfiguration; import io.gravitee.am.plugins.policy.spring.PolicySpringConfiguration; @@ -134,4 +135,9 @@ public RepositoriesEnvironment repositoriesEnvironment(Environment environment){ return new RepositoriesEnvironment(environment); } + @Bean + public PluginConfigurationValidatorsRegistry pluginConfigurationValidatorsRegistry(){ + return new PluginConfigurationValidatorsRegistry(); + } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidator.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidator.java index 8c8172d5d3a..7f807650d07 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidator.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidator.java @@ -15,23 +15,29 @@ */ package io.gravitee.am.plugins.handlers.api.core; -import io.gravitee.json.validation.InvalidJsonException; import io.gravitee.json.validation.JsonSchemaValidator; +import io.gravitee.json.validation.JsonSchemaValidatorImpl; import lombok.Getter; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class PluginConfigurationValidator { + private static final JsonSchemaValidatorImpl SCHEMA_VALIDATOR = new JsonSchemaValidatorImpl(); + @Getter private final String pluginIdentifier; private final String schema; private final JsonSchemaValidator jsonSchemaValidator; + public static PluginConfigurationValidator defaultSchemaValidator(String pluginIdentifier, String schema){ + return new PluginConfigurationValidator(pluginIdentifier, schema, SCHEMA_VALIDATOR); + } + public Result validate(String pluginData) { try { jsonSchemaValidator.validate(schema, pluginData); return Result.VALID_RESPONSE; - } catch (InvalidJsonException e) { + } catch (Exception e) { return new Result(false, e.getMessage()); } } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistry.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistry.java index e121d15ab8f..5d6c09656ac 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistry.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistry.java @@ -15,12 +15,10 @@ */ package io.gravitee.am.plugins.handlers.api.core; -import lombok.RequiredArgsConstructor; - import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -@RequiredArgsConstructor public class PluginConfigurationValidatorsRegistry { private final Map validators = new ConcurrentHashMap<>(); @@ -28,11 +26,7 @@ public void put(PluginConfigurationValidator validator){ this.validators.put(validator.getPluginIdentifier(), validator); } - public PluginConfigurationValidator get(String id){ - return validators.get(id); - } - - public boolean contains(String id){ - return validators.containsKey(id); + public Optional get(String id){ + return Optional.ofNullable(validators.get(id)); } } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/ProviderPluginManager.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/ProviderPluginManager.java index 544eeab0e00..6351a094365 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/ProviderPluginManager.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/core/ProviderPluginManager.java @@ -16,6 +16,8 @@ package io.gravitee.am.plugins.handlers.api.core; import io.gravitee.am.common.plugin.AmPlugin; +import io.gravitee.am.common.plugin.AmPluginProvider; +import io.gravitee.am.common.plugin.ValidationResult; import io.gravitee.am.plugins.handlers.api.provider.ProviderConfiguration; import io.gravitee.common.service.AbstractService; import io.gravitee.common.service.Service; @@ -29,11 +31,13 @@ import java.util.List; +import static java.util.Optional.ofNullable; + /** * @author Rémi SULTAN (remi.sultan at graviteesource.com) * @author GraviteeSource Team */ -public abstract class ProviderPluginManager, PROVIDER, PROVIDER_CONFIG extends ProviderConfiguration> +public abstract class ProviderPluginManager, PROVIDER extends AmPluginProvider, PROVIDER_CONFIG extends ProviderConfiguration> extends AbstractConfigurablePluginManager { private final static Logger logger = LoggerFactory.getLogger(ProviderPluginManager.class); @@ -46,6 +50,10 @@ protected ProviderPluginManager(PluginContextFactory pluginContextFactory) { public abstract PROVIDER create(PROVIDER_CONFIG config); + public ValidationResult validate(PROVIDER_CONFIG config) { + return ValidationResult.SUCCEEDED; + } + public Plugin findById(String pluginId) { return get(pluginId); } @@ -58,9 +66,19 @@ protected T createProvider(INSTANCE plugin, List(plugin.getDelegate(), (Class) plugin.provider(), postProcessors)); } + protected ValidationResult validateProvider(INSTANCE plugin, List postProcessors) { + try (var provider = createProvider(plugin, postProcessors)) { + return provider.validate(); + } catch (Exception e) { + logger.error("Plugin configuration error", e); + return ValidationResult.invalid("The configuration details entered are incorrect. Please check those and try again."); + } + } + private T createProvider(AmPluginContextConfigurer amPluginContextConfigurer) { try { var pluginApplicationContext = pluginContextFactory.create(amPluginContextConfigurer); @@ -95,4 +113,14 @@ protected T createInstance(Class clazz) throws Exception { public boolean isPluginDeployed(String pluginTypeId) { return this.findAll().stream().anyMatch(p -> p.getDelegate().id().equals(pluginTypeId)); } + + protected INSTANCE getOrThrow(PROVIDER_CONFIG providerConfig) { + logger.debug("Looking for a provider for [{}]", providerConfig.getType()); + + return ofNullable(get(providerConfig.getType())).orElseGet(() -> { + logger.error("No plugin is registered for type {}", providerConfig.getType()); + throw new IllegalStateException("No plugin is registered for type " + providerConfig.getType()); + }); + } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/plugin/AmPluginHandler.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/plugin/AmPluginHandler.java index a30f1842ce0..4c3ca26d726 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/plugin/AmPluginHandler.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/main/java/io/gravitee/am/plugins/handlers/api/plugin/AmPluginHandler.java @@ -26,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.Assert; +import static io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidator.defaultSchemaValidator; + /** * @author Rémi SULTAN (remi.sultan at graviteesource.com) * @author GraviteeSource Team @@ -65,8 +67,9 @@ protected void handle(Plugin plugin, Class pluginClass) { Assert.isAssignable(getClazz(), pluginClass); pluginManager.register(createInstance(pluginClass, plugin)); + registerValidator(plugin); } catch (Exception iae) { - getLogger().error("Unexpected error while create bot detection instance", iae); + getLogger().error("Unexpected error while create plugin instance", iae); } } @@ -86,4 +89,13 @@ protected T createInstance(Class pluginClass, Plugin plugin) throws Exception } } + private void registerValidator(Plugin plugin){ + try { + getLogger().info("Registering a new plugin validator: {} [{}]", plugin.id(), plugin.clazz()); + validatorsRegistry.put(defaultSchemaValidator(plugin.id(), pluginManager.getSchema(plugin.id()))); + } catch (Exception iae) { + getLogger().error("Unexpected error while creating plugin schema validator", iae); + } + } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/test/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistryTest.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/test/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistryTest.java index d5c1eff9326..54904051924 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/test/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistryTest.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-api/src/test/java/io/gravitee/am/plugins/handlers/api/core/PluginConfigurationValidatorsRegistryTest.java @@ -33,13 +33,13 @@ public void added_plugin_validator_should_be_accessible() { registry.put(validator); // expect - Assertions.assertEquals(validator, registry.get("id")); + Assertions.assertEquals(validator, registry.get("id").get()); } @Test public void should_return_null_if_validator_is_not_found() { // expect - Assertions.assertNull(registry.get("id")); + Assertions.assertTrue(registry.get("id").isEmpty()); } } \ No newline at end of file diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-authdevice-notifier/src/main/java/io/gravitee/am/plugins/authdevice/notifier/spring/AuthenticationDeviceNotifierSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-authdevice-notifier/src/main/java/io/gravitee/am/plugins/authdevice/notifier/spring/AuthenticationDeviceNotifierSpringConfiguration.java index a7e65e4ec1b..8817a48a266 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-authdevice-notifier/src/main/java/io/gravitee/am/plugins/authdevice/notifier/spring/AuthenticationDeviceNotifierSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-authdevice-notifier/src/main/java/io/gravitee/am/plugins/authdevice/notifier/spring/AuthenticationDeviceNotifierSpringConfiguration.java @@ -42,4 +42,5 @@ public AuthenticationDeviceNotifierPluginManager authDeviceNotifierPluginManager public ConfigurationFactory authDeviceNotifierConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/core/BotDetectionPluginManager.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/core/BotDetectionPluginManager.java index 54c1bf6e6e2..b951712c405 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/core/BotDetectionPluginManager.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/core/BotDetectionPluginManager.java @@ -24,10 +24,6 @@ import io.gravitee.am.plugins.handlers.api.core.ProviderPluginManager; import io.gravitee.am.plugins.handlers.api.provider.ProviderConfiguration; import io.gravitee.plugin.core.api.PluginContextFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.util.Optional.ofNullable; /** * @author Eric LELEU (eric.leleu at graviteesource.com) @@ -38,7 +34,6 @@ public class BotDetectionPluginManager extends ProviderPluginManager, BotDetectionProvider, ProviderConfiguration> implements AmPluginManager> { - private static final Logger logger = LoggerFactory.getLogger(BotDetectionPluginManager.class); private final ConfigurationFactory configurationFactory; public BotDetectionPluginManager( @@ -50,13 +45,7 @@ public BotDetectionPluginManager( @Override public BotDetectionProvider create(ProviderConfiguration providerConfig) { - logger.debug("Looking for a bot detection for [{}]", providerConfig.getType()); - - var botDetection = ofNullable(get(providerConfig.getType())).orElseGet(() -> { - logger.error("No bot detection is registered for type {}", providerConfig.getType()); - throw new IllegalStateException("No bot detection is registered for type " + providerConfig.getType()); - }); - + var botDetection = getOrThrow(providerConfig); var configuration = configurationFactory.create(botDetection.configuration(), providerConfig.getConfiguration()); return createProvider(botDetection, new BotDetectionConfigurationBeanFactoryPostProcessor(configuration)); } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/spring/BotDetectionSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/spring/BotDetectionSpringConfiguration.java index 34a3c86deb5..135b04fd435 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/spring/BotDetectionSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-botdetection/src/main/java/io/gravitee/am/plugins/botdetection/spring/BotDetectionSpringConfiguration.java @@ -42,4 +42,5 @@ public BotDetectionPluginManager botDetectionPluginManager( public ConfigurationFactory botDetectionConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/core/CertificatePluginManager.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/core/CertificatePluginManager.java index b96e6926bf9..5da810d16bf 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/core/CertificatePluginManager.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/core/CertificatePluginManager.java @@ -19,18 +19,15 @@ import io.gravitee.am.certificate.api.CertificateConfiguration; import io.gravitee.am.certificate.api.CertificateMetadata; import io.gravitee.am.certificate.api.CertificateProvider; +import io.gravitee.am.common.plugin.ValidationResult; import io.gravitee.am.plugins.handlers.api.core.AmPluginManager; import io.gravitee.am.plugins.handlers.api.core.ConfigurationFactory; import io.gravitee.am.plugins.handlers.api.core.NamedBeanFactoryPostProcessor; import io.gravitee.am.plugins.handlers.api.core.ProviderPluginManager; import io.gravitee.plugin.core.api.PluginContextFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; -import static java.util.Optional.ofNullable; - /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author Rémi SULTAN (remi.sultan at graviteesource.com) @@ -39,9 +36,6 @@ public class CertificatePluginManager extends ProviderPluginManager, CertificateProvider, CertificateProviderConfiguration> implements AmPluginManager> { - - private final Logger logger = LoggerFactory.getLogger(CertificatePluginManager.class); - private final ConfigurationFactory configurationFactory; public CertificatePluginManager( @@ -54,25 +48,34 @@ public CertificatePluginManager( @Override public CertificateProvider create(CertificateProviderConfiguration providerConfig) { - logger.debug("Looking for a certificate provider for [{}]", providerConfig.getType()); - var certificatePlugin = ofNullable(get(providerConfig.getType())).orElseGet(() -> { - logger.error("No certificate provider is registered for type {}", providerConfig.getType()); - throw new IllegalStateException("No certificate provider is registered for type " + providerConfig.getType()); - }); + Certificate certificatePlugin = getOrThrow(providerConfig); - var certificateConfiguration = configurationFactory.create(certificatePlugin.configuration(), providerConfig.getConfiguration()); + CertificateConfiguration certificateConfiguration = configurationFactory.create(certificatePlugin.configuration(), providerConfig.getConfiguration()); return createProvider(certificatePlugin, List.of( new CertificateConfigurationBeanFactoryPostProcessor(certificateConfiguration), new CertificateMetadataBeanFactoryPostProcessor(getCertificateMetadata(providerConfig)) )); } + @Override + public ValidationResult validate(CertificateProviderConfiguration providerConfig) { + Certificate certificatePlugin = getOrThrow(providerConfig); + + CertificateConfiguration certificateConfiguration = configurationFactory.create(certificatePlugin.configuration(), providerConfig.getConfiguration()); + return validateProvider(certificatePlugin, List.of( + new CertificateConfigurationBeanFactoryPostProcessor(certificateConfiguration), + new CertificateMetadataBeanFactoryPostProcessor(getCertificateMetadata(providerConfig)) + )); + } + private static CertificateMetadata getCertificateMetadata(CertificateProviderConfiguration providerConfig) { CertificateMetadata certificateMetadata = new CertificateMetadata(); certificateMetadata.setMetadata(providerConfig.getMetadata()); return certificateMetadata; } + + private static class CertificateMetadataBeanFactoryPostProcessor extends NamedBeanFactoryPostProcessor { private CertificateMetadataBeanFactoryPostProcessor(CertificateMetadata metadata) { super("metadata", metadata); diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/plugin/CertificatePluginHandler.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/plugin/CertificatePluginHandler.java index 67b8f712566..3d772cea46e 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/plugin/CertificatePluginHandler.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/plugin/CertificatePluginHandler.java @@ -16,15 +16,11 @@ package io.gravitee.am.plugins.certificate.plugin; import io.gravitee.am.certificate.api.Certificate; -import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidator; -import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.plugins.handlers.api.plugin.AmPluginHandler; -import io.gravitee.json.validation.JsonSchemaValidatorImpl; import io.gravitee.plugin.core.api.Plugin; import io.gravitee.plugin.core.api.PluginType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) @@ -35,31 +31,11 @@ public class CertificatePluginHandler extends AmPluginHandler> private final Logger LOGGER = LoggerFactory.getLogger(CertificatePluginHandler.class); - @Autowired - private PluginConfigurationValidatorsRegistry validatorsRegistry; - @Override public boolean canHandle(Plugin plugin) { return type().equalsIgnoreCase(plugin.type()); } - @Override - protected void handle(Plugin plugin, Class pluginClass) { - super.handle(plugin, pluginClass); - if (pluginManager.findById(plugin.id()) != null) { - registerValidator(plugin); - } - } - - private void registerValidator(Plugin plugin){ - try { - getLogger().info("Register a new plugin validator: {} [{}]", plugin.id(), plugin.clazz()); - validatorsRegistry.put(new PluginConfigurationValidator(plugin.id(), pluginManager.getSchema(plugin.id()), new JsonSchemaValidatorImpl())); - } catch (Exception iae) { - getLogger().error("Unexpected error while create certificate schema validator", iae); - } - } - @Override protected Logger getLogger() { return LOGGER; diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/spring/CertificateSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/spring/CertificateSpringConfiguration.java index f4da6024056..ccdfee050ef 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/spring/CertificateSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-certificate/src/main/java/io/gravitee/am/plugins/certificate/spring/CertificateSpringConfiguration.java @@ -18,7 +18,6 @@ import io.gravitee.am.certificate.api.CertificateConfiguration; import io.gravitee.am.plugins.certificate.core.CertificatePluginManager; import io.gravitee.am.plugins.handlers.api.core.ConfigurationFactory; -import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.plugins.handlers.api.core.impl.ConfigurationFactoryImpl; import io.gravitee.plugin.core.api.PluginContextFactory; import org.springframework.context.annotation.Bean; @@ -34,9 +33,9 @@ public class CertificateSpringConfiguration { @Bean public CertificatePluginManager certificatePluginManager( PluginContextFactory pluginContextFactory, - ConfigurationFactory botDetectionConfigurationFactory + ConfigurationFactory certConfigurationFactory ) { - return new CertificatePluginManager(pluginContextFactory, botDetectionConfigurationFactory); + return new CertificatePluginManager(pluginContextFactory, certConfigurationFactory); } @Bean @@ -44,9 +43,4 @@ public ConfigurationFactory certificateConfigurationFa return new ConfigurationFactoryImpl<>(); } - @Bean - public PluginConfigurationValidatorsRegistry certificateValidatorsRegistry(){ - return new PluginConfigurationValidatorsRegistry(); - } - } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-deviceidentifier/src/main/java/io/gravitee/am/plugins/deviceidentifier/spring/DeviceIdentifierSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-deviceidentifier/src/main/java/io/gravitee/am/plugins/deviceidentifier/spring/DeviceIdentifierSpringConfiguration.java index 0986d00b8a8..a6e96482aa5 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-deviceidentifier/src/main/java/io/gravitee/am/plugins/deviceidentifier/spring/DeviceIdentifierSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-deviceidentifier/src/main/java/io/gravitee/am/plugins/deviceidentifier/spring/DeviceIdentifierSpringConfiguration.java @@ -42,4 +42,5 @@ public DeviceIdentifierPluginManager deviceIdentifierPluginManager( public ConfigurationFactory deviceIdentifierConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-extensiongrant/src/main/java/io/gravitee/am/plugins/extensiongrant/spring/ExtensionGrantSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-extensiongrant/src/main/java/io/gravitee/am/plugins/extensiongrant/spring/ExtensionGrantSpringConfiguration.java index bd33dcb8671..1d57fe1ed16 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-extensiongrant/src/main/java/io/gravitee/am/plugins/extensiongrant/spring/ExtensionGrantSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-extensiongrant/src/main/java/io/gravitee/am/plugins/extensiongrant/spring/ExtensionGrantSpringConfiguration.java @@ -42,4 +42,5 @@ public ExtensionGrantPluginManager extensionGrantPluginManager( public ConfigurationFactory extensionGrantConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-identityprovider/src/main/java/io/gravitee/am/plugins/idp/spring/IdentityProviderSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-identityprovider/src/main/java/io/gravitee/am/plugins/idp/spring/IdentityProviderSpringConfiguration.java index 0d0fde6ba6c..03302fbd358 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-identityprovider/src/main/java/io/gravitee/am/plugins/idp/spring/IdentityProviderSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-identityprovider/src/main/java/io/gravitee/am/plugins/idp/spring/IdentityProviderSpringConfiguration.java @@ -81,4 +81,5 @@ public IdentityProviderRoleMapperFactory identityProviderRoleMapperFactory() { public IdentityProviderGroupMapperFactory identityProviderGroupMapperFactory() { return new IdentityProviderGroupMapperFactoryImpl(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-policy/src/main/java/io/gravitee/am/plugins/policy/spring/PolicySpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-policy/src/main/java/io/gravitee/am/plugins/policy/spring/PolicySpringConfiguration.java index 23c9e74f12e..26e2e79db9a 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-policy/src/main/java/io/gravitee/am/plugins/policy/spring/PolicySpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-policy/src/main/java/io/gravitee/am/plugins/policy/spring/PolicySpringConfiguration.java @@ -39,4 +39,5 @@ public PolicyPluginManager policyPluginManager() { public ConfigurationFactory policyConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-protocol/src/main/java/io/gravitee/am/plugins/protocol/spring/ProtocolSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-protocol/src/main/java/io/gravitee/am/plugins/protocol/spring/ProtocolSpringConfiguration.java index 8f63aaa8bb8..df6440d2300 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-protocol/src/main/java/io/gravitee/am/plugins/protocol/spring/ProtocolSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-protocol/src/main/java/io/gravitee/am/plugins/protocol/spring/ProtocolSpringConfiguration.java @@ -36,4 +36,5 @@ public ProtocolPluginManager protocolPluginManager( ) { return new ProtocolPluginManager(pluginContextFactory, pluginClassLoaderFactory); } + } diff --git a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-reporter/src/main/java/io/gravitee/am/plugins/reporter/spring/ReporterSpringConfiguration.java b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-reporter/src/main/java/io/gravitee/am/plugins/reporter/spring/ReporterSpringConfiguration.java index b9aab2c1d70..e68cf23507f 100644 --- a/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-reporter/src/main/java/io/gravitee/am/plugins/reporter/spring/ReporterSpringConfiguration.java +++ b/gravitee-am-plugins-handlers/gravitee-am-plugins-handlers-reporter/src/main/java/io/gravitee/am/plugins/reporter/spring/ReporterSpringConfiguration.java @@ -42,4 +42,5 @@ public ReporterPluginManager reporterPluginManager( public ConfigurationFactory reporterConfigurationFactory() { return new ConfigurationFactoryImpl<>(); } + } diff --git a/gravitee-am-reporter/gravitee-am-reporter-api/src/main/java/io/gravitee/am/reporter/api/audit/AuditReporter.java b/gravitee-am-reporter/gravitee-am-reporter-api/src/main/java/io/gravitee/am/reporter/api/audit/AuditReporter.java index a64a63dbb61..4887bfe64a1 100644 --- a/gravitee-am-reporter/gravitee-am-reporter-api/src/main/java/io/gravitee/am/reporter/api/audit/AuditReporter.java +++ b/gravitee-am-reporter/gravitee-am-reporter-api/src/main/java/io/gravitee/am/reporter/api/audit/AuditReporter.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.reporter.api.audit; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.am.reporter.api.audit.model.Audit; import io.gravitee.am.reporter.api.provider.Reporter; @@ -22,5 +23,5 @@ * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public interface AuditReporter extends Reporter { +public interface AuditReporter extends Reporter, AmPluginProvider { } diff --git a/gravitee-am-resource/gravitee-am-resource-api/src/main/java/io/gravitee/am/resource/api/ResourceProvider.java b/gravitee-am-resource/gravitee-am-resource-api/src/main/java/io/gravitee/am/resource/api/ResourceProvider.java index fe0f2b0d843..98718552983 100644 --- a/gravitee-am-resource/gravitee-am-resource-api/src/main/java/io/gravitee/am/resource/api/ResourceProvider.java +++ b/gravitee-am-resource/gravitee-am-resource-api/src/main/java/io/gravitee/am/resource/api/ResourceProvider.java @@ -15,6 +15,7 @@ */ package io.gravitee.am.resource.api; +import io.gravitee.am.common.plugin.AmPluginProvider; import io.gravitee.common.component.Lifecycle; import io.gravitee.common.service.Service; @@ -22,7 +23,7 @@ * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public interface ResourceProvider extends Service { +public interface ResourceProvider extends Service, AmPluginProvider { @Override default Lifecycle.State lifecycleState() { diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/impl/CertificateServiceImpl.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/impl/CertificateServiceImpl.java index 331a3f45bc5..1b40f96ddd9 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/impl/CertificateServiceImpl.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/impl/CertificateServiceImpl.java @@ -87,9 +87,7 @@ import java.security.KeyPairGenerator; import java.security.KeyStore; import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; import java.security.cert.X509Certificate; -import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Base64; @@ -211,7 +209,7 @@ public Single create(String domain, NewCertificate newCertificate, var certificate = schema.getFileKey() .map(fileKey -> createCertificateWithEmbeddedKeys(domain, newCertificate, isSystem, fileKey)) .orElseGet(() -> createCertificate(domain, newCertificate, isSystem)); - return certificateRepository.create(getValid(certificate)); + return certificateRepository.create(validate(certificate)); } catch (CertificateException ex) { log.error("An error occurs while trying to create certificate configuration", ex); return Single.error(ex); @@ -290,7 +288,7 @@ public Single update(String domain, String id, UpdateCertificate up .flatMap(oldCertificate -> { try { var certificate = getCertificateToUpdate(updateCertificate, oldCertificate); - return certificateRepository.update(getValid(certificate)); + return certificateRepository.update(validate(certificate)); } catch (IOException | CertificateException ex) { log.error("An error occurs while trying to update certificate binaries", ex); return Single.error(ex); @@ -563,22 +561,14 @@ private X509Certificate generateCertificate(String dn, KeyPair keyPair, int vali return new JcaX509CertificateConverter().setProvider(BouncyCastleProviderSingleton.getInstance()).getCertificate(certBuilder.build(contentSigner)); } - private Certificate getValid(Certificate certificate) throws CertificateException { + private Certificate validate(Certificate certificate) throws CertificateException { var providerConfig = new CertificateProviderConfiguration(certificate); - var certificateProvider = certificatePluginManager.create(providerConfig); - if (certificateProvider == null) { - throw new CertificateException("The configuration details entered are incorrect. Please check those and try again."); + var validationResult = certificatePluginManager.validate(providerConfig); + if (validationResult.failed()) { + throw new CertificateException(validationResult.failedMessage()); } - var expiryDate = certificateProvider.getExpirationDate().orElse(null); - if (expiryDate != null) { - if (Instant.now().isAfter(expiryDate.toInstant())) { - throw new CertificateExpiredException("The certificate you uploaded has already expired. Please select a different certificate to upload."); - } - if (certificate.getExpiresAt() == null) { - certificate.setExpiresAt(expiryDate); - } - } - certificateProvider.unregister(); + validationResult.getAdditionalInformation("expDate", Date.class) + .ifPresent(certificate::setExpiresAt); return certificate; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAlertNotifier.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAlertNotifier.java index 4fcc17bb3f8..673ec991992 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAlertNotifier.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAlertNotifier.java @@ -17,7 +17,6 @@ import io.gravitee.am.model.ReferenceType; import io.gravitee.am.model.alert.AlertNotifier; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -25,7 +24,7 @@ * @author Jeoffrey HAEYAERT (jeoffrey.haeyaert at graviteesource.com) * @author GraviteeSource Team */ -public class NewAlertNotifier { +public class NewAlertNotifier implements PluginConfigurationPayload { @NotEmpty private String type; @@ -36,7 +35,6 @@ public class NewAlertNotifier { private boolean enabled; @NotNull - @JsonString private String configuration; public AlertNotifier toAlertNotifier(ReferenceType refType, String refId) { diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAuthenticationDeviceNotifier.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAuthenticationDeviceNotifier.java index fa28c832640..1f3986a4896 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAuthenticationDeviceNotifier.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewAuthenticationDeviceNotifier.java @@ -15,14 +15,18 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class NewAuthenticationDeviceNotifier { + +@Getter +@Setter +public class NewAuthenticationDeviceNotifier implements PluginConfigurationPayload { private String id; @@ -33,40 +37,8 @@ public class NewAuthenticationDeviceNotifier { private String name; @NotNull - @JsonString private String configuration; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } @Override public String toString() { diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewBotDetection.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewBotDetection.java index 0e25580e445..0262c3f61a3 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewBotDetection.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewBotDetection.java @@ -15,14 +15,18 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class NewBotDetection { + +@Getter +@Setter +public class NewBotDetection implements PluginConfigurationPayload { private String id; @@ -36,49 +40,8 @@ public class NewBotDetection { private String name; @NotNull - @JsonString private String configuration; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDetectionType() { - return detectionType; - } - - public void setDetectionType(String detectionType) { - this.detectionType = detectionType; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "NewBotDetection{" + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewCertificate.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewCertificate.java index 7d5c1661920..fbb28c59bc6 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewCertificate.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewCertificate.java @@ -15,7 +15,6 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -32,7 +31,6 @@ public class NewCertificate implements PluginConfigurationPayload { private String name; @NotNull - @JsonString private String configuration; public String getType() { diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewDeviceIdentifier.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewDeviceIdentifier.java index 9db869e1d70..631c3f5b702 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewDeviceIdentifier.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewDeviceIdentifier.java @@ -15,14 +15,17 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Rémi SULTAN (remi.sultan at graviteesource.com) * @author GraviteeSource Team */ -public class NewDeviceIdentifier { +@Getter +@Setter +public class NewDeviceIdentifier implements PluginConfigurationPayload { private String id; @@ -33,41 +36,8 @@ public class NewDeviceIdentifier { private String name; @NotNull - @JsonString private String configuration; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "NewDeviceIdentifier{" + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewExtensionGrant.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewExtensionGrant.java index 3fa25e49522..e1da7d2cb21 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewExtensionGrant.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewExtensionGrant.java @@ -15,15 +15,18 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; +import lombok.Getter; +import lombok.Setter; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public class NewExtensionGrant { +@Getter +@Setter +public class NewExtensionGrant implements PluginConfigurationPayload { @NotNull private String type; @@ -32,7 +35,6 @@ public class NewExtensionGrant { private String name; @NotNull - @JsonString private String configuration; @NotNull @@ -45,62 +47,6 @@ public class NewExtensionGrant { private boolean userExists; - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - - public String getGrantType() { - return grantType; - } - - public void setGrantType(String grantType) { - this.grantType = grantType; - } - - public String getIdentityProvider() { - return identityProvider; - } - - public void setIdentityProvider(String identityProvider) { - this.identityProvider = identityProvider; - } - - public boolean isCreateUser() { - return createUser; - } - - public void setCreateUser(boolean createUser) { - this.createUser = createUser; - } - - public boolean isUserExists() { - return userExists; - } - - public void setUserExists(boolean userExists) { - this.userExists = userExists; - } - @Override public String toString() { return "NewExtensionGrant{" + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewFactor.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewFactor.java index 5a7179c13f9..7b70c38b8fd 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewFactor.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewFactor.java @@ -15,14 +15,17 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public class NewFactor { +@Getter +@Setter +public class NewFactor implements PluginConfigurationPayload{ private String id; @@ -36,48 +39,8 @@ public class NewFactor { private String name; @NotNull - @JsonString private String configuration; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getFactorType() { - return factorType; - } - - public void setFactorType(String factorType) { - this.factorType = factorType; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } @Override public String toString() { diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewIdentityProvider.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewIdentityProvider.java index f0fe3478097..2b18c0f6b75 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewIdentityProvider.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewIdentityProvider.java @@ -15,8 +15,9 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; import java.util.List; @@ -24,7 +25,9 @@ * @author David BRASSELY (david.brassely at graviteesource.com) * @author GraviteeSource Team */ -public class NewIdentityProvider { +@Getter +@Setter +public class NewIdentityProvider implements PluginConfigurationPayload { private String id; @@ -35,61 +38,12 @@ public class NewIdentityProvider { private String name; @NotNull - @JsonString private String configuration; private List domainWhitelist; private boolean external; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - - public boolean isExternal() { - return external; - } - - public void setExternal(boolean external) { - this.external = external; - } - - public List getDomainWhitelist() { - return domainWhitelist; - } - - public void setDomainWhitelist(List domainWhitelist) { - this.domainWhitelist = domainWhitelist; - } - @Override public String toString() { return "NewIdentityProvider{" + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewReporter.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewReporter.java index 4d78a6ef83d..0b37fa0bfcc 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewReporter.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewReporter.java @@ -15,7 +15,6 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -24,7 +23,7 @@ * @author GraviteeSource Team */ @Data -public class NewReporter { +public class NewReporter implements PluginConfigurationPayload { private String id; @@ -37,7 +36,6 @@ public class NewReporter { private String name; @NotNull - @JsonString(message = "configuration must be json form") private String configuration; private boolean inherited; diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewServiceResource.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewServiceResource.java index 0510748ade3..7fc9584e822 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewServiceResource.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/NewServiceResource.java @@ -15,14 +15,17 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class NewServiceResource { +@Getter +@Setter +public class NewServiceResource implements PluginConfigurationPayload { private String id; @@ -33,41 +36,8 @@ public class NewServiceResource { private String type; @NotNull - @JsonString private String configuration; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "NewServiceResource{" + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateAuthenticationDeviceNotifier.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateAuthenticationDeviceNotifier.java index 5875b8aea8a..2d21f3661b9 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateAuthenticationDeviceNotifier.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateAuthenticationDeviceNotifier.java @@ -15,42 +15,33 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateAuthenticationDeviceNotifier { +@Getter +@Setter +public class UpdateAuthenticationDeviceNotifier implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "UpdateAuthenticationDeviceNotifier{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateBotDetection.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateBotDetection.java index 36ee1e7f402..0edca699a6a 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateBotDetection.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateBotDetection.java @@ -15,42 +15,33 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateBotDetection { +@Getter +@Setter +public class UpdateBotDetection implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "UpdateBotDetection{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateCertificate.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateCertificate.java index 40ed6ca186c..9de884a12b9 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateCertificate.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateCertificate.java @@ -15,14 +15,17 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ +@Getter +@Setter public class UpdateCertificate implements PluginConfigurationPayload { @NotBlank @@ -32,38 +35,13 @@ public class UpdateCertificate implements PluginConfigurationPayload { private String type; @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - - @Override - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - @Override public String toString() { return "UpdateCertificate{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateDeviceIdentifier.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateDeviceIdentifier.java index f5110f86689..c7fce605aef 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateDeviceIdentifier.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateDeviceIdentifier.java @@ -15,42 +15,33 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Rémi SULTAN (remi.sultan at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateDeviceIdentifier { +@Getter +@Setter +public class UpdateDeviceIdentifier implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "UpdateDeviceIdentifier{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateExtensionGrant.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateExtensionGrant.java index a6cbff96e4a..3d2a2d5e90c 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateExtensionGrant.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateExtensionGrant.java @@ -15,21 +15,27 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; +import lombok.Getter; +import lombok.Setter; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateExtensionGrant { +@Getter +@Setter +public class UpdateExtensionGrant implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; @Pattern(regexp = "[A-Za-z][A-Za-z0-9+\\-.]*:(?://(?:(?:[A-Za-z0-9\\-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}|::(?:[0-9A-Fa-f]{1,4}:){5}|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}|(?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}|(?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:|(?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::)(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)|[Vv][0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)(?::[0-9]*)?(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*|/(?:(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)?|(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*|)(?:\\?(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*)?") @@ -41,58 +47,11 @@ public class UpdateExtensionGrant { private boolean userExists; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - - public String getGrantType() { - return grantType; - } - - public void setGrantType(String grantType) { - this.grantType = grantType; - } - - public String getIdentityProvider() { - return identityProvider; - } - - public void setIdentityProvider(String identityProvider) { - this.identityProvider = identityProvider; - } - - public boolean isCreateUser() { - return createUser; - } - - public void setCreateUser(boolean createUser) { - this.createUser = createUser; - } - - public boolean isUserExists() { - return userExists; - } - - public void setUserExists(boolean userExists) { - this.userExists = userExists; - } - @Override public String toString() { return "UpdateExtensionGrant{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + ", grantType='" + grantType + '\'' + ", identityProvider='" + identityProvider + '\'' + ", createUser='" + createUser + '\'' + diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateFactor.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateFactor.java index 6ec0abe0692..0ebdc928325 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateFactor.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateFactor.java @@ -15,42 +15,34 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateFactor { + +@Getter +@Setter +public class UpdateFactor implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "UpdateFactor{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateIdentityProvider.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateIdentityProvider.java index 65d9787828d..a499cdd7232 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateIdentityProvider.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateIdentityProvider.java @@ -15,7 +15,7 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -29,13 +29,15 @@ */ @Getter @Setter -public class UpdateIdentityProvider { +public class UpdateIdentityProvider implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; private Map mappers; @@ -51,7 +53,8 @@ public class UpdateIdentityProvider { @Override public String toString() { return "UpdateIdentityProvider{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateReporter.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateReporter.java index a0515b4a2e4..5fbc2f69d33 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateReporter.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateReporter.java @@ -15,7 +15,7 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -24,15 +24,17 @@ * @author GraviteeSource Team */ @Data -public class UpdateReporter { +public class UpdateReporter implements PluginConfigurationPayload { private boolean enabled; @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; private boolean inherited; @@ -41,7 +43,8 @@ public class UpdateReporter { @Override public String toString() { return "UpdateReporter{" + - ", name='" + name + '\'' + + "name='" + name + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateServiceResource.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateServiceResource.java index 2638e1a096b..7d9cad36d3f 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateServiceResource.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/model/UpdateServiceResource.java @@ -15,43 +15,35 @@ */ package io.gravitee.am.service.model; -import io.gravitee.am.service.validators.jsonstring.JsonString; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** * @author Eric LELEU (eric.leleu at graviteesource.com) * @author GraviteeSource Team */ -public class UpdateServiceResource { + +@Getter +@Setter +public class UpdateServiceResource implements PluginConfigurationPayload { @NotNull private String name; + @NotBlank + private String type; + @NotNull - @JsonString private String configuration; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConfiguration() { - return configuration; - } - - public void setConfiguration(String configuration) { - this.configuration = configuration; - } - @Override public String toString() { return "UpdateServiceResource{" + "name='" + name + '\'' + ", configuration='" + configuration + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonString.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonString.java deleted file mode 100644 index c8a06ef2896..00000000000 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonString.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2015 The Gravitee team (http://gravitee.io) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ -package io.gravitee.am.service.validators.jsonstring; - -import jakarta.validation.Constraint; -import jakarta.validation.Payload; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Constraint(validatedBy = JsonStringValidator.class) -public @interface JsonString { - - String message() default "Malformed json"; - - Class[] groups() default {}; - - Class[] payload() default {}; -} diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidator.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidator.java deleted file mode 100644 index 459f345ecea..00000000000 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidator.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2015 The Gravitee team (http://gravitee.io) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ -package io.gravitee.am.service.validators.jsonstring; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class JsonStringValidator implements ConstraintValidator { - private final ObjectMapper objectMapper; - - - @Override - public boolean isValid(String json, ConstraintValidatorContext constraintValidatorContext) { - try { - objectMapper.readTree(json); - return true; - } catch (JsonProcessingException e) { - return false; - } - } -} diff --git a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidator.java b/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidator.java index 20b6a9bd7b3..de2c7454b00 100644 --- a/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidator.java +++ b/gravitee-am-service/src/main/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidator.java @@ -15,27 +15,22 @@ */ package io.gravitee.am.service.validators.plugincfg; -import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidator; import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidator.Result; import io.gravitee.am.plugins.handlers.api.core.PluginConfigurationValidatorsRegistry; import io.gravitee.am.service.model.PluginConfigurationPayload; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.util.List; -import java.util.Optional; - @Component +@RequiredArgsConstructor public class PluginJsonFormValidator implements ConstraintValidator { - private final List pluginValidatorsRegistry; - public PluginJsonFormValidator(List pluginValidatorsRegistry) { - this.pluginValidatorsRegistry = pluginValidatorsRegistry; - } + private final PluginConfigurationValidatorsRegistry pluginValidatorsRegistry; @Override public boolean isValid(PluginConfigurationPayload newPluginInstance, ConstraintValidatorContext ctx) { - return validator(newPluginInstance.getType()) + return pluginValidatorsRegistry.get(newPluginInstance.getType()) .map(validator -> validator.validate(newPluginInstance.getConfiguration())) .map(result -> processResult(result, ctx)) .orElse(Boolean.TRUE); @@ -51,10 +46,4 @@ private boolean processResult(Result result, ConstraintValidatorContext ctx){ } } - private Optional validator(String id){ - return pluginValidatorsRegistry.stream() - .filter(reg -> reg.contains(id)) - .findFirst() - .map(reg -> reg.get(id)); - } } diff --git a/gravitee-am-service/src/test/java/io/gravitee/am/service/CertificateServiceTest.java b/gravitee-am-service/src/test/java/io/gravitee/am/service/CertificateServiceTest.java index 4e08394427c..46a195c7776 100644 --- a/gravitee-am-service/src/test/java/io/gravitee/am/service/CertificateServiceTest.java +++ b/gravitee-am-service/src/test/java/io/gravitee/am/service/CertificateServiceTest.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import io.gravitee.am.certificate.api.CertificateProvider; +import io.gravitee.am.common.plugin.ValidationResult; import io.gravitee.am.identityprovider.api.User; import io.gravitee.am.model.Application; import io.gravitee.am.model.Certificate; @@ -42,9 +42,6 @@ import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.observers.TestObserver; import io.reactivex.rxjava3.subscribers.TestSubscriber; - -import static java.time.temporal.ChronoUnit.DAYS; - import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -61,18 +58,14 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.security.cert.CertificateException; -import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Base64; import java.util.Date; -import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static io.gravitee.am.service.impl.CertificateServiceImpl.DEFAULT_CERTIFICATE_PLUGIN; -import static java.time.temporal.ChronoUnit.HOURS; import static org.mockito.Mockito.any; import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.doReturn; @@ -289,9 +282,7 @@ public void shouldCreateAwsCertificate() { var newCertificate = new NewCertificate(); newCertificate.setType(type); newCertificate.setConfiguration(certificateNode.toString()); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().plus(30, DAYS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.valid()); when(certificateRepository.create(any())).thenReturn(Single.just(new Certificate())); when(eventService.create(any())).thenReturn(Single.just(new Event())); @@ -300,7 +291,7 @@ public void shouldCreateAwsCertificate() { .awaitDone(10, TimeUnit.SECONDS) .assertComplete(); - verify(certificatePluginManager, times(1)).create(any()); + verify(certificatePluginManager, times(1)).validate(any()); verify(certificateRepository, times(1)).create(any()); verify(eventService, times(1)).create(any()); } @@ -314,9 +305,7 @@ public void shouldUpdateAwsCertificate() { certificateNode.put("secretname", "aws-secret-name"); var newCertificate = new UpdateCertificate(); newCertificate.setConfiguration(certificateNode.toString()); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().plus(30, DAYS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.valid()); var certificate = new Certificate(); certificate.setType(type); when(certificateRepository.findById(any())).thenReturn(Maybe.just(certificate)); @@ -328,7 +317,7 @@ public void shouldUpdateAwsCertificate() { .awaitDone(10, TimeUnit.SECONDS) .assertComplete(); - verify(certificatePluginManager, times(1)).create(any()); + verify(certificatePluginManager, times(1)).validate(any()); verify(certificateRepository, times(1)).update(any()); verify(eventService, times(1)).create(any()); } @@ -349,9 +338,7 @@ public void shouldNotCreateWhenCertificateIsExpired() throws JsonProcessingExcep newCertificate.setName("expired-certificate"); newCertificate.setType(DEFAULT_CERTIFICATE_PLUGIN); newCertificate.setConfiguration(certificateNode.toString()); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().minus(1, HOURS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.invalid("The certificate you uploaded has already expired. Please select a different certificate to upload.")); TestObserver testObserver = certificateService.create(DOMAIN_NAME, newCertificate, Mockito.mock(User.class)).test(); testObserver.awaitDone(10, TimeUnit.SECONDS); @@ -374,7 +361,8 @@ public void shouldNotCreateWhenIncorrectCertificatePassword() throws JsonProcess newCertificate.setName("certificate"); newCertificate.setType(DEFAULT_CERTIFICATE_PLUGIN); newCertificate.setConfiguration(certificateNode.toString()); - when(certificatePluginManager.create(any())).thenReturn(null); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.invalid("The configuration details entered are incorrect. Please check those and try again.")); + TestObserver testObserver = certificateService.create(DOMAIN_NAME, newCertificate, Mockito.mock(User.class)).test(); testObserver.awaitDone(10, TimeUnit.SECONDS); @@ -405,9 +393,7 @@ private TestObserver defaultCertificate(int keySize, String algorit doReturn(mock(ObjectNode.class)).when(objectMapper).createObjectNode(); when(certificatePluginService.getSchema(CertificateServiceImpl.DEFAULT_CERTIFICATE_PLUGIN)) .thenReturn(Maybe.just(certificateSchemaDefinition)); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().plus(1, HOURS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.valid()); TestObserver testObserver = certificateService.create(DOMAIN_NAME).test(); testObserver.awaitDone(10, TimeUnit.SECONDS); @@ -484,9 +470,7 @@ public void shouldRotate_defaultCertificate_Rsa() { when(certificatePluginService.getSchema(DEFAULT_CERTIFICATE_PLUGIN)) .thenReturn(Maybe.just(certificateSchemaDefinition)); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().plus(1, HOURS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.valid()); TestObserver testObserver = certificateService.rotate(DOMAIN, mock(User.class)).test(); testObserver.awaitDone(10, TimeUnit.SECONDS); @@ -537,9 +521,8 @@ public void shouldRotate_defaultCertificate_Rsa_firstDefault() { when(certificatePluginService.getSchema(DEFAULT_CERTIFICATE_PLUGIN)) .thenReturn(Maybe.just(certificateSchemaDefinition)); - var certificateProvider = mock(CertificateProvider.class); - when(certificateProvider.getExpirationDate()).thenReturn(Optional.of(new Date(Instant.now().plus(1, HOURS).toEpochMilli()))); - when(certificatePluginManager.create(any())).thenReturn(certificateProvider); + when(certificatePluginManager.validate(any())).thenReturn(ValidationResult.valid()); + TestObserver testObserver = certificateService.rotate(DOMAIN, mock(User.class)).test(); testObserver.awaitDone(10, TimeUnit.SECONDS); diff --git a/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidatorTest.java b/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidatorTest.java deleted file mode 100644 index 4a094f9f1ff..00000000000 --- a/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/jsonstring/JsonStringValidatorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2015 The Gravitee team (http://gravitee.io) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ -package io.gravitee.am.service.validators.jsonstring; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -import org.mockito.Mockito; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class JsonStringValidatorTest { - - @Test - public void validatorTest() { - JsonStringValidator validator = new JsonStringValidator(new ObjectMapper()); - assertFalse(validator.isValid("{{}", Mockito.mock())); - assertFalse(validator.isValid("{\"a:}", Mockito.mock())); - assertFalse(validator.isValid("{\"xx\":}", Mockito.mock())); - - assertTrue(validator.isValid("", Mockito.mock())); - assertTrue(validator.isValid("{\"aa\":\"xxx\"}", Mockito.mock())); - assertTrue(validator.isValid("{\"aa\":[]}", Mockito.mock())); - assertTrue(validator.isValid("{\"aa\":[1,2,3]}", Mockito.mock())); - } - - -} \ No newline at end of file diff --git a/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidatorTest.java b/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidatorTest.java index 012370b0199..23f9a49c94b 100644 --- a/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidatorTest.java +++ b/gravitee-am-service/src/test/java/io/gravitee/am/service/validators/plugincfg/PluginJsonFormValidatorTest.java @@ -24,7 +24,6 @@ import jakarta.validation.ConstraintValidatorContext.ConstraintViolationBuilder; import lombok.SneakyThrows; import lombok.Value; -import org.junit.BeforeClass; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,9 +32,7 @@ import org.mockito.internal.util.io.IOUtil; import org.mockito.junit.MockitoJUnitRunner; -import java.io.IOException; import java.io.InputStream; -import java.util.List; import java.util.stream.Collectors; import static org.mockito.ArgumentMatchers.anyString; @@ -55,7 +52,7 @@ class PluginJsonFormValidatorTest { @BeforeEach public void setUp() { registry = new PluginConfigurationValidatorsRegistry(); - jsonFormValidator = new PluginJsonFormValidator(List.of(registry)); + jsonFormValidator = new PluginJsonFormValidator(registry); } @Test diff --git a/gravitee-am-test/api/management/models/UpdateAuthenticationDeviceNotifier.ts b/gravitee-am-test/api/management/models/UpdateAuthenticationDeviceNotifier.ts index cc49dec65d9..a89d005d38e 100644 --- a/gravitee-am-test/api/management/models/UpdateAuthenticationDeviceNotifier.ts +++ b/gravitee-am-test/api/management/models/UpdateAuthenticationDeviceNotifier.ts @@ -24,8 +24,8 @@ */ /* tslint:disable */ + /* eslint-disable */ -import { exists, mapValues } from '../runtime'; /** * * @export @@ -38,6 +38,12 @@ export interface UpdateAuthenticationDeviceNotifier { * @memberof UpdateAuthenticationDeviceNotifier */ name: string; + /** + * + * @type {string} + * @memberof UpdateAuthenticationDeviceNotifier + */ + type: string; /** * * @type {string} @@ -57,6 +63,7 @@ export function UpdateAuthenticationDeviceNotifierFromJSONTyped(json: any, ignor return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], }; } @@ -71,6 +78,7 @@ export function UpdateAuthenticationDeviceNotifierToJSON(value?: UpdateAuthentic return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, }; } diff --git a/gravitee-am-test/api/management/models/UpdateBotDetection.ts b/gravitee-am-test/api/management/models/UpdateBotDetection.ts index 2e299d58106..d5592c518dd 100644 --- a/gravitee-am-test/api/management/models/UpdateBotDetection.ts +++ b/gravitee-am-test/api/management/models/UpdateBotDetection.ts @@ -24,8 +24,8 @@ */ /* tslint:disable */ + /* eslint-disable */ -import { exists, mapValues } from '../runtime'; /** * * @export @@ -38,6 +38,12 @@ export interface UpdateBotDetection { * @memberof UpdateBotDetection */ name: string; + /** + * + * @type {string} + * @memberof UpdateBotDetection + */ + type: string; /** * * @type {string} @@ -57,6 +63,7 @@ export function UpdateBotDetectionFromJSONTyped(json: any, ignoreDiscriminator: return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], }; } @@ -71,6 +78,7 @@ export function UpdateBotDetectionToJSON(value?: UpdateBotDetection | null): any return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, }; } diff --git a/gravitee-am-test/api/management/models/UpdateDeviceIdentifier.ts b/gravitee-am-test/api/management/models/UpdateDeviceIdentifier.ts index 6ea223a4f05..3708bd3c352 100644 --- a/gravitee-am-test/api/management/models/UpdateDeviceIdentifier.ts +++ b/gravitee-am-test/api/management/models/UpdateDeviceIdentifier.ts @@ -24,8 +24,8 @@ */ /* tslint:disable */ + /* eslint-disable */ -import { exists, mapValues } from '../runtime'; /** * * @export @@ -38,6 +38,12 @@ export interface UpdateDeviceIdentifier { * @memberof UpdateDeviceIdentifier */ name: string; + /** + * + * @type {string} + * @memberof UpdateDeviceIdentifier + */ + type: string; /** * * @type {string} @@ -57,6 +63,7 @@ export function UpdateDeviceIdentifierFromJSONTyped(json: any, ignoreDiscriminat return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], }; } @@ -71,6 +78,7 @@ export function UpdateDeviceIdentifierToJSON(value?: UpdateDeviceIdentifier | nu return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, }; } diff --git a/gravitee-am-test/api/management/models/UpdateExtensionGrant.ts b/gravitee-am-test/api/management/models/UpdateExtensionGrant.ts index 94c906153c0..b25482eb190 100644 --- a/gravitee-am-test/api/management/models/UpdateExtensionGrant.ts +++ b/gravitee-am-test/api/management/models/UpdateExtensionGrant.ts @@ -25,7 +25,8 @@ /* tslint:disable */ /* eslint-disable */ -import { exists, mapValues } from '../runtime'; +import { exists } from '../runtime'; + /** * * @export @@ -38,6 +39,12 @@ export interface UpdateExtensionGrant { * @memberof UpdateExtensionGrant */ name: string; + /** + * + * @type {string} + * @memberof UpdateExtensionGrant + */ + type: string; /** * * @type {string} @@ -81,6 +88,7 @@ export function UpdateExtensionGrantFromJSONTyped(json: any, ignoreDiscriminator return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], 'grantType': !exists(json, 'grantType') ? undefined : json['grantType'], 'identityProvider': !exists(json, 'identityProvider') ? undefined : json['identityProvider'], @@ -99,6 +107,7 @@ export function UpdateExtensionGrantToJSON(value?: UpdateExtensionGrant | null): return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, 'grantType': value.grantType, 'identityProvider': value.identityProvider, diff --git a/gravitee-am-test/api/management/models/UpdateFactor.ts b/gravitee-am-test/api/management/models/UpdateFactor.ts index d0238fcfd8d..d9110077bb5 100644 --- a/gravitee-am-test/api/management/models/UpdateFactor.ts +++ b/gravitee-am-test/api/management/models/UpdateFactor.ts @@ -24,8 +24,8 @@ */ /* tslint:disable */ + /* eslint-disable */ -import { exists, mapValues } from '../runtime'; /** * * @export @@ -38,6 +38,12 @@ export interface UpdateFactor { * @memberof UpdateFactor */ name: string; + /** + * + * @type {string} + * @memberof UpdateFactor + */ + type: string; /** * * @type {string} @@ -57,6 +63,7 @@ export function UpdateFactorFromJSONTyped(json: any, ignoreDiscriminator: boolea return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], }; } @@ -71,6 +78,7 @@ export function UpdateFactorToJSON(value?: UpdateFactor | null): any { return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, }; } diff --git a/gravitee-am-test/api/management/models/UpdateIdentityProvider.ts b/gravitee-am-test/api/management/models/UpdateIdentityProvider.ts index 540143e4657..324c4cfa5b0 100644 --- a/gravitee-am-test/api/management/models/UpdateIdentityProvider.ts +++ b/gravitee-am-test/api/management/models/UpdateIdentityProvider.ts @@ -25,7 +25,8 @@ /* tslint:disable */ /* eslint-disable */ -import { exists, mapValues } from '../runtime'; +import { exists } from '../runtime'; + /** * * @export @@ -38,6 +39,12 @@ export interface UpdateIdentityProvider { * @memberof UpdateIdentityProvider */ name: string; + /** + * + * @type {string} + * @memberof UpdateIdentityProvider + */ + type: string; /** * * @type {string} @@ -87,6 +94,7 @@ export function UpdateIdentityProviderFromJSONTyped(json: any, ignoreDiscriminat return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], 'mappers': !exists(json, 'mappers') ? undefined : json['mappers'], 'roleMapper': !exists(json, 'roleMapper') ? undefined : json['roleMapper'], @@ -106,6 +114,7 @@ export function UpdateIdentityProviderToJSON(value?: UpdateIdentityProvider | nu return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, 'mappers': value.mappers, 'roleMapper': value.roleMapper, diff --git a/gravitee-am-test/api/management/models/UpdateReporter.ts b/gravitee-am-test/api/management/models/UpdateReporter.ts index 778921ea035..f4d1db213e4 100644 --- a/gravitee-am-test/api/management/models/UpdateReporter.ts +++ b/gravitee-am-test/api/management/models/UpdateReporter.ts @@ -25,7 +25,8 @@ /* tslint:disable */ /* eslint-disable */ -import { exists, mapValues } from '../runtime'; +import { exists } from '../runtime'; + /** * * @export @@ -44,6 +45,12 @@ export interface UpdateReporter { * @memberof UpdateReporter */ name: string; + /** + * + * @type {string} + * @memberof UpdateReporter + */ + type: string; /** * * @type {string} @@ -70,6 +77,7 @@ export function UpdateReporterFromJSONTyped(json: any, ignoreDiscriminator: bool 'enabled': !exists(json, 'enabled') ? undefined : json['enabled'], 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], 'inherited': !exists(json, 'inherited') ? undefined : json['inherited'], }; @@ -86,6 +94,7 @@ export function UpdateReporterToJSON(value?: UpdateReporter | null): any { 'enabled': value.enabled, 'name': value.name, + 'type': value.type, 'configuration': value.configuration, 'inherited': value.inherited, }; diff --git a/gravitee-am-test/api/management/models/UpdateServiceResource.ts b/gravitee-am-test/api/management/models/UpdateServiceResource.ts index df4a884b084..27b77b62557 100644 --- a/gravitee-am-test/api/management/models/UpdateServiceResource.ts +++ b/gravitee-am-test/api/management/models/UpdateServiceResource.ts @@ -24,8 +24,8 @@ */ /* tslint:disable */ + /* eslint-disable */ -import { exists, mapValues } from '../runtime'; /** * * @export @@ -38,6 +38,12 @@ export interface UpdateServiceResource { * @memberof UpdateServiceResource */ name: string; + /** + * + * @type {string} + * @memberof UpdateServiceResource + */ + type: string; /** * * @type {string} @@ -57,6 +63,7 @@ export function UpdateServiceResourceFromJSONTyped(json: any, ignoreDiscriminato return { 'name': json['name'], + 'type': json['type'], 'configuration': json['configuration'], }; } @@ -71,6 +78,7 @@ export function UpdateServiceResourceToJSON(value?: UpdateServiceResource | null return { 'name': value.name, + 'type': value.type, 'configuration': value.configuration, }; } diff --git a/gravitee-am-test/specs/gateway/oidc-idp/common.ts b/gravitee-am-test/specs/gateway/oidc-idp/common.ts index 5f28329a557..18ad5e030d9 100644 --- a/gravitee-am-test/specs/gateway/oidc-idp/common.ts +++ b/gravitee-am-test/specs/gateway/oidc-idp/common.ts @@ -30,7 +30,7 @@ import { Application } from '@management-models/Application'; import { initiateLoginFlow, login, postConsent } from '@gateway-commands/login-commands'; import { patchApplication } from '@management-commands/application-management-commands'; import { BasicResponse, followRedirect, followRedirectTag } from '@utils-commands/misc'; -import {performFormPost, performGet, performPost } from '@gateway-commands/oauth-oidc-commands'; +import { performFormPost, performGet } from '@gateway-commands/oauth-oidc-commands'; import cheerio from 'cheerio'; import { requestAdminAccessToken } from '@management-commands/token-management-commands'; import faker from 'faker'; @@ -200,12 +200,11 @@ export async function setupOidcProviderTest(domainSuffix: string): Promise { if (flow == 'code') { - return followRedirectTag('login-code')(response) - .then(followRedirect); + return followRedirectTag('login-code')(response).then(followRedirect); } else { return followRedirectTag('login-implicit-1')(response) - .then(submitFragmentForm) - .then(followRedirectTag('login-implicit-2')); + .then(submitFragmentForm) + .then(followRedirectTag('login-implicit-2')); } }) ); @@ -242,7 +241,7 @@ export async function setupOidcProviderTest(domainSuffix: string): Promise { - console.log(`Cleaning up domains: ${clientDomain.hrid}, ${providerDomain.hrid}`) + console.log(`Cleaning up domains: ${clientDomain.hrid}, ${providerDomain.hrid}`); return Promise.all([deleteDomain(clientDomain.id, accessToken), deleteDomain(providerDomain.id, accessToken)]).then((ok) => console.log('Cleanup complete'), ); @@ -253,6 +252,7 @@ export async function setupOidcProviderTest(domainSuffix: string): Promise fixture.expectRedirectToClient(res, (uri: string) => expect(uri).toMatch(/\?code=[^&]*/)); + return (res) => fixture.expectRedirectToClient(res, (uri: string) => expect(uri).toMatch(/\?code=[^&]*/)); } describe('The OIDC provider', () => { @@ -48,14 +49,14 @@ describe('The OIDC provider', () => { .then((code) => expect(code).not.toBeNull()); }); it('should login with S256 challenge', async () => { - await fixture.idpPluginInClient.setPkceMethod('s256'); + await fixture.idpPluginInClient.setPkceMethod('S256'); await fixture .login(TEST_USER.username, TEST_USER.password, { oidcSignInUrlAssertions: expectCodeChallenge('S256') }) .then(expectRedirectToClientWithAuthCode) .then((code) => expect(code).not.toBeNull()); }); it('should fail with challenge unsupported by provider', async () => { - await fixture.idpPluginInClient.setPkceMethod('non-existing-method'); + await fixture.idpPluginInClient.setPkceMethod('non-existing-method').catch((e) => expect(e.response.status).toBe(400)); }); }); diff --git a/gravitee-am-test/specs/management/extension-grant.jest.spec.ts b/gravitee-am-test/specs/management/extension-grant.jest.spec.ts index f6ee8528f87..5a2c5e6f34c 100644 --- a/gravitee-am-test/specs/management/extension-grant.jest.spec.ts +++ b/gravitee-am-test/specs/management/extension-grant.jest.spec.ts @@ -14,10 +14,9 @@ * limitations under the License. */ import fetch from 'cross-fetch'; -import * as faker from 'faker'; import { afterAll, beforeAll, expect, jest } from '@jest/globals'; import { requestAdminAccessToken } from '@management-commands/token-management-commands'; -import { createDomain, deleteDomain,setupDomainForTest, startDomain } from '@management-commands/domain-management-commands'; +import { deleteDomain, setupDomainForTest } from '@management-commands/domain-management-commands'; import { createExtensionGrant, deleteExtensionGrant, @@ -26,10 +25,10 @@ import { updateExtensionGrant, } from '@management-commands/extension-grant-commands'; import { createApplication, patchApplication } from '@management-commands/application-management-commands'; -import { getWellKnownOpenIdConfiguration, performPost } from '@gateway-commands/oauth-oidc-commands'; +import { performPost } from '@gateway-commands/oauth-oidc-commands'; import { applicationBase64Token } from '@gateway-commands/utils'; import { buildCreateAndTestUser, deleteUser, getAllUsers } from '@management-commands/user-management-commands'; -import { delay,uniqueName } from '@utils-commands/misc'; +import { delay, uniqueName } from '@utils-commands/misc'; import { getAllIdps } from '@management-commands/idp-management-commands'; import { generateSignedJwt, getPublicKey } from '@utils-commands/jwt'; @@ -47,10 +46,10 @@ let user: any; jest.setTimeout(200000); beforeAll(async () => { - accessToken = await requestAdminAccessToken() - const startedDomain = await setupDomainForTest(uniqueName("domain-extension-grant"), {accessToken, waitForStart: true}) - domain = startedDomain.domain - tokenEndpoint = startedDomain.oidcConfig.token_endpoint + accessToken = await requestAdminAccessToken(); + const startedDomain = await setupDomainForTest(uniqueName('domain-extension-grant'), { accessToken, waitForStart: true }); + domain = startedDomain.domain; + tokenEndpoint = startedDomain.oidcConfig.token_endpoint; const appBody = { name: 'app', diff --git a/gravitee-am-test/specs/management/identity-provider.jest.spec.ts b/gravitee-am-test/specs/management/identity-provider.jest.spec.ts index 360a6043893..d0eb32e03fb 100644 --- a/gravitee-am-test/specs/management/identity-provider.jest.spec.ts +++ b/gravitee-am-test/specs/management/identity-provider.jest.spec.ts @@ -17,9 +17,9 @@ import fetch from 'cross-fetch'; import * as faker from 'faker'; import { afterAll, beforeAll, expect } from '@jest/globals'; import { requestAdminAccessToken } from '@management-commands/token-management-commands'; -import { createDomain, deleteDomain,setupDomainForTest, startDomain } from '@management-commands/domain-management-commands'; +import { deleteDomain, setupDomainForTest } from '@management-commands/domain-management-commands'; import { createIdp, deleteIdp, getAllIdps, getIdp, updateIdp } from '@management-commands/idp-management-commands'; -import {uniqueName} from '@utils-commands/misc'; +import { uniqueName } from '@utils-commands/misc'; global.fetch = fetch; @@ -28,8 +28,8 @@ let domain; let idp; beforeAll(async () => { - accessToken = await requestAdminAccessToken() - domain = await setupDomainForTest(uniqueName('domain-idp'), {accessToken}).then(it=>it.domain) + accessToken = await requestAdminAccessToken(); + domain = await setupDomainForTest(uniqueName('domain-idp'), { accessToken }).then((it) => it.domain); }); function buildIdp(i: number) { @@ -95,6 +95,7 @@ describe('after creating identity providers', () => { accessToken, { name: faker.commerce.productName(), + type: idp.type, configuration: idp.configuration, }, idp.id, diff --git a/gravitee-am-ui/src/app/services/bot-detection.service.ts b/gravitee-am-ui/src/app/services/bot-detection.service.ts index 9e8c20360ef..8b215cacb51 100644 --- a/gravitee-am-ui/src/app/services/bot-detection.service.ts +++ b/gravitee-am-ui/src/app/services/bot-detection.service.ts @@ -33,14 +33,15 @@ export class BotDetectionService { return this.http.get(this.botDetectionsURL + domainId + '/bot-detections/' + id); } - create(domainId, factor): Observable { - return this.http.post(this.botDetectionsURL + domainId + '/bot-detections', factor); + create(domainId, botDetection): Observable { + return this.http.post(this.botDetectionsURL + domainId + '/bot-detections', botDetection); } - update(domainId, id, dection): Observable { + update(domainId, id, botDetection): Observable { return this.http.put(this.botDetectionsURL + domainId + '/bot-detections/' + id, { - name: dection.name, - configuration: dection.configuration, + name: botDetection.name, + type: botDetection.type, + configuration: botDetection.configuration, }); } diff --git a/gravitee-am-ui/src/app/services/device-identifier.service.ts b/gravitee-am-ui/src/app/services/device-identifier.service.ts index cf594d1c075..02e8230477b 100644 --- a/gravitee-am-ui/src/app/services/device-identifier.service.ts +++ b/gravitee-am-ui/src/app/services/device-identifier.service.ts @@ -40,6 +40,7 @@ export class DeviceIdentifierService { update(domainId, id, deviceIdentifier): Observable { return this.http.put(this.deviceIdentifierUrl + domainId + '/device-identifiers/' + id, { name: deviceIdentifier.name, + type: deviceIdentifier.type, configuration: deviceIdentifier.configuration, }); } diff --git a/gravitee-am-ui/src/app/services/device-notifiers.service.ts b/gravitee-am-ui/src/app/services/device-notifiers.service.ts index bcf40fecfbd..b2b279d39b9 100644 --- a/gravitee-am-ui/src/app/services/device-notifiers.service.ts +++ b/gravitee-am-ui/src/app/services/device-notifiers.service.ts @@ -40,6 +40,7 @@ export class DeviceNotifiersService { update(domainId, id, deviceNotifier): Observable { return this.http.put(this.notfiersURL + domainId + '/auth-device-notifiers/' + id, { name: deviceNotifier.name, + type: deviceNotifier.type, configuration: deviceNotifier.configuration, }); } diff --git a/gravitee-am-ui/src/app/services/extension-grant.service.ts b/gravitee-am-ui/src/app/services/extension-grant.service.ts index 4ecb3d77e77..bef84eb6058 100644 --- a/gravitee-am-ui/src/app/services/extension-grant.service.ts +++ b/gravitee-am-ui/src/app/services/extension-grant.service.ts @@ -40,6 +40,7 @@ export class ExtensionGrantService { update(domainId, id, tokenGranter): Observable { return this.http.put(this.extensionGrantsUrl + domainId + '/extensionGrants/' + id, { name: tokenGranter.name, + type: tokenGranter.type, configuration: tokenGranter.configuration, grantType: tokenGranter.grantType, identityProvider: tokenGranter.identityProvider, diff --git a/gravitee-am-ui/src/app/services/factor.service.ts b/gravitee-am-ui/src/app/services/factor.service.ts index 71c9798002a..22ab57d0800 100644 --- a/gravitee-am-ui/src/app/services/factor.service.ts +++ b/gravitee-am-ui/src/app/services/factor.service.ts @@ -40,6 +40,7 @@ export class FactorService { update(domainId, id, factor): Observable { return this.http.put(this.factorsURL + domainId + '/factors/' + id, { name: factor.name, + type: factor.type, configuration: factor.configuration, }); } diff --git a/gravitee-am-ui/src/app/services/provider.service.ts b/gravitee-am-ui/src/app/services/provider.service.ts index e0d7692666d..5f6cb6b1175 100644 --- a/gravitee-am-ui/src/app/services/provider.service.ts +++ b/gravitee-am-ui/src/app/services/provider.service.ts @@ -58,6 +58,7 @@ export class ProviderService { } return this.http.put(this.providersURL + domainId + '/identities/' + id, { name: provider.name, + type: provider.type, configuration: provider.configuration, domainWhitelist: provider.domainWhitelist, mappers: provider.mappers, diff --git a/gravitee-am-ui/src/app/services/reporter.service.ts b/gravitee-am-ui/src/app/services/reporter.service.ts index ebb191515cc..8291bf688b7 100644 --- a/gravitee-am-ui/src/app/services/reporter.service.ts +++ b/gravitee-am-ui/src/app/services/reporter.service.ts @@ -51,6 +51,7 @@ export class ReporterService { } return this.http.put(this.reportersURL + domainId + '/reporters/' + id, { name: reporter.name, + type: reporter.type, enabled: reporter.enabled, configuration: reporter.configuration, }); diff --git a/gravitee-am-ui/src/app/services/resource.service.ts b/gravitee-am-ui/src/app/services/resource.service.ts index 3db06460bba..4e197026bbc 100644 --- a/gravitee-am-ui/src/app/services/resource.service.ts +++ b/gravitee-am-ui/src/app/services/resource.service.ts @@ -40,6 +40,7 @@ export class ResourceService { update(domainId, id, resource): Observable { return this.http.put(this.resourcesURL + domainId + '/resources/' + id, { name: resource.name, + type: resource.type, configuration: resource.configuration, }); } diff --git a/postman/collections/graviteeio-am-api-management-collection.json b/postman/collections/graviteeio-am-api-management-collection.json index 11d5c9f78a0..f522737dd0f 100644 --- a/postman/collections/graviteeio-am-api-management-collection.json +++ b/postman/collections/graviteeio-am-api-management-collection.json @@ -1125,7 +1125,7 @@ ], "body": { "mode": "raw", - "raw": "{\n\t\"external\": true,\n\t\"type\": \"oauth2-generic-am-idp\",\n \"domainWhitelist\" : [],\n\t\"configuration\": \"{\\\"clientId\\\":\\\"my-client\\\",\\\"clientSecret\\\":\\\"my-client-secret\\\",\\\"wellKnownUri\\\":\\\"{{gateway_url}}/social/oidc/.well-known/openid-configuration\\\",\\\"responseType\\\":\\\"code\\\",\\\"encodeRedirectUri\\\":false,\\\"useIdTokenForUserInfo\\\":false,\\\"signature\\\":\\\"RSA_RS256\\\",\\\"publicKeyResolver\\\":\\\"GIVEN_KEY\\\",\\\"connectTimeout\\\":10000,\\\"maxPoolSize\\\":200}\",\n\t\"name\": \"Social\"\n}", + "raw": "{\n\t\"external\": true,\n\t\"type\": \"oauth2-generic-am-idp\",\n \"domainWhitelist\" : [],\n\t\"configuration\": \"{\\\"clientId\\\":\\\"my-client\\\",\\\"clientAuthenticationMethod\\\":\\\"client_secret_post\\\",\\\"clientSecret\\\":\\\"my-client-secret\\\",\\\"wellKnownUri\\\":\\\"{{gateway_url}}/social/oidc/.well-known/openid-configuration\\\",\\\"responseType\\\":\\\"code\\\",\\\"encodeRedirectUri\\\":false,\\\"useIdTokenForUserInfo\\\":false,\\\"signature\\\":\\\"RSA_RS256\\\",\\\"publicKeyResolver\\\":\\\"GIVEN_KEY\\\",\\\"connectTimeout\\\":10000,\\\"maxPoolSize\\\":200}\",\n\t\"name\": \"Social\"\n}", "options": { "raw": { "language": "json" diff --git a/postman/collections/graviteeio-am-oauth2-collection-app-version.json b/postman/collections/graviteeio-am-oauth2-collection-app-version.json index 273d274376f..8292b358764 100644 --- a/postman/collections/graviteeio-am-oauth2-collection-app-version.json +++ b/postman/collections/graviteeio-am-oauth2-collection-app-version.json @@ -11550,7 +11550,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"name\": \"JWT BEARER\",\n \"configuration\": \"{\\\"publicKey\\\":\\\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDI6xahwspOwhzSHrga3SFif04FITcAhyygXoeS+GwUSx6HaMCMkULTQVMgQoU/7VAUf32uoiVgLDo1FI6vWvBGbp1Zbf7MRVpqK98PvhTK4PN5py2OAmpd3i3z5SgGZCP1oxJE/uF+mMUkvtQOJ+RL32pU8oaAwzPuBLKX/jA5OZPouq6Y5e7abrgValYyGCI8aZK5SfukZTMq14mDc84Y2t4IvwS/GqSUiRsTp7r6aj5F+lwD0vyUBo3eH5v5J1R+t7F8T/B2Jl+oJQTPLFxBwcN/2AGC5aqrn7BDoGUG2NZtb6WTolZsBUYjgL7MdYEQHMz/N4WoPCXCEbUQU5rZ test@test.com\\\",\\\"claimsMapper\\\":[{\\\"assertion_claim\\\":\\\"email\\\",\\\"token_claim\\\":\\\"email\\\"}]}\",\n \"grantType\": \"urn:ietf:params:oauth:grant-type:jwt-bearer\",\n \"identityProvider\": \"{{idp.inmemory}}\",\n \"createUser\": false,\n \"userExists\": false\n}" + "raw": "{\n \"type\": \"jwtbearer-am-extension-grant\",\n \"name\": \"JWT BEARER\",\n \"configuration\": \"{\\\"publicKey\\\":\\\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDI6xahwspOwhzSHrga3SFif04FITcAhyygXoeS+GwUSx6HaMCMkULTQVMgQoU/7VAUf32uoiVgLDo1FI6vWvBGbp1Zbf7MRVpqK98PvhTK4PN5py2OAmpd3i3z5SgGZCP1oxJE/uF+mMUkvtQOJ+RL32pU8oaAwzPuBLKX/jA5OZPouq6Y5e7abrgValYyGCI8aZK5SfukZTMq14mDc84Y2t4IvwS/GqSUiRsTp7r6aj5F+lwD0vyUBo3eH5v5J1R+t7F8T/B2Jl+oJQTPLFxBwcN/2AGC5aqrn7BDoGUG2NZtb6WTolZsBUYjgL7MdYEQHMz/N4WoPCXCEbUQU5rZ test@test.com\\\",\\\"claimsMapper\\\":[{\\\"assertion_claim\\\":\\\"email\\\",\\\"token_claim\\\":\\\"email\\\"}]}\",\n \"grantType\": \"urn:ietf:params:oauth:grant-type:jwt-bearer\",\n \"identityProvider\": \"{{idp.inmemory}}\",\n \"createUser\": false,\n \"userExists\": false\n}" }, "url": { "raw": "{{management_url}}/management/organizations/{{defaultOrganizationId}}/environments/{{defaultEnvironmentId}}/domains/{{domain}}/extensionGrants/{{jwtBearerExtensionGrant}}",