Search in sources :

Example 1 with RandomPasswordGenerator

use of org.wso2.carbon.user.mgt.common.RandomPasswordGenerator 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)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 CarbonException (org.wso2.carbon.CarbonException)1 CryptoException (org.wso2.carbon.core.util.CryptoException)1 ConnectorConfig (org.wso2.carbon.identity.governance.stub.bean.ConnectorConfig)1 Property (org.wso2.carbon.identity.governance.stub.bean.Property)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1 DefaultPasswordGenerator (org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator)1 RandomPasswordGenerator (org.wso2.carbon.user.mgt.common.RandomPasswordGenerator)1 IdentityGovernanceAdminClient (org.wso2.carbon.user.mgt.ui.client.IdentityGovernanceAdminClient)1