Search in sources :

Example 11 with UserStorePersistanceDTO

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

the class DatabaseBasedUserStoreDAOImpl method doAddUserStore.

@Override
protected void doAddUserStore(UserStorePersistanceDTO userStorePersistanceDTO) throws IdentityUserStoreMgtException {
    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    try {
        // Run pre user-store add listeners.
        triggerListenersOnUserStorePreAdd(domainName);
        boolean isValidDomain = xmlProcessorUtils.isValidDomain(domainName, true);
        validateForFederatedDomain(domainName);
        if (isValidDomain) {
            addUserStoreProperties(userStorePersistanceDTO.getUserStoreProperties(), domainName);
            addRealmToSecondaryUserStoreManager(userStorePersistanceDTO);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("The user store domain: " + domainName + "is not a valid domain name.");
            }
        }
    } catch (UserStoreException | XMLStreamException e) {
        throw new IdentityUserStoreMgtException("Error occured while adding the user store with the domain: " + domainName, e);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) XMLStreamException(javax.xml.stream.XMLStreamException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 12 with UserStorePersistanceDTO

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

the class FileBasedUserStoreDAOImpl method doUpdateUserStore.

@Override
protected void doUpdateUserStore(UserStorePersistanceDTO userStorePersistanceDTO, boolean isStateChange) throws IdentityUserStoreMgtException {
    boolean isValidDomain;
    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    try {
        validateForFederatedDomain(domainName);
        isValidDomain = isDomainNameExists(domainName);
    } catch (UserStoreException e) {
        throw new IdentityUserStoreClientException("Error while updating the user store.", e);
    }
    if (isValidDomain) {
        Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
        if (!Files.exists(userStoreConfigFile)) {
            throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), true);
        }
        writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(), true, isStateChange, domainName);
    } else {
        String errorMessage = "Trying to edit an invalid domain : " + domainName;
        throw new IdentityUserStoreClientException(errorMessage);
    }
}
Also used : Path(java.nio.file.Path) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)

Example 13 with UserStorePersistanceDTO

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

the class FileBasedUserStoreDAOImpl method doGetAllUserStores.

@Override
protected UserStorePersistanceDTO[] doGetAllUserStores() throws IdentityUserStoreMgtException {
    RealmConfiguration secondaryRealmConfiguration;
    List<UserStorePersistanceDTO> userStorePersistanceDAOList = new ArrayList<>();
    UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStorePersistanceDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration, userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
            userStorePersistanceDAOList.add(userStorePersistanceDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
        } while (secondaryRealmConfiguration != null);
    }
    return userStorePersistanceDAOList.toArray(new UserStorePersistanceDTO[userStorePersistanceDAOList.size()]);
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStorePersistanceDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)

Example 14 with UserStorePersistanceDTO

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

the class FileBasedUserStoreDAOImpl method doUpdateUserStoreDomainName.

@Override
protected void doUpdateUserStoreDomainName(String previousDomainName, UserStorePersistanceDTO userStorePersistanceDTO) throws IdentityUserStoreMgtException {
    Path userStoreConfigFile;
    Path previousUserStoreConfigFile;
    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    String fileName = domainName.replace(".", "_");
    String previousFileName = previousDomainName.replace(".", "_");
    validateFileName(domainName, fileName);
    validateFileName(previousDomainName, previousFileName);
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
        createUserStoreDirectory(null, fileName, false);
        userStoreConfigFile = Paths.get(DEPLOYMENT_DIRECTORY, fileName + FILE_EXTENSION_XML);
        previousUserStoreConfigFile = Paths.get(DEPLOYMENT_DIRECTORY, previousFileName + FILE_EXTENSION_XML);
    } else {
        String tenantFilePath = CarbonUtils.getCarbonTenantsDirPath();
        createUserStoreDirectory(tenantFilePath, fileName, true);
        userStoreConfigFile = Paths.get(tenantFilePath, String.valueOf(tenantId), USERSTORES, fileName + FILE_EXTENSION_XML);
        previousUserStoreConfigFile = Paths.get(tenantFilePath, String.valueOf(tenantId), USERSTORES, previousFileName + FILE_EXTENSION_XML);
    }
    if (!Files.exists(previousUserStoreConfigFile)) {
        String errorMessage = "Cannot update user store domain name. Previous domain name " + previousDomainName + " does not exists.";
        throw new IdentityUserStoreClientException(UserStoreConfigurationConstant.ErrorMessage.ERROR_CODE_XML_FILE_NOT_FOUND.getCode(), errorMessage);
    }
    if (Files.exists(userStoreConfigFile)) {
        String errorMessage = "Cannot update user store domain name. An user store already exists with new domain" + " " + domainName + ".";
        throw new IdentityUserStoreClientException(UserStoreConfigurationConstant.ErrorMessage.ERROR_CODE_XML_FILE_ALREADY_EXISTS.getCode(), errorMessage);
    }
    try {
        // Run pre user-store name update listeners
        triggerListnersOnUserStorePreUpdate(previousDomainName, domainName);
        // Update persisted domain name
        updatePersistedDomainName(previousDomainName, domainName, tenantId);
        // Run post userstore name update listeners.
        triggerListenersOnUserStorePostUpdate(previousDomainName, domainName);
    } catch (UserStoreClientException e) {
        throw buildIdentityUserStoreClientException("Userstore " + domainName + " cannot be updated.", e);
    } catch (UserStoreException e) {
        String errorMessage = "Error while updating user store domain : " + domainName;
        log.error(errorMessage, e);
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    try {
        Files.delete(previousUserStoreConfigFile);
        writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(), true, false, previousDomainName);
    } catch (IOException e) {
        log.info("Error when deleting previous configuration files " + previousUserStoreConfigFile);
    }
}
Also used : Path(java.nio.file.Path) IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException) UserStoreClientException(org.wso2.carbon.user.api.UserStoreClientException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IOException(java.io.IOException)

Example 15 with UserStorePersistanceDTO

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

the class AbstractUserStoreDAO method updateUserStoreDomainName.

@Override
public void updateUserStoreDomainName(String previousDomainName, UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {
    UserStorePersistanceDTO userStorePersistanceDTO = getUserStorePersistanceDTO(userStoreDTO, getUserStoreProperties(userStoreDTO, previousDomainName));
    doUpdateUserStoreDomainName(previousDomainName, userStorePersistanceDTO);
}
Also used : UserStorePersistanceDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)

Aggregations

UserStorePersistanceDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)9 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)8 XMLStreamException (javax.xml.stream.XMLStreamException)5 IOException (java.io.IOException)4 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)4 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Path (java.nio.file.Path)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)3 ResultSet (java.sql.ResultSet)2 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)2 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)2 MaskedProperty (org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)1 UserRealm (org.wso2.carbon.user.core.UserRealm)1