Search in sources :

Example 11 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class SecondaryUserStoreConfigurationUtil method triggerListenersOnUserStorePreAdd.

/**
 * Trigger the listeners before a userstore is added.
 *
 * @param userStoreDTO Userstore configuration to be added.
 * @throws UserStoreException throws when an error occurred when triggering listeners.
 */
public static void triggerListenersOnUserStorePreAdd(UserStoreDTO userStoreDTO) throws UserStoreException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<UserStoreConfigListener> userStoreConfigListeners = UserStoreConfigListenersHolder.getInstance().getUserStoreConfigListeners();
    for (UserStoreConfigListener userStoreConfigListener : userStoreConfigListeners) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Triggering userstore pre add listener: %s for tenant: %s", userStoreConfigListener.getClass().getName(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
        }
        userStoreConfigListener.onUserStorePreAdd(tenantId, userStoreDTO);
    }
}
Also used : UserStoreConfigListener(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)

Example 12 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class SecondaryUserStoreConfigurationUtil method triggerListenersOnUserStorePostGet.

/**
 * Trigger the listeners after a userstore is retrieved.
 *
 * @param userStoreDTO Retrieved userstore configuration.
 * @throws UserStoreException throws when an error occurred when triggering listeners.
 */
public static void triggerListenersOnUserStorePostGet(UserStoreDTO userStoreDTO) throws UserStoreException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<UserStoreConfigListener> userStoreConfigListeners = UserStoreConfigListenersHolder.getInstance().getUserStoreConfigListeners();
    for (UserStoreConfigListener userStoreConfigListener : userStoreConfigListeners) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Triggering userstore post get listener: %s for tenant: %s", userStoreConfigListener.getClass().getName(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
        }
        userStoreConfigListener.onUserStorePostGet(tenantId, userStoreDTO);
    }
}
Also used : UserStoreConfigListener(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)

Example 13 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class UserStoreHashProviderConfigListenerImpl method validateHashProviderParams.

/**
 * Derive the userStoreProperties from UserStoreDTO and Validating HashProvider params.
 *
 * @param userStoreDTO Data transfer object of userStore properties.
 * @throws UserStoreException The exception thrown at validating the hashProvider params.
 */
private void validateHashProviderParams(UserStoreDTO userStoreDTO) throws UserStoreException {
    PropertyDTO[] userStoreProperty = userStoreDTO.getProperties();
    String userstoreDomainId = userStoreDTO.getDomainId();
    String digestFunction = null;
    String hashProviderParamsJSON = null;
    if (ArrayUtils.isEmpty(userStoreProperty)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No userstore properties found for userstore: " + userstoreDomainId);
        }
        return;
    }
    for (PropertyDTO propertyDTO : userStoreProperty) {
        if (DIGEST_FUNCTION.equals(propertyDTO.getName())) {
            digestFunction = propertyDTO.getValue();
        }
        if (HASH_PROVIDER_PARAMS_JSON.equals(propertyDTO.getName())) {
            hashProviderParamsJSON = propertyDTO.getValue();
        }
    }
    if (StringUtils.isBlank(hashProviderParamsJSON)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No hash provider configurations found for: " + userstoreDomainId);
        }
        return;
    }
    // Retrieve the corresponding HashProviderFactory for the defined hashing function.
    HashProviderFactory hashProviderFactory = UserStoreConfigListenersHolder.getInstance().getHashProviderFactory(digestFunction);
    if (hashProviderFactory == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("No HashProviderFactory found digest function : %s for userstore: %s", digestFunction, userstoreDomainId));
        }
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("HashProviderFactory: %s found for digest function: %s for userstore: %s", hashProviderFactory.getAlgorithm(), digestFunction, userstoreDomainId));
    }
    Set<String> hashProviderMetaProperties = hashProviderFactory.getHashProviderConfigProperties();
    validateParams(hashProviderParamsJSON, hashProviderMetaProperties);
    Map<String, Object> hashProviderPropertiesMap = getHashProviderInitConfigs(hashProviderParamsJSON);
    try {
        hashProviderFactory.getHashProvider(hashProviderPropertiesMap);
    } catch (HashProviderException e) {
        throw new UserStoreException("Error occurred while initializing the hashProvider.", e);
    }
}
Also used : HashProviderException(org.wso2.carbon.user.core.exceptions.HashProviderException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) HashProviderFactory(org.wso2.carbon.user.core.hash.HashProviderFactory) JsonObject(com.google.gson.JsonObject) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Example 14 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project product-is by wso2.

the class OIDCPasswordGrantTest method addSecondaryUserStore.

private void addSecondaryUserStore() throws Exception {
    String jdbcClass = "org.wso2.carbon.user.core.jdbc.UniqueIDJDBCUserStoreManager";
    H2DataBaseManager dataBaseManager = new H2DataBaseManager("jdbc:h2:" + ServerConfigurationManager.getCarbonHome() + "/repository/database/" + USER_STORE_DB_NAME, DB_USER_NAME, DB_USER_PASSWORD);
    dataBaseManager.executeUpdate(new File(ServerConfigurationManager.getCarbonHome() + "/dbscripts/h2.sql"));
    dataBaseManager.disconnect();
    PropertyDTO[] propertyDTOs = new PropertyDTO[10];
    for (int i = 0; i < 10; i++) {
        propertyDTOs[i] = new PropertyDTO();
    }
    propertyDTOs[0].setName("driverName");
    propertyDTOs[0].setValue("org.h2.Driver");
    propertyDTOs[1].setName("url");
    propertyDTOs[1].setValue("jdbc:h2:" + ServerConfigurationManager.getCarbonHome() + "/repository/database/" + USER_STORE_DB_NAME);
    propertyDTOs[2].setName("userName");
    propertyDTOs[2].setValue(DB_USER_NAME);
    propertyDTOs[3].setName("password");
    propertyDTOs[3].setValue(DB_USER_PASSWORD);
    propertyDTOs[4].setName("UserIDEnabled");
    propertyDTOs[4].setValue("true");
    UserStoreDTO userStoreDTO = userStoreConfigAdminServiceClient.createUserStoreDTO(jdbcClass, USER_STORE_DOMAIN, propertyDTOs);
    userStoreConfigAdminServiceClient.addUserStore(userStoreDTO);
    Thread.sleep(5000);
    userStoreConfigUtils.waitForUserStoreDeployment(userStoreConfigAdminServiceClient, USER_STORE_DOMAIN);
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO) H2DataBaseManager(org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager) File(java.io.File) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO)

Example 15 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project product-is by wso2.

the class SCIMUtils method createSecondaryUserStore.

/**
 * Create a secondary user store.
 *
 * @param userStoreType       User store type.
 * @param userStoreDomain     User store domain.
 * @param userStoreProperties Configuration properties for the user store.
 * @param backendURL          Backend URL of the Identity Server.
 * @param sessionCookie       Session Cookie.
 * @throws Exception Thrown if the user store creation fails.
 */
public static void createSecondaryUserStore(String userStoreType, String userStoreDomain, PropertyDTO[] userStoreProperties, String backendURL, String sessionCookie) throws Exception {
    UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient = new UserStoreConfigAdminServiceClient(backendURL, sessionCookie);
    UserStoreDTO userStoreDTO = userStoreConfigAdminServiceClient.createUserStoreDTO(userStoreType, userStoreDomain, userStoreProperties);
    userStoreConfigAdminServiceClient.addUserStore(userStoreDTO);
    Thread.sleep(5000);
    Assert.assertTrue(userStoreConfigUtils.waitForUserStoreDeployment(userStoreConfigAdminServiceClient, userStoreDomain), "Domain addition via DTO has failed.");
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO) UserStoreConfigAdminServiceClient(org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient)

Aggregations

UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)21 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)14 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)13 UserStoreException (org.wso2.carbon.user.api.UserStoreException)11 ArrayList (java.util.ArrayList)9 AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)8 Test (org.testng.annotations.Test)7 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)7 UserStorePersistanceDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)6 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)6 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)5 File (java.io.File)4 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)4 UserStoreConfigListener (org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)4 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)4 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)4 H2DataBaseManager (org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager)3 MaskedProperty (org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)3 Property (org.wso2.carbon.user.api.Property)3