use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class JPAConnInstanceDAO method save.
@Override
public ConnInstance save(final ConnInstance connector) {
final ConnInstance merged = entityManager().merge(connector);
merged.getResources().forEach(resource -> {
try {
connRegistry.registerConnector(resource);
} catch (NotFoundException e) {
LOG.error("While registering connector for resource", e);
}
});
return merged;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class LDAPPasswordPropagationActions method before.
@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
if (AnyTypeKind.USER == task.getAnyTypeKind()) {
User user = userDAO.find(task.getEntityKey());
if (user != null && user.getPassword() != null) {
Attribute missing = AttributeUtil.find(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, task.getAttributes());
ConnInstance connInstance = task.getResource().getConnector();
String cipherAlgorithm = getCipherAlgorithm(connInstance);
if (missing != null && missing.getValue() != null && missing.getValue().size() == 1 && missing.getValue().get(0).equals(OperationalAttributes.PASSWORD_NAME) && cipherAlgorithmMatches(getCipherAlgorithm(connInstance), user.getCipherAlgorithm())) {
String password = user.getPassword().toLowerCase();
byte[] decodedPassword = DatatypeConverter.parseHexBinary(password);
String base64EncodedPassword = Base64.getEncoder().encodeToString(decodedPassword);
String cipherPlusPassword = ("{" + cipherAlgorithm.toLowerCase() + "}" + base64EncodedPassword);
Attribute passwordAttribute = AttributeBuilder.buildPassword(new GuardedString(cipherPlusPassword.toCharArray()));
Set<Attribute> attributes = new HashSet<>(task.getAttributes());
attributes.add(passwordAttribute);
attributes.remove(missing);
task.setAttributes(attributes);
}
}
}
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ConnectorManager method registerConnector.
@Override
public void registerConnector(final ExternalResource resource) {
ConnInstance connInstance = buildConnInstanceOverride(connInstanceDataBinder.getConnInstanceTO(resource.getConnector()), resource.getConfOverride(), resource.isOverrideCapabilities() ? resource.getCapabilitiesOverride() : null);
Connector connector = createConnector(connInstance);
LOG.debug("Connector to be registered: {}", connector);
String beanName = getBeanName(resource);
if (ApplicationContextProvider.getBeanFactory().containsSingleton(beanName)) {
unregisterConnector(beanName);
}
ApplicationContextProvider.getBeanFactory().registerSingleton(beanName, connector);
LOG.debug("Successfully registered bean {}", beanName);
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ConnInstanceDataBinderImpl method getConnInstance.
@Override
public ConnInstance getConnInstance(final ConnInstanceTO connInstanceTO) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
if (connInstanceTO.getLocation() == null) {
sce.getElements().add("location");
}
if (connInstanceTO.getBundleName() == null) {
sce.getElements().add("bundlename");
}
if (connInstanceTO.getVersion() == null) {
sce.getElements().add("bundleversion");
}
if (connInstanceTO.getConnectorName() == null) {
sce.getElements().add("connectorname");
}
if (connInstanceTO.getConf().isEmpty()) {
sce.getElements().add("configuration");
}
ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
BeanUtils.copyProperties(connInstanceTO, connInstance, IGNORE_PROPERTIES);
if (connInstanceTO.getAdminRealm() != null) {
connInstance.setAdminRealm(realmDAO.findByFullPath(connInstanceTO.getAdminRealm()));
}
if (connInstance.getAdminRealm() == null) {
sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
}
if (connInstanceTO.getLocation() != null) {
connInstance.setLocation(connInstanceTO.getLocation());
}
connInstance.setConf(connInstanceTO.getConf());
if (connInstanceTO.getPoolConf() != null) {
connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
}
// Throw exception if there is at least one element set
if (!sce.isEmpty()) {
throw sce;
}
return connInstance;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ResourceDataBinderImpl method getResourceTO.
@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
ResourceTO resourceTO = new ResourceTO();
// set the resource name
resourceTO.setKey(resource.getKey());
// set the connector instance
ConnInstance connector = resource.getConnector();
resourceTO.setConnector(connector == null ? null : connector.getKey());
resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
// set the provision information
resource.getProvisions().stream().map(provision -> {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setKey(provision.getKey());
provisionTO.setAnyType(provision.getAnyType().getKey());
provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
provisionTO.setSyncToken(provision.getSerializedSyncToken());
if (provision.getMapping() != null) {
MappingTO mappingTO = new MappingTO();
provisionTO.setMapping(mappingTO);
mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
populateItems(provision.getMapping().getItems(), mappingTO);
}
virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
provisionTO.getVirSchemas().add(virSchema.getKey());
MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
ItemTO itemTO = new ItemTO();
itemTO.setKey(linkingMappingItem.getKey());
BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
provisionTO.getMapping().getLinkingItems().add(itemTO);
});
return provisionTO;
}).forEachOrdered(provisionTO -> {
resourceTO.getProvisions().add(provisionTO);
});
if (resource.getOrgUnit() != null) {
OrgUnit orgUnit = resource.getOrgUnit();
OrgUnitTO orgUnitTO = new OrgUnitTO();
orgUnitTO.setKey(orgUnit.getKey());
orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
populateItems(orgUnit.getItems(), orgUnitTO);
resourceTO.setOrgUnit(orgUnitTO);
}
resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
resourceTO.setPropagationPriority(resource.getPropagationPriority());
resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
resourceTO.getConfOverride().addAll(resource.getConfOverride());
Collections.sort(resourceTO.getConfOverride());
resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
return resourceTO;
}
Aggregations