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);
}
}
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);
}
}
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()]);
}
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);
}
}
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);
}
Aggregations