-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add plugin validation capability
fixes AM-3373
- Loading branch information
1 parent
fa28b38
commit 1745bcb
Showing
85 changed files
with
643 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...am-certificate-api/src/main/java/io/gravitee/am/certificate/api/CertificateProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<Date> getExpirationDate() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Single<Key> key() { | ||
return Single.just(certificateKey); | ||
} | ||
|
||
@Override | ||
public Flowable<JWK> privateKey() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Single<String> publicKey() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Flowable<JWK> keys() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String signatureAlgorithm() { | ||
return signatureAlgorithm.getValue(); | ||
} | ||
|
||
@Override | ||
public CertificateMetadata certificateMetadata() { | ||
return certificateMetadata; | ||
} | ||
}; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...certificate-api/src/main/java/io/gravitee/am/certificate/api/NoneCertificateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<Date> getExpirationDate() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Flowable<JWK> privateKey() { | ||
throw new UnsupportedOperationException("No private key for \"none\" algorithm"); | ||
} | ||
|
||
@Override | ||
public Single<io.gravitee.am.certificate.api.Key> key() { | ||
throw new UnsupportedOperationException("No key for \"none\" algorithm"); | ||
} | ||
|
||
@Override | ||
public Single<String> publicKey() { | ||
throw new UnsupportedOperationException("No public key for \"none\" algorithm"); | ||
} | ||
|
||
@Override | ||
public Flowable<JWK> keys() { | ||
throw new UnsupportedOperationException("No keys for \"none\" algorithm"); | ||
} | ||
|
||
@Override | ||
public String signatureAlgorithm() { | ||
return SignatureAlgorithm.NONE.getValue(); | ||
} | ||
|
||
@Override | ||
public CertificateMetadata certificateMetadata() { | ||
return metadata; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/AmPluginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
gravitee-am-common/src/main/java/io/gravitee/am/common/plugin/ValidationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<String, Object> additionalInformation){ | ||
public static final ValidationResult SUCCEEDED = new ValidationResult(true, null, Map.of()); | ||
public boolean failed(){ | ||
return !succeeded; | ||
} | ||
|
||
public <T> Optional<T> getAdditionalInformation(String key, Class<T> 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<String, Object> 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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.