use of org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO in project carbon-identity-framework by wso2.
the class DatabaseBasedUserStoreDAOImpl method doGetUserStore.
@Override
protected UserStorePersistanceDTO doGetUserStore(String domainName) throws IdentityUserStoreMgtException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
InputStream scriptBinaryStream = null;
InputStream clonedStream = null;
String userStoreProperties = null;
UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement prepStmt = connection.prepareStatement(UserStoreMgtDBQueries.GET_USERSTORE_PROPERTIES)) {
prepStmt.setString(1, domainName);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, USERSTORE);
try (ResultSet rSet = prepStmt.executeQuery()) {
if (rSet.next()) {
RealmConfiguration realmConfiguration = null;
scriptBinaryStream = rSet.getBinaryStream(1);
clonedStream = rSet.getBinaryStream(1);
if (scriptBinaryStream != null) {
realmConfiguration = getRealmConfiguration(domainName, scriptBinaryStream);
}
if (clonedStream != null) {
userStoreProperties = IOUtils.toString(clonedStream);
}
userStorePersistanceDTO.setUserStoreProperties(userStoreProperties);
if (realmConfiguration != null) {
userStorePersistanceDTO.setUserStoreDTO(getUserStoreDTO(realmConfiguration));
}
} else {
if (log.isDebugEnabled()) {
log.debug("No user store properties found for domain: " + domainName + " in tenant: " + tenantId);
}
}
} catch (IOException | UserStoreException | XMLStreamException e) {
throw new IdentityUserStoreMgtException("Error occured while getting user store properties for " + "domain:" + domainName + " in tenant:" + tenantId, e);
} finally {
try {
if (scriptBinaryStream != null) {
scriptBinaryStream.close();
}
if (clonedStream != null) {
clonedStream.close();
}
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new IdentityUserStoreMgtException("Error occured while loading user stores.", e);
}
}
} catch (SQLException e) {
throw new IdentityUserStoreMgtException("Could not read the user store properties for the domain:" + domainName + " in tenant:" + tenantId, e);
}
return userStorePersistanceDTO;
}
use of org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO in project carbon-identity-framework by wso2.
the class DatabaseBasedUserStoreDAOImpl method doGetAllUserStores.
@Override
protected UserStorePersistanceDTO[] doGetAllUserStores() throws IdentityUserStoreMgtException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
List<UserStorePersistanceDTO> userStorePersistanceDTOs = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement prepStmt = connection.prepareStatement(GET_ALL_USERSTORE_PROPERTIES)) {
prepStmt.setInt(1, tenantId);
prepStmt.setString(2, USERSTORE);
try (ResultSet rSet = prepStmt.executeQuery()) {
while (rSet.next()) {
String identifier = rSet.getString(1);
InputStream scriptBinaryStream = null;
InputStream clonedStream = null;
String userStorePropertyValues = null;
try {
scriptBinaryStream = rSet.getBinaryStream(2);
clonedStream = rSet.getBinaryStream(2);
RealmConfiguration realmConfiguration = null;
if (scriptBinaryStream != null) {
realmConfiguration = getRealmConfiguration(identifier, scriptBinaryStream);
}
if (clonedStream != null) {
userStorePropertyValues = IOUtils.toString(clonedStream);
}
getUserStorePersistanceDTOs(userStorePersistanceDTOs, realmConfiguration, userStorePropertyValues);
} finally {
if (scriptBinaryStream != null) {
scriptBinaryStream.close();
}
if (clonedStream != null) {
clonedStream.close();
}
}
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new IdentityUserStoreMgtException("Error occured while listing user stores in tenant: " + tenantId, e);
} catch (XMLStreamException | IOException e) {
throw new IdentityUserStoreMgtException("Could not read the user store properties in tenant:" + tenantId, e);
}
} catch (SQLException e) {
throw new IdentityUserStoreMgtException("Could not read the user store properties in tenant:" + tenantId, e);
}
return userStorePersistanceDTOs.toArray(new UserStorePersistanceDTO[userStorePersistanceDTOs.size()]);
}
use of org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO in project carbon-identity-framework by wso2.
the class DatabaseBasedUserStoreDAOImpl method doUpdateUserStoreDomainName.
@Override
protected void doUpdateUserStoreDomainName(String domainName, UserStorePersistanceDTO userStorePersistanceDTO) throws IdentityUserStoreMgtException {
try {
String newDomainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
triggerListnersOnUserStorePreUpdate(domainName, newDomainName);
updateUserStoreProperties(domainName, userStorePersistanceDTO);
removeRealmFromSecondaryUserStoreManager(domainName);
addRealmToSecondaryUserStoreManager(userStorePersistanceDTO);
triggerListenersOnUserStorePostUpdate(domainName, newDomainName);
} catch (UserStoreClientException e) {
throw buildIdentityUserStoreClientException("Userstore " + domainName + " cannot be updated.", e);
} catch (UserStoreException | XMLStreamException e) {
throw new IdentityUserStoreMgtException("Error occured while updating the userstore.", e);
}
}
use of org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO in project carbon-identity-framework by wso2.
the class DatabaseBasedUserStoreDAOImpl method updateUserStoreProperties.
private void updateUserStoreProperties(String domainName, UserStorePersistanceDTO userStorePersistanceDTO) throws IdentityUserStoreMgtException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String msg = "Error occured while updating user store properties for the domain:" + domainName + "in the " + "tenant:" + tenantId;
try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
try (PreparedStatement pst = connection.prepareStatement(UserStoreMgtDBQueries.UPDATE_USERSTORE_PROPERTIES)) {
setBlobValue(userStorePersistanceDTO.getUserStoreProperties(), pst, 1);
pst.setString(2, userStorePersistanceDTO.getUserStoreDTO().getDomainId());
pst.setString(3, domainName);
pst.setInt(4, tenantId);
pst.setString(5, USERSTORE);
pst.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug("The userstore domain:" + domainName + "updated for the tenant:" + tenantId);
}
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new IdentityUserStoreMgtException(msg, e);
} catch (IOException ex) {
throw new IdentityUserStoreMgtException(msg, ex);
}
} catch (SQLException e) {
throw new IdentityUserStoreMgtException(msg);
}
}
use of org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO in project carbon-identity-framework by wso2.
the class FileBasedUserStoreDAOImpl 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 validDomain = isValidDomainToAdd(domainName);
validateForFederatedDomain(domainName);
if (validDomain) {
Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
if (Files.exists(userStoreConfigFile)) {
throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), false);
}
writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(), false, false, domainName);
} else {
if (log.isDebugEnabled()) {
log.debug("The user store domain: " + domainName + "is not a valid domain name.");
}
}
} catch (UserStoreException e) {
throw new IdentityUserStoreClientException("Error occurred while adding the user store with the domain: " + domainName, e);
}
}
Aggregations