Search in sources :

Example 1 with IdentityGovernanceAdminClient

use of org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient in project carbon-identity-framework by wso2.

the class Util method isUserOnBoardingEnabled.

public static boolean isUserOnBoardingEnabled(ServletContext context, HttpSession session) {
    if (!isAskPasswordAdminUIEnabled) {
        return false;
    }
    String backendServerURL = CarbonUIUtil.getServerURL(context, session);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    ConfigurationContext configContext = (ConfigurationContext) context.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    Map<String, Map<String, List<ConnectorConfig>>> connectorList;
    try {
        IdentityGovernanceAdminClient client = new IdentityGovernanceAdminClient(cookie, backendServerURL, configContext);
        connectorList = client.getConnectorList();
    } catch (Exception e) {
        log.error("Error while getting connector list from governance service, at URL :" + backendServerURL, e);
        return false;
    }
    if (connectorList != null) {
        for (Map.Entry<String, Map<String, List<ConnectorConfig>>> entry : connectorList.entrySet()) {
            Map<String, List<ConnectorConfig>> subCatList = entry.getValue();
            for (String subCatKey : subCatList.keySet()) {
                List<ConnectorConfig> connectorConfigs = subCatList.get(subCatKey);
                for (ConnectorConfig connectorConfig : connectorConfigs) {
                    Property[] properties = connectorConfig.getProperties();
                    for (Property property : properties) {
                        if (property != null) {
                            if (EMAIL_VERIFICATION_ENABLE_PROP_NAME.equals(property.getName())) {
                                String propValue = property.getValue();
                                boolean isEmailVerificationEnabled = false;
                                if (!StringUtils.isEmpty(propValue)) {
                                    isEmailVerificationEnabled = Boolean.parseBoolean(propValue);
                                }
                                return isEmailVerificationEnabled;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : IdentityGovernanceAdminClient(org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConnectorConfig(org.wso2.carbon.identity.governance.stub.bean.ConnectorConfig) CryptoException(org.wso2.carbon.core.util.CryptoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) CarbonException(org.wso2.carbon.CarbonException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Property(org.wso2.carbon.identity.governance.stub.bean.Property)

Example 2 with IdentityGovernanceAdminClient

use of org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient in project carbon-identity-framework by wso2.

the class Util method getAskPasswordTempPassGenerator.

public static RandomPasswordGenerator getAskPasswordTempPassGenerator(ServletContext context, HttpSession session) {
    if (!isAskPasswordAdminUIEnabled) {
        return new DefaultPasswordGenerator();
    }
    String randomPasswordGenerationClass = "org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator";
    if (isUserOnBoardingEnabled(context, session)) {
        String backendServerURL = CarbonUIUtil.getServerURL(context, session);
        String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
        ConfigurationContext configContext = (ConfigurationContext) context.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        Map<String, Map<String, List<ConnectorConfig>>> connectorList;
        try {
            IdentityGovernanceAdminClient client = new IdentityGovernanceAdminClient(cookie, backendServerURL, configContext);
            connectorList = client.getConnectorList();
            if (connectorList != null) {
                for (Map.Entry<String, Map<String, List<ConnectorConfig>>> entry : connectorList.entrySet()) {
                    Map<String, List<ConnectorConfig>> subCatList = entry.getValue();
                    for (String subCatKey : subCatList.keySet()) {
                        List<ConnectorConfig> connectorConfigs = subCatList.get(subCatKey);
                        for (ConnectorConfig connectorConfig : connectorConfigs) {
                            Property[] properties = connectorConfig.getProperties();
                            for (Property property : properties) {
                                if (ASK_PASSWORD_TEMP_PASSWORD_GENERATOR.equals(property.getName())) {
                                    randomPasswordGenerationClass = property.getValue();
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("Error while getting connector list from governance service, at URL :" + backendServerURL, e);
        }
    } else {
        String randomPasswordGenerationClassFromFile = IdentityUtil.getProperty(ASK_PASSWORD_TEMP_PASSWORD_GENERATOR);
        if (StringUtils.isNotBlank(randomPasswordGenerationClassFromFile)) {
            randomPasswordGenerationClass = randomPasswordGenerationClassFromFile;
        }
    }
    try {
        Class clazz = Class.forName(randomPasswordGenerationClass);
        return (RandomPasswordGenerator) clazz.newInstance();
    } catch (Exception e) {
        log.error("Error while loading random password generator class. " + "Default random password generator would be used", e);
    }
    return new DefaultPasswordGenerator();
}
Also used : IdentityGovernanceAdminClient(org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConnectorConfig(org.wso2.carbon.identity.governance.stub.bean.ConnectorConfig) DefaultPasswordGenerator(org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator) CryptoException(org.wso2.carbon.core.util.CryptoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) CarbonException(org.wso2.carbon.CarbonException) RandomPasswordGenerator(org.wso2.carbon.user.mgt.common.RandomPasswordGenerator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Property(org.wso2.carbon.identity.governance.stub.bean.Property)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 CarbonException (org.wso2.carbon.CarbonException)2 CryptoException (org.wso2.carbon.core.util.CryptoException)2 ConnectorConfig (org.wso2.carbon.identity.governance.stub.bean.ConnectorConfig)2 Property (org.wso2.carbon.identity.governance.stub.bean.Property)2 UserStoreException (org.wso2.carbon.user.core.UserStoreException)2 IdentityGovernanceAdminClient (org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient)2 DefaultPasswordGenerator (org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator)1 RandomPasswordGenerator (org.wso2.carbon.user.mgt.common.RandomPasswordGenerator)1