Add requested changes

fix-access-authorization
Rajitha Kumara 12 months ago
parent a9aa66173a
commit b144be0f97

@ -1228,15 +1228,18 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
private String getTemplateName(String deviceType, String prefix, String separator) throws NoSuchFileException { private String getTemplateName(String deviceType, String prefix, String separator) throws NoSuchFileException {
String templateName = deviceType + separator + prefix; String templateName = deviceType + separator + prefix + ".vm";
File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator List<String> templatePathSegments =
+ "resources" + File.separator + "email-templates" + File.separator + templateName + ".vm"); Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", templateName);
File template = new File(String.join(File.separator, templatePathSegments));
if (template.exists()) { if (template.exists()) {
return templateName; return templateName;
} }
String defaultTemplateName = "default" + separator + prefix;
File defaultTemplate = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator String defaultTemplateName = "default" + separator + prefix + ".vm";
+ "resources" + File.separator + "email-templates" + File.separator + defaultTemplateName + ".vm"); List<String> defaultTemplatePathSegments =
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", defaultTemplateName);
File defaultTemplate = new File(String.join(File.separator, defaultTemplatePathSegments));
if (defaultTemplate.exists()) { if (defaultTemplate.exists()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -1245,8 +1248,7 @@ public class UserManagementServiceImpl implements UserManagementService {
return defaultTemplateName; return defaultTemplateName;
} }
String msg = "Didn't found template file for " + templateName; throw new NoSuchFileException("Didn't found template file for " + templateName);
throw new NoSuchFileException(msg);
} }
/** /**

@ -124,15 +124,15 @@ public class JITEnrollmentCallbackHandler extends HttpServlet {
Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile); Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile);
JITConfigurationDoc.getDocumentElement().normalize(); JITConfigurationDoc.getDocumentElement().normalize();
Element enrollmentScopes; Element enrollmentScopes;
if (Objects.equals(JITEnrollmentInfo.getOs(), "android")) { if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_ANDROID)) {
enrollmentScopes = (Element) JITConfigurationDoc. enrollmentScopes = (Element) JITConfigurationDoc.
getElementsByTagName("AndroidEnrollmentScopes").item(0); getElementsByTagName(HandlerConstants.TAG_ANDROID_ENROLLMENT_SCOPES).item(0);
} else if (Objects.equals(JITEnrollmentInfo.getOs(), "ios")) { } else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_IOS)) {
enrollmentScopes = (Element) JITConfigurationDoc. enrollmentScopes = (Element) JITConfigurationDoc.
getElementsByTagName("IOSEnrollmentScopes").item(0); getElementsByTagName(HandlerConstants.TAG_IOS_ENROLLMENT_SCOPES).item(0);
} else if (Objects.equals(JITEnrollmentInfo.getOs(), "windows")) { } else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_WINDOWS)) {
enrollmentScopes = (Element) JITConfigurationDoc. enrollmentScopes = (Element) JITConfigurationDoc.
getElementsByTagName("IOSEnrollmentScopes").item(0); getElementsByTagName(HandlerConstants.TAG_WINDOWS_ENROLLMENT_SCOPES).item(0);
} else { } else {
String msg = "OS type not supported"; String msg = "OS type not supported";
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -52,6 +52,8 @@ import javax.xml.parsers.ParserConfigurationException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -71,6 +73,7 @@ public class JITProvisionHandler extends HttpServlet {
private String JITConfigurationPath; private String JITConfigurationPath;
private String redirectUrl; private String redirectUrl;
private String state; private String state;
private static final Map<String, Element> tenantConfigs = new HashMap<>();
@Override @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) { protected void doGet(HttpServletRequest request, HttpServletResponse response) {
@ -165,13 +168,17 @@ public class JITProvisionHandler extends HttpServlet {
*/ */
private boolean initializeJITConfigurations() throws JITProvisionException { private boolean initializeJITConfigurations() throws JITProvisionException {
try { try {
File JITConfigurationFile = new File(JITConfigurationPath); Element serviceProvider = tenantConfigs.get(tenantDomain);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); if (serviceProvider == null) {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); File JITConfigurationFile = new File(JITConfigurationPath);
Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
JITConfigurationDoc.getDocumentElement().normalize(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Element serviceProvider = findServiceProvider(tenantDomain, JITConfigurationDoc); Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile);
if (serviceProvider == null) return false; JITConfigurationDoc.getDocumentElement().normalize();
serviceProvider = findServiceProvider(tenantDomain, JITConfigurationDoc);
if (serviceProvider == null) return false;
tenantConfigs.put(tenantDomain, serviceProvider);
}
clientId = serviceProvider.getElementsByTagName("ClientId").item(0).getTextContent(); clientId = serviceProvider.getElementsByTagName("ClientId").item(0).getTextContent();
String clientSecret = serviceProvider.getElementsByTagName("ClientSecret").item(0).getTextContent(); String clientSecret = serviceProvider.getElementsByTagName("ClientSecret").item(0).getTextContent();
String headerValue = clientId + ":" + clientSecret; String headerValue = clientId + ":" + clientSecret;

@ -115,4 +115,10 @@ public class HandlerConstants {
public static final String JIT_PROVISION_HANDLER = "/jit-provision"; 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 JIT_ENROLLMENT_AUTH_APP_KEY = "JIT_ENROLLMENT_AUTH_APP";
public static final String CLIENT_CREDENTIAL_GRANT_TYPE = "client_credentials"; 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";
} }

Loading…
Cancel
Save