From e95f8c7b495f2b1b77bf6c3e8ccdea499cd43ba2 Mon Sep 17 00:00:00 2001 From: shekhar16 Date: Tue, 14 Jan 2025 22:31:28 +0530 Subject: [PATCH 1/2] fix(jans-keycloak-link): unstatisfied dependencies Signed-off-by: shekhar16 --- jans-keycloak-link/server/pom.xml | 10 -- .../server/service/ConfigurationService.java | 97 +++++++++++++++++++ .../service/config/ApplicationFactory.java | 51 ++++++++++ 3 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/server/service/ConfigurationService.java diff --git a/jans-keycloak-link/server/pom.xml b/jans-keycloak-link/server/pom.xml index 75a754de219..034ca6d63f9 100644 --- a/jans-keycloak-link/server/pom.xml +++ b/jans-keycloak-link/server/pom.xml @@ -33,16 +33,6 @@ io.jans jans-core-service - - - io.jans - jans-core-document-store - - - io.jans - jans-core-message - - diff --git a/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/server/service/ConfigurationService.java b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/server/service/ConfigurationService.java new file mode 100644 index 00000000000..4f8a766e64a --- /dev/null +++ b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/server/service/ConfigurationService.java @@ -0,0 +1,97 @@ +/* + * Copyright [2024] [Janssen Project] + * + * 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.jans.keycloak.link.server.service; + +import io.jans.config.GluuConfiguration; +import io.jans.keycloak.link.model.config.StaticConfiguration; +import io.jans.model.SmtpConfiguration; +import io.jans.orm.PersistenceEntryManager; +import io.jans.service.EncryptionService; +import io.jans.util.StringHelper; +import io.jans.util.security.StringEncrypter.EncryptionException; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.slf4j.Logger; + +/** + * + * @author Yuriy Movchan Date: 12/12/2023 + */ +@ApplicationScoped +public class ConfigurationService { + + @Inject + private Logger log; + + @Inject + private PersistenceEntryManager persistenceEntryManager; + + @Inject + private StaticConfiguration staticConfiguration; + + @Inject + private EncryptionService encryptionService; + + public GluuConfiguration getConfiguration() { + String configurationDn = staticConfiguration.getBaseDn().getConfiguration(); + if (StringHelper.isEmpty(configurationDn)) { + return null; + } + + return persistenceEntryManager.find(GluuConfiguration.class, configurationDn); + } + + /** + * Build DN string for configuration + * + * @param inum Inum + * @return DN string for specified configuration or DN for configurations branch if inum is null + * @throws Exception + */ + public String getDnForConfiguration(String inum) { + String baseDn = staticConfiguration.getBaseDn().getConfiguration(); + if (StringHelper.isEmpty(inum)) { + return baseDn; + } + + return String.format("inum=%s,%s", inum, baseDn); + } + + public void decryptSmtpPasswords(SmtpConfiguration smtpConfiguration) { + if (smtpConfiguration == null) { + return; + } + String password = smtpConfiguration.getSmtpAuthenticationAccountPassword(); + if (StringHelper.isNotEmpty(password)) { + try { + smtpConfiguration.setSmtpAuthenticationAccountPasswordDecrypted(encryptionService.decrypt(password)); + } catch (EncryptionException ex) { + log.error("Failed to decrypt SMTP user password", ex); + } + } + password = smtpConfiguration.getKeyStorePassword(); + if (StringHelper.isNotEmpty(password)) { + try { + smtpConfiguration.setKeyStorePasswordDecrypted(encryptionService.decrypt(password)); + } catch (EncryptionException ex) { + log.error("Failed to decrypt Kestore password", ex); + } + } + } + +} + diff --git a/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java index 63e8978275d..372fe6cb4cd 100644 --- a/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java +++ b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java @@ -6,6 +6,14 @@ package io.jans.keycloak.link.service.config; +import io.jans.config.GluuConfiguration; +import io.jans.keycloak.link.server.service.ConfigurationService; +import io.jans.service.document.store.conf.DocumentStoreConfiguration; +import io.jans.service.document.store.conf.LocalDocumentStoreConfiguration; +import io.jans.service.message.model.config.MessageConfiguration; +import io.jans.service.message.model.config.MessageProviderType; +import io.jans.service.message.model.config.NullMessageConfiguration; +import jakarta.enterprise.inject.Produces; import org.slf4j.Logger; import io.jans.keycloak.link.model.config.AppConfiguration; @@ -35,6 +43,9 @@ public class ApplicationFactory { @Inject private AppConfiguration appConfiguration; + @Inject + private ConfigurationService сonfigurationService; + public static final String PERSISTENCE_ENTRY_MANAGER_FACTORY_NAME = "persistenceEntryManagerFactory"; public static final String PERSISTENCE_ENTRY_MANAGER_NAME = "persistenceEntryManager"; @@ -57,4 +68,44 @@ public PersistenceEntryManagerFactory getPersistenceEntryManagerFactory(Class Date: Tue, 14 Jan 2025 23:55:22 +0530 Subject: [PATCH 2/2] fix(oxtrust): sonar fixes Signed-off-by: shekhar16 --- .../keycloak/link/service/config/ApplicationFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java index 372fe6cb4cd..4804abbd9ae 100644 --- a/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java +++ b/jans-keycloak-link/server/src/main/java/io/jans/keycloak/link/service/config/ApplicationFactory.java @@ -75,7 +75,7 @@ public DocumentStoreConfiguration getDocumentStoreConfiguration() { DocumentStoreConfiguration documentStoreConfiguration = jansConf.getDocumentStoreConfiguration(); if ((documentStoreConfiguration == null) || (documentStoreConfiguration.getDocumentStoreType() == null)) { log.error("Failed to read document store configuration from DB. Please check configuration jsDocStoreConf attribute " + - "that must contain document store configuration JSON represented by DocumentStoreConfiguration.class. Appliance DN: " + jansConf.getDn()); + "that must contain document store configuration JSON represented by DocumentStoreConfiguration.class. Appliance DN: {0}", jansConf.getDn()); log.info("Creating fallback LOCAL document store configuration ... "); documentStoreConfiguration = new DocumentStoreConfiguration(); @@ -84,7 +84,7 @@ public DocumentStoreConfiguration getDocumentStoreConfiguration() { log.info("LOCAL document store configuration is created."); } - log.info("Document store configuration: " + documentStoreConfiguration); + log.info("Document store configuration: {0}" , documentStoreConfiguration); return documentStoreConfiguration; } @@ -95,7 +95,7 @@ public MessageConfiguration getMessageConfiguration() { MessageConfiguration messageConfiguration = jansConf.getMessageConfiguration(); if (messageConfiguration == null || messageConfiguration.getMessageProviderType() == null) { log.error("Failed to read message configuration from DB. Please check configuration jsMessageConf attribute " + - "that must contain message configuration JSON represented by MessageConfiguration.class. Appliance DN: " + jansConf.getDn()); + "that must contain message configuration JSON represented by MessageConfiguration.class. Appliance DN: {0}" , jansConf.getDn()); log.info("Creating fallback Null message configuration ... "); messageConfiguration = new MessageConfiguration(); @@ -105,7 +105,7 @@ public MessageConfiguration getMessageConfiguration() { log.info("NULL message configuration is created."); } - log.info("Message configuration: " + messageConfiguration); + log.info("Message configuration: {0}" , messageConfiguration); return messageConfiguration; } } \ No newline at end of file