use of org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getScriptConfiguration.
private AuthenticationScriptConfig getScriptConfiguration(int applicationId, Connection connection) throws SQLException, IdentityApplicationManagementException {
try (PreparedStatement localAndOutboundConfigScriptPrepStmt = connection.prepareStatement(LOAD_SCRIPT_BY_APP_ID_QUERY)) {
localAndOutboundConfigScriptPrepStmt.setInt(1, applicationId);
try (ResultSet localAndOutboundConfigScriptResultSet = localAndOutboundConfigScriptPrepStmt.executeQuery()) {
if (localAndOutboundConfigScriptResultSet.next()) {
AuthenticationScriptConfig authenticationScriptConfig = new AuthenticationScriptConfig();
try {
boolean isEnabled = "1".equals(localAndOutboundConfigScriptResultSet.getString(2));
InputStream scriptBinaryStream = localAndOutboundConfigScriptResultSet.getBinaryStream(1);
String targetString = StringUtils.EMPTY;
if (scriptBinaryStream != null) {
targetString = IOUtils.toString(scriptBinaryStream);
}
authenticationScriptConfig.setContent(targetString);
authenticationScriptConfig.setEnabled(isEnabled);
} catch (IOException e) {
throw new IdentityApplicationManagementException("Could not read the Script for application : " + applicationId, e);
}
return authenticationScriptConfig;
}
}
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getServiceProviderByClientId.
/**
* @param clientId
* @param clientType
* @param tenantDomain
* @return
* @throws IdentityApplicationManagementException
*/
@Override
public ServiceProvider getServiceProviderByClientId(String clientId, String clientType, String tenantDomain) throws IdentityApplicationManagementException {
// invoking the listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPreGetServiceProviderByClientId(clientId, clientType, tenantDomain)) {
return null;
}
}
// client id can contain the @ to identify the tenant domain.
if (clientId != null && clientId.contains("@")) {
clientId = clientId.split("@")[0];
}
String serviceProviderName;
ServiceProvider serviceProvider = null;
serviceProviderName = getServiceProviderNameByClientId(clientId, clientType, tenantDomain);
try {
startTenantFlow(tenantDomain);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
serviceProvider = appDAO.getApplication(serviceProviderName, tenantDomain);
if (serviceProvider != null) {
// if "Authentication Type" is "Default" we must get the steps from the default SP
AuthenticationStep[] authenticationSteps = serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps();
if (authenticationSteps == null || authenticationSteps.length == 0) {
ServiceProvider defaultSP = ApplicationManagementServiceComponent.getFileBasedSPs().get(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
authenticationSteps = defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps();
AuthenticationScriptConfig scriptConfig = defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationScriptConfig();
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(authenticationSteps);
if (scriptConfig != null) {
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(scriptConfig);
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(ApplicationConstants.AUTH_TYPE_FLOW);
}
}
}
} finally {
endTenantFlow();
}
if (serviceProvider == null && serviceProviderName != null && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
}
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostGetServiceProviderByClientId(serviceProvider, clientId, clientType, tenantDomain)) {
return null;
}
}
return serviceProvider;
}
use of org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig in project carbon-identity-framework by wso2.
the class ApplicationBean method conditionalAuthentication.
/**
* @param request
*/
public void conditionalAuthentication(HttpServletRequest request) {
AuthenticationScriptConfig authenticationScriptConfig = new AuthenticationScriptConfig();
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
String flawByScript = request.getParameter("scriptTextArea");
if (StringUtils.isBlank(flawByScript)) {
authenticationScriptConfig.setEnabled(false);
} else {
if ("true".equalsIgnoreCase(request.getParameter("enableScript"))) {
authenticationScriptConfig.setEnabled(true);
} else {
authenticationScriptConfig.setEnabled(false);
}
}
authenticationScriptConfig.setContent(flawByScript);
localAndOutboundAuthenticationConfig.setAuthenticationScriptConfig(authenticationScriptConfig);
}
use of org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig in project carbon-identity-framework by wso2.
the class DefaultApplicationValidatorTest method validateAdaptiveAuthScriptTest.
@Test(dataProvider = "validateAdaptiveAuthScriptDataProvider")
public void validateAdaptiveAuthScriptTest(String isValidationFailScenario, String isLoopsAllowed, String script) throws Exception {
DefaultApplicationValidator defaultApplicationValidator = new DefaultApplicationValidator();
Field configuration = IdentityUtil.class.getDeclaredField("configuration");
configuration.setAccessible(true);
Map<String, Object> configMap = new HashMap<>();
configMap.put("AdaptiveAuth.AllowLoops", isLoopsAllowed);
configuration.set(IdentityUtil.class, configMap);
Method validateAdaptiveAuthScript = DefaultApplicationValidator.class.getDeclaredMethod("validateAdaptiveAuthScript", List.class, AuthenticationScriptConfig.class);
validateAdaptiveAuthScript.setAccessible(true);
AuthenticationScriptConfig scriptConfig = new AuthenticationScriptConfig();
scriptConfig.setContent(script);
List<String> validationErrors = new ArrayList<>();
validateAdaptiveAuthScript.invoke(defaultApplicationValidator, validationErrors, scriptConfig);
if (Boolean.parseBoolean(isValidationFailScenario)) {
Assert.assertFalse(validationErrors.isEmpty(), "This is an invalid scenario. There should be " + "validation messages.");
List<String> filtered = validationErrors.stream().filter(error -> StringUtils.containsIgnoreCase(error, "loop")).collect(Collectors.toList());
Assert.assertFalse(filtered.isEmpty(), "There should be a validation message related to loops");
} else {
Assert.assertTrue(validationErrors.isEmpty(), "There are validation messages. This is a valid case " + "there should not be any validation messages. Validation messages: " + String.join("|", validationErrors));
}
}
use of org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig in project product-is by wso2.
the class DefaultAuthSeqManagementTestCase method updateApplicationData.
private void updateApplicationData(String name) {
try {
ServiceProvider serviceProvider = applicationManagementServiceClient.getApplication(name);
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType("flow");
AuthenticationStep authStep = new AuthenticationStep();
authStep.setStepOrder(1);
authStep.setAttributeStep(true);
authStep.setSubjectStep(true);
LocalAuthenticatorConfig localAuthenticatorConfig = new LocalAuthenticatorConfig();
localAuthenticatorConfig.setName("BasicAuthenticator");
localAuthenticatorConfig.setDisplayName("basic");
localAuthenticatorConfig.setEnabled(true);
authStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuthenticatorConfig });
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
AuthenticationScriptConfig scriptConfig = new AuthenticationScriptConfig();
scriptConfig.setLanguage("application/javascript");
scriptConfig.setContent("function onLoginRequest(context) {\r\n executeStep(1);\r\n}\r\n");
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(scriptConfig);
applicationManagementServiceClient.updateApplicationData(serviceProvider);
ServiceProvider updatedServiceProvider = applicationManagementServiceClient.getApplication(applicationName);
Assert.assertEquals(updatedServiceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps()[0].getLocalAuthenticatorConfigs()[0].getDisplayName(), "basic", "Failed update Authentication step");
} catch (Exception e) {
fail("Error while trying to update Service Provider", e);
}
}
Aggregations