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 {
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<String> 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<String> 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);
}
/**

@ -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()) {

@ -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<String, Element> 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;

@ -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";
}

Loading…
Cancel
Save