Search in sources :

Example 1 with DefaultApplicationValidator

use of org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator 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));
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DataProvider(org.testng.annotations.DataProvider) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) DefaultApplicationValidator(org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator) ArrayList(java.util.ArrayList) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) List(java.util.List) Assert(org.testng.Assert) Map(java.util.Map) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) DefaultApplicationValidator(org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator) HashMap(java.util.HashMap) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 2 with DefaultApplicationValidator

use of org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceComponent method activate.

@Activate
protected void activate(ComponentContext context) {
    try {
        buildFileBasedSPList();
        if (log.isDebugEnabled()) {
            log.debug("File based SP building completed");
        }
        loadAuthenticationTemplates();
        if (log.isDebugEnabled()) {
            log.debug("Authentication templates are loaded");
        }
        bundleContext = context.getBundleContext();
        // Registering Application management service as a OSGIService
        bundleContext.registerService(ApplicationManagementService.class.getName(), ApplicationManagementServiceImpl.getInstance(), null);
        bundleContext.registerService(IdentityProviderMgtListener.class.getName(), new ApplicationIdentityProviderMgtListener(), null);
        ApplicationMgtSystemConfig.getInstance();
        bundleContext.registerService(ApplicationMgtListener.class.getName(), new ApplicationMgtAuditLogger(), null);
        bundleContext.registerService(DefaultAuthSeqMgtService.class.getName(), DefaultAuthSeqMgtServiceImpl.getInstance(), null);
        // Register the DefaultApplicationResourceMgtListener.
        context.getBundleContext().registerService(ApplicationResourceManagementListener.class, new DefaultApplicationResourceMgtListener(), null);
        bundleContext.registerService(DiscoverableApplicationManager.class.getName(), new DiscoverableApplicationManagerImpl(), null);
        bundleContext.registerService(ClaimMetadataMgtListener.class.getName(), new ApplicationClaimMgtListener(), null);
        // Register the ApplicationValidator.
        context.getBundleContext().registerService(ApplicationValidator.class, new DefaultApplicationValidator(), null);
        if (log.isDebugEnabled()) {
            log.debug("Identity ApplicationManagementComponent bundle is activated");
        }
    } catch (Exception e) {
        log.error("Error while activating ApplicationManagementComponent bundle", e);
    }
}
Also used : ApplicationClaimMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationClaimMgtListener) ApplicationIdentityProviderMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationIdentityProviderMgtListener) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) DiscoverableApplicationManager(org.wso2.carbon.identity.application.mgt.DiscoverableApplicationManager) ClaimMetadataMgtListener(org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataMgtListener) JSONException(org.json.JSONException) IOException(java.io.IOException) DiscoverableApplicationManagerImpl(org.wso2.carbon.identity.application.mgt.internal.impl.DiscoverableApplicationManagerImpl) ApplicationMgtAuditLogger(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtAuditLogger) DefaultAuthSeqMgtService(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtService) DefaultApplicationValidator(org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) ApplicationIdentityProviderMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationIdentityProviderMgtListener) DefaultApplicationResourceMgtListener(org.wso2.carbon.identity.application.mgt.listener.DefaultApplicationResourceMgtListener) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

DefaultApplicationValidator (org.wso2.carbon.identity.application.mgt.validator.DefaultApplicationValidator)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1 JSONException (org.json.JSONException)1 Activate (org.osgi.service.component.annotations.Activate)1 Assert (org.testng.Assert)1 DataProvider (org.testng.annotations.DataProvider)1 Test (org.testng.annotations.Test)1 AuthenticationScriptConfig (org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig)1 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)1 DiscoverableApplicationManager (org.wso2.carbon.identity.application.mgt.DiscoverableApplicationManager)1 DefaultAuthSeqMgtService (org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtService)1 DiscoverableApplicationManagerImpl (org.wso2.carbon.identity.application.mgt.internal.impl.DiscoverableApplicationManagerImpl)1