From 6d6e09b9de96399b06f7470375f8bdd4408f725a Mon Sep 17 00:00:00 2001 From: AngelTG2 Date: Mon, 19 Apr 2021 18:13:24 +0200 Subject: [PATCH 1/4] fixes #5177 --- .../openapi/impl/OpenApiService.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java index b2e701b4e4e..4e5300e7a88 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java @@ -106,29 +106,40 @@ public void setCorsHeaders(boolean withCorsHeaders) { this.withCorsHeaders = withCorsHeaders; } - public void registerApp(String applicationId, DeploymentContext ctx) { + public void registerApp(String applicationId, DeploymentContext ctx) { final WebBundleDescriptorImpl descriptor = ctx.getModuleMetaData(WebBundleDescriptorImpl.class); final String contextRoot = descriptor.getContextRoot(); final ReadableArchive archive = ctx.getSource(); final ClassLoader classLoader = ctx.getClassLoader(); - documents.put(applicationId, new OpenAPISupplier(applicationId, contextRoot, archive, classLoader)); + + if (this.enabled) { + documents.put(applicationId, new OpenAPISupplier(applicationId, contextRoot, archive, classLoader)); + } cachedResult = null; - } + } - public void deregisterApp(String applicationId) { - documents.remove(applicationId); + public void deregisterApp(String applicationId) { + if (documents.get(applicationId) != null) { + documents.remove(applicationId); + } cachedResult = null; - } + } - public void resumeApp(String applicationId) { - documents.get(applicationId).setEnabled(true); + public void resumeApp(String applicationId) { + OpenAPISupplier supplier=documents.get(applicationId); + if (supplier != null) { + supplier.setEnabled(true); + } cachedResult = null; - } + } - public void suspendApp(String applicationId) { - documents.get(applicationId).setEnabled(false); + public void suspendApp(String applicationId) { + OpenAPISupplier supplier=documents.get(applicationId); + if (supplier != null) { + supplier.setEnabled(false); + } cachedResult = null; - } + } /** * @return the document If multiple application deployed then merge all the From 4c6197dda504c5807cb3049558fcac3fc3e5a098 Mon Sep 17 00:00:00 2001 From: AngelTG2 Date: Wed, 21 Apr 2021 12:17:20 +0200 Subject: [PATCH 2/4] fixes #5177 v2 --- .../openapi/impl/OpenApiService.java | 19 ++++--------------- .../source/PasswordAliasConfigSource.java | 17 +++++++++++++++++ .../microprofile/config/spi/PayaraConfig.java | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java index 4e5300e7a88..f367e431e0c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java @@ -111,33 +111,22 @@ public void registerApp(String applicationId, DeploymentContext ctx) { final String contextRoot = descriptor.getContextRoot(); final ReadableArchive archive = ctx.getSource(); final ClassLoader classLoader = ctx.getClassLoader(); - - if (this.enabled) { - documents.put(applicationId, new OpenAPISupplier(applicationId, contextRoot, archive, classLoader)); - } + documents.put(applicationId, new OpenAPISupplier(applicationId, contextRoot, archive, classLoader)); cachedResult = null; } public void deregisterApp(String applicationId) { - if (documents.get(applicationId) != null) { - documents.remove(applicationId); - } + documents.remove(applicationId); cachedResult = null; } public void resumeApp(String applicationId) { - OpenAPISupplier supplier=documents.get(applicationId); - if (supplier != null) { - supplier.setEnabled(true); - } + documents.get(applicationId).setEnabled(true); cachedResult = null; } public void suspendApp(String applicationId) { - OpenAPISupplier supplier=documents.get(applicationId); - if (supplier != null) { - supplier.setEnabled(false); - } + documents.get(applicationId).setEnabled(false); cachedResult = null; } diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java index 9224bc6e16d..a5d8798484f 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java @@ -55,6 +55,9 @@ import org.glassfish.config.support.TranslatedConfigView; import org.glassfish.internal.api.Globals; +import java.util.Set; +import java.util.HashSet; + /** * * @author steve @@ -86,6 +89,20 @@ public Map getProperties() { return properties; } + @Override + public Set getPropertyNames() { + Set propertyNames = new HashSet<>(); + if (store != null) { + Iterator keys = store.keys(); + while (keys.hasNext()){ + String key = keys.next(); + propertyNames.add(key); + } + } + return propertyNames; + } + + @Override public String getValue(String name) { if (name == null || store == null) { diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java index d74a605f677..36aba1c0432 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java @@ -192,7 +192,7 @@ private T getValueInternal(String propertyName, Class propertyType) { public Iterable getPropertyNames() { List result = new ArrayList<>(); for (ConfigSource configSource : sources) { - result.addAll(configSource.getProperties().keySet()); + result.addAll(configSource.getPropertyNames()); } return result; } From dc8c0a765991b334074a2154c262336da163fcb5 Mon Sep 17 00:00:00 2001 From: lprimak Date: Fri, 23 Apr 2021 13:28:14 -0500 Subject: [PATCH 3/4] cleanup / refactor / simplify --- .../source/PasswordAliasConfigSource.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java index a5d8798484f..c0fa021667a 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2018-2020 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2018-2021 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -47,7 +47,6 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -65,11 +64,11 @@ public class PasswordAliasConfigSource extends PayaraConfigSource { private final DomainScopedPasswordAliasStore store; - + public PasswordAliasConfigSource() { store = Globals.getDefaultHabitat().getService(DomainScopedPasswordAliasStore.class); } - + @Override public int getOrdinal() { return Integer.parseInt(configService.getMPConfig().getPasswordOrdinality()); @@ -79,26 +78,14 @@ public int getOrdinal() { @Override public Map getProperties() { Map properties = new HashMap<>(); - if (store != null) { - Iterator keys = store.keys(); - while (keys.hasNext()){ - String key = keys.next(); - properties.put(key, new String(store.get(key))); - } - } + store.keys().forEachRemaining(key -> properties.put(key, new String(store.get(key)))); return properties; } @Override public Set getPropertyNames() { Set propertyNames = new HashSet<>(); - if (store != null) { - Iterator keys = store.keys(); - while (keys.hasNext()){ - String key = keys.next(); - propertyNames.add(key); - } - } + store.keys().forEachRemaining(propertyNames::add); return propertyNames; } @@ -136,5 +123,4 @@ public String getValue(String name) { public String getName() { return "Password Alias"; } - } From 89c80c49861d035fb7e7323efd15bbcfdcb76200 Mon Sep 17 00:00:00 2001 From: lprimak Date: Fri, 23 Apr 2021 13:30:57 -0500 Subject: [PATCH 4/4] null check --- .../config/source/PasswordAliasConfigSource.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java index c0fa021667a..4a972ace23c 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/source/PasswordAliasConfigSource.java @@ -56,6 +56,7 @@ import java.util.Set; import java.util.HashSet; +import java.util.Objects; /** * @@ -92,9 +93,7 @@ public Set getPropertyNames() { @Override public String getValue(String name) { - if (name == null || store == null) { - return null; - } + Objects.requireNonNull(name, "Name perameter cannot be null"); String value = null;