Search in sources :

Example 46 with UserStoreDTO

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

the class IDENTITY4776SCIMServiceWithOAuthTestCase method addSecondaryUserStore.

private void addSecondaryUserStore() throws Exception {
    String jdbcClass = "org.wso2.carbon.user.core.jdbc.UniqueIDJDBCUserStoreManager";
    H2DataBaseManager dbmanager = new H2DataBaseManager("jdbc:h2:" + Utils.getResidentCarbonHome() + "/repository/database/" + USER_STORE_DB_NAME, DB_USER_NAME, DB_USER_PASSWORD);
    dbmanager.executeUpdate(new File(Utils.getResidentCarbonHome() + "/dbscripts/h2.sql"));
    dbmanager.disconnect();
    PropertyDTO[] propertyDTOs = new PropertyDTO[11];
    for (int i = 0; i < 11; i++) {
        propertyDTOs[i] = new PropertyDTO();
    }
    propertyDTOs[0].setName("driverName");
    propertyDTOs[0].setValue("org.h2.Driver");
    propertyDTOs[1].setName("url");
    propertyDTOs[1].setValue("jdbc:h2:./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("PasswordJavaRegEx");
    propertyDTOs[4].setValue("^[\\S]{5,30}$");
    propertyDTOs[5].setName("UsernameJavaRegEx");
    propertyDTOs[5].setValue("^[\\S]{5,30}$");
    propertyDTOs[6].setName("Disabled");
    propertyDTOs[6].setValue("false");
    propertyDTOs[7].setName("PasswordDigest");
    propertyDTOs[7].setValue("SHA-256");
    propertyDTOs[8].setName("StoreSaltedPassword");
    propertyDTOs[8].setValue("true");
    propertyDTOs[9].setName("SCIMEnabled");
    propertyDTOs[9].setValue("true");
    propertyDTOs[10].setName("UserIDEnabled");
    propertyDTOs[10].setValue("true");
    UserStoreDTO userStoreDTO = userStoreConfigAdminServiceClient.createUserStoreDTO(jdbcClass, DOMAIN_ID, propertyDTOs);
    userStoreConfigAdminServiceClient.addUserStore(userStoreDTO);
    Thread.sleep(5000);
    userStoreConfigUtils.waitForUserStoreDeployment(userStoreConfigAdminServiceClient, DOMAIN_ID);
}
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 47 with UserStoreDTO

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

the class UserStoreConfigUtils method waitForUserStoreDeployment.

public boolean waitForUserStoreDeployment(UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient, String domain) throws Exception {
    // wait for 45 seconds
    long waitTime = System.currentTimeMillis() + 30000;
    while (System.currentTimeMillis() < waitTime) {
        UserStoreDTO[] userStoreDTOs = userStoreConfigAdminServiceClient.getActiveDomains();
        if (userStoreDTOs != null) {
            for (UserStoreDTO userStoreDTO : userStoreDTOs) {
                if (userStoreDTO != null) {
                    if (userStoreDTO.getDomainId().equalsIgnoreCase(domain)) {
                        return true;
                    }
                }
            }
        }
        Thread.sleep(500);
    }
    return false;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)

Example 48 with UserStoreDTO

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

the class UserStoreConfigUtils method waitForUserStoreUnDeployment.

public boolean waitForUserStoreUnDeployment(UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient, String domain) throws Exception {
    // wait for 15 seconds
    long waitTime = System.currentTimeMillis() + 20000;
    while (System.currentTimeMillis() < waitTime) {
        UserStoreDTO[] userStoreDTOs = userStoreConfigAdminServiceClient.getActiveDomains();
        userStoreConfigAdminServiceClient.getActiveDomains();
        if (userStoreDTOs != null) {
            for (UserStoreDTO userStoreDTO : userStoreDTOs) {
                if (userStoreDTO != null && userStoreDTO.getDomainId() != null) {
                    if (userStoreDTO.getDomainId().equalsIgnoreCase(domain)) {
                        Thread.sleep(500);
                    }
                }
            }
        }
    }
    return true;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)

Example 49 with UserStoreDTO

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

the class ServerUserStoreService method buildUserStoreListResponse.

/**
 * Construct response list with configured user stores details.
 *
 * @param userStoreDTOS array of UserStoreDTO object.
 * @return List<UserStoreListResponse>.
 */
private List<UserStoreListResponse> buildUserStoreListResponse(UserStoreDTO[] userStoreDTOS, String requiredAttributes) {
    List<UserStoreListResponse> userStoreListResponseToAdd = new ArrayList<>();
    Map<String, Boolean> userStoreManagersType = UserStoreManagerRegistry.getUserStoreManagersType();
    if (ArrayUtils.isNotEmpty(userStoreDTOS)) {
        for (UserStoreDTO jsonObject : userStoreDTOS) {
            UserStoreListResponse userStoreList = new UserStoreListResponse();
            userStoreList.setDescription(jsonObject.getDescription());
            userStoreList.setName(jsonObject.getDomainId());
            userStoreList.setId(base64URLEncodeId(jsonObject.getDomainId()));
            userStoreList.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + UserStoreConstants.USER_STORE_PATH_COMPONENT + "/%s", base64URLEncodeId(jsonObject.getDomainId()))).toString());
            userStoreList.setEnabled(jsonObject.getDisabled() != null && !jsonObject.getDisabled());
            userStoreList.setTypeName(getUserStoreTypeName(jsonObject.getClassName()));
            if (StringUtils.isNotBlank(requiredAttributes)) {
                String[] requiredAttributesArray = requiredAttributes.split(REGEX_COMMA);
                addUserstoreProperties(jsonObject, userStoreList, Arrays.asList(requiredAttributesArray));
            }
            if (userStoreManagersType.containsKey(jsonObject.getClassName())) {
                userStoreList.setIsLocal(userStoreManagersType.get(jsonObject.getClassName()));
            }
            userStoreListResponseToAdd.add(userStoreList);
        }
    }
    return userStoreListResponseToAdd;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreListResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)

Example 50 with UserStoreDTO

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

the class ServerUserStoreService method buildUserStoreForPatch.

private UserStoreDTO buildUserStoreForPatch(String domainId, List<PatchDocument> patchDocuments) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    UserStoreDTO userStoreDTO;
    try {
        userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
        PropertyDTO[] propertyDTOS = userStoreDTO.getProperties();
        for (PatchDocument patchDocument : patchDocuments) {
            String path = patchDocument.getPath();
            String value = patchDocument.getValue();
            if (StringUtils.isBlank(path)) {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
            if (path.startsWith(UserStoreConstants.USER_STORE_PROPERTIES)) {
                String propName = extractPropertyName(path);
                if (StringUtils.isNotEmpty(propName)) {
                    for (PropertyDTO propertyDTO : propertyDTOS) {
                        if (propName.equals(propertyDTO.getName())) {
                            propertyDTO.setValue(value);
                        }
                    }
                }
            } else if (path.equals(UserStoreConstants.USER_STORE_DESCRIPTION)) {
                userStoreDTO.setDescription(value);
            } else {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
        }
        userStoreDTO.setProperties(propertyDTOS);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
    return userStoreDTO;
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO) PatchDocument(org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument)

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