diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java index 2ed0d17bee8..bc3a26b88d2 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java @@ -1228,15 +1228,18 @@ public class UserManagementServiceImpl implements UserManagementService { } private String getTemplateName(String deviceType, String prefix, String separator) throws NoSuchFileException { - String templateName = deviceType + separator + prefix; - File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator - + "resources" + File.separator + "email-templates" + File.separator + templateName + ".vm"); + String templateName = deviceType + separator + prefix + ".vm"; + List templatePathSegments = + Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", templateName); + File template = new File(String.join(File.separator, templatePathSegments)); if (template.exists()) { return templateName; } - String defaultTemplateName = "default" + separator + prefix; - File defaultTemplate = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator - + "resources" + File.separator + "email-templates" + File.separator + defaultTemplateName + ".vm"); + + String defaultTemplateName = "default" + separator + prefix + ".vm"; + List defaultTemplatePathSegments = + Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", defaultTemplateName); + File defaultTemplate = new File(String.join(File.separator, defaultTemplatePathSegments)); if (defaultTemplate.exists()) { if (log.isDebugEnabled()) { @@ -1245,8 +1248,7 @@ public class UserManagementServiceImpl implements UserManagementService { return defaultTemplateName; } - String msg = "Didn't found template file for " + templateName; - throw new NoSuchFileException(msg); + throw new NoSuchFileException("Didn't found template file for " + templateName); } /** diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITEnrollmentCallbackHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITEnrollmentCallbackHandler.java index e0b33691b16..6a82ae3f268 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITEnrollmentCallbackHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITEnrollmentCallbackHandler.java @@ -124,15 +124,15 @@ public class JITEnrollmentCallbackHandler extends HttpServlet { Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile); JITConfigurationDoc.getDocumentElement().normalize(); Element enrollmentScopes; - if (Objects.equals(JITEnrollmentInfo.getOs(), "android")) { + if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_ANDROID)) { enrollmentScopes = (Element) JITConfigurationDoc. - getElementsByTagName("AndroidEnrollmentScopes").item(0); - } else if (Objects.equals(JITEnrollmentInfo.getOs(), "ios")) { + getElementsByTagName(HandlerConstants.TAG_ANDROID_ENROLLMENT_SCOPES).item(0); + } else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_IOS)) { enrollmentScopes = (Element) JITConfigurationDoc. - getElementsByTagName("IOSEnrollmentScopes").item(0); - } else if (Objects.equals(JITEnrollmentInfo.getOs(), "windows")) { + getElementsByTagName(HandlerConstants.TAG_IOS_ENROLLMENT_SCOPES).item(0); + } else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_WINDOWS)) { enrollmentScopes = (Element) JITConfigurationDoc. - getElementsByTagName("IOSEnrollmentScopes").item(0); + getElementsByTagName(HandlerConstants.TAG_WINDOWS_ENROLLMENT_SCOPES).item(0); } else { String msg = "OS type not supported"; if (log.isDebugEnabled()) { diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITProvisionHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITProvisionHandler.java index 5ff97d4a872..9c1cf31a942 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITProvisionHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/JITProvisionHandler.java @@ -52,6 +52,8 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.util.Base64; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; @@ -71,6 +73,7 @@ public class JITProvisionHandler extends HttpServlet { private String JITConfigurationPath; private String redirectUrl; private String state; + private static final Map tenantConfigs = new HashMap<>(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { @@ -165,13 +168,17 @@ public class JITProvisionHandler extends HttpServlet { */ private boolean initializeJITConfigurations() throws JITProvisionException { try { - File JITConfigurationFile = new File(JITConfigurationPath); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile); - JITConfigurationDoc.getDocumentElement().normalize(); - Element serviceProvider = findServiceProvider(tenantDomain, JITConfigurationDoc); - if (serviceProvider == null) return false; + Element serviceProvider = tenantConfigs.get(tenantDomain); + if (serviceProvider == null) { + File JITConfigurationFile = new File(JITConfigurationPath); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile); + JITConfigurationDoc.getDocumentElement().normalize(); + serviceProvider = findServiceProvider(tenantDomain, JITConfigurationDoc); + if (serviceProvider == null) return false; + tenantConfigs.put(tenantDomain, serviceProvider); + } clientId = serviceProvider.getElementsByTagName("ClientId").item(0).getTextContent(); String clientSecret = serviceProvider.getElementsByTagName("ClientSecret").item(0).getTextContent(); String headerValue = clientId + ":" + clientSecret; diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java index f7f4399a772..44aedaafe5c 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java @@ -115,4 +115,10 @@ public class HandlerConstants { public static final String JIT_PROVISION_HANDLER = "/jit-provision"; public static final String JIT_ENROLLMENT_AUTH_APP_KEY = "JIT_ENROLLMENT_AUTH_APP"; public static final String CLIENT_CREDENTIAL_GRANT_TYPE = "client_credentials"; + public static final String OS_ANDROID = "android"; + public static final String OS_WINDOWS = "windows"; + public static final String OS_IOS = "ios"; + public static final String TAG_ANDROID_ENROLLMENT_SCOPES = "AndroidEnrollmentScopes"; + public static final String TAG_WINDOWS_ENROLLMENT_SCOPES = "WindowsEnrollmentScopes"; + public static final String TAG_IOS_ENROLLMENT_SCOPES = "IOSEnrollmentScopes"; }