use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ResourceTest method delete.
@Test
public void delete() {
ExternalResource resource = resourceDAO.find("resource-testdb");
assertNotNull(resource);
// -------------------------------------
// Get originally associated connector
// -------------------------------------
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
// -------------------------------------
// -------------------------------------
// Get originally associated users
// -------------------------------------
List<User> users = userDAO.findByResource(resource);
assertNotNull(users);
Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
// -------------------------------------
// Get tasks
List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
assertFalse(propagationTasks.isEmpty());
// delete resource
resourceDAO.delete(resource.getKey());
// close the transaction
resourceDAO.flush();
// resource must be removed
ExternalResource actual = resourceDAO.find("resource-testdb");
assertNull(actual);
// resource must be not referenced any more from users
userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
assertNotNull(actualUser);
return actualUser;
}).forEachOrdered((actualUser) -> {
userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
});
// resource must be not referenced any more from the connector
ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
assertNotNull(actualConnector);
actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
// there must be no tasks
propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class DBPasswordPullActions method parseEncodedPassword.
private void parseEncodedPassword(final String password, final Connector connector) {
if (password != null) {
ConnInstance connInstance = connector.getConnInstance();
String cipherAlgorithm = getCipherAlgorithm(connInstance);
if (!CLEARTEXT.equals(cipherAlgorithm)) {
try {
encodedPassword = password;
cipher = CipherAlgorithm.valueOf(cipherAlgorithm);
} catch (IllegalArgumentException e) {
LOG.error("Cipher algorithm not allowed: {}", cipherAlgorithm, e);
encodedPassword = null;
}
}
}
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ConnInstanceDataBinderImpl method update.
@Override
public ConnInstance update(final ConnInstanceTO connInstanceTO) {
ConnInstance connInstance = connInstanceDAO.authFind(connInstanceTO.getKey());
if (connInstance == null) {
throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
}
ConnInstanceTO current = getConnInstanceTO(connInstance);
if (!current.equals(connInstanceTO)) {
// 1. save the current configuration, before update
ConnInstanceHistoryConf connInstanceHistoryConf = entityFactory.newEntity(ConnInstanceHistoryConf.class);
connInstanceHistoryConf.setCreator(AuthContextUtils.getUsername());
connInstanceHistoryConf.setCreation(new Date());
connInstanceHistoryConf.setEntity(connInstance);
connInstanceHistoryConf.setConf(current);
connInstanceHistoryConfDAO.save(connInstanceHistoryConf);
// 2. ensure the maximum history size is not exceeded
List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(connInstance);
long maxHistorySize = confDAO.find("connector.conf.history.size", 10L);
if (maxHistorySize < history.size()) {
// always remove the last item since history was obtained by a query with ORDER BY creation DESC
for (int i = 0; i < history.size() - maxHistorySize; i++) {
connInstanceHistoryConfDAO.delete(history.get(history.size() - 1).getKey());
}
}
}
// 3. actual update
connInstance.getCapabilities().clear();
connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities());
if (connInstanceTO.getAdminRealm() != null) {
Realm realm = realmDAO.findByFullPath(connInstanceTO.getAdminRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
throw sce;
}
connInstance.setAdminRealm(realm);
}
if (connInstanceTO.getLocation() != null) {
connInstance.setLocation(connInstanceTO.getLocation());
}
if (connInstanceTO.getBundleName() != null) {
connInstance.setBundleName(connInstanceTO.getBundleName());
}
if (connInstanceTO.getVersion() != null) {
connInstance.setVersion(connInstanceTO.getVersion());
}
if (connInstanceTO.getConnectorName() != null) {
connInstance.setConnectorName(connInstanceTO.getConnectorName());
}
if (connInstanceTO.getConf() != null && !connInstanceTO.getConf().isEmpty()) {
connInstance.setConf(connInstanceTO.getConf());
}
if (connInstanceTO.getDisplayName() != null) {
connInstance.setDisplayName(connInstanceTO.getDisplayName());
}
if (connInstanceTO.getConnRequestTimeout() != null) {
connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout());
}
if (connInstanceTO.getPoolConf() == null) {
connInstance.setPoolConf(null);
} else {
connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
}
try {
connInstance = connInstanceDAO.save(connInstance);
} catch (Exception e) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
sce.getElements().add(e.getMessage());
throw sce;
}
return connInstance;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ConnectorManager method buildConnInstanceOverride.
@Override
public ConnInstance buildConnInstanceOverride(final ConnInstanceTO connInstance, final Collection<ConnConfProperty> confOverride, final Collection<ConnectorCapability> capabilitiesOverride) {
synchronized (this) {
if (entityFactory == null) {
entityFactory = ApplicationContextProvider.getApplicationContext().getBean(EntityFactory.class);
}
}
ConnInstance override = entityFactory.newEntity(ConnInstance.class);
override.setAdminRealm(realmDAO.findByFullPath(connInstance.getAdminRealm()));
override.setConnectorName(connInstance.getConnectorName());
override.setDisplayName(connInstance.getDisplayName());
override.setBundleName(connInstance.getBundleName());
override.setVersion(connInstance.getVersion());
override.setLocation(connInstance.getLocation());
override.setConf(connInstance.getConf());
override.getCapabilities().addAll(connInstance.getCapabilities());
override.setConnRequestTimeout(connInstance.getConnRequestTimeout());
Map<String, ConnConfProperty> overridable = new HashMap<>();
Set<ConnConfProperty> conf = new HashSet<>();
for (ConnConfProperty prop : override.getConf()) {
if (prop.isOverridable()) {
overridable.put(prop.getSchema().getName(), prop);
} else {
conf.add(prop);
}
}
// add override properties
for (ConnConfProperty prop : confOverride) {
if (overridable.containsKey(prop.getSchema().getName()) && !prop.getValues().isEmpty()) {
conf.add(prop);
overridable.remove(prop.getSchema().getName());
}
}
// add override properties not substituted
conf.addAll(overridable.values());
override.setConf(conf);
// replace capabilities
if (capabilitiesOverride != null) {
override.getCapabilities().clear();
override.getCapabilities().addAll(capabilitiesOverride);
}
return override;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ResourceLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_CREATE + "')")
public ResourceTO create(final ResourceTO resourceTO) {
if (StringUtils.isBlank(resourceTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add("Resource key");
throw sce;
}
ConnInstance connInstance = connInstanceDAO.authFind(resourceTO.getConnector());
if (connInstance == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidExternalResource);
sce.getElements().add("Connector " + resourceTO.getConnector());
throw sce;
}
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_CREATE), connInstance.getAdminRealm().getFullPath());
securityChecks(effectiveRealms, connInstance.getAdminRealm().getFullPath(), null);
if (resourceDAO.authFind(resourceTO.getKey()) != null) {
throw new DuplicateException(resourceTO.getKey());
}
return binder.getResourceTO(resourceDAO.save(binder.create(resourceTO)));
}
Aggregations