Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public List<ConnIdBundle> getBundles(final String lang) {
}

List<ConnIdBundle> connectorBundleTOs = new ArrayList<>();
connIdBundleManager.getConnInfoManagers().forEach((uri, cim) -> connectorBundleTOs.addAll(
connIdBundleManager.getConnectorInfoManagers().forEach((uri, cim) -> connectorBundleTOs.addAll(
cim.getConnectorInfos().stream().map(bundle -> {
ConnIdBundle connBundleTO = new ConnIdBundle();
connBundleTO.setDisplayName(bundle.getConnectorDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.syncope.core.provisioning.java.pushpull.InboundMatcher;
import org.apache.syncope.core.provisioning.java.pushpull.OutboundMatcher;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -85,7 +86,8 @@ public ReconciliationLogic reconciliationLogic(
final ConnectorManager connectorManager,
final InboundMatcher inboundMatcher,
final OutboundMatcher outboundMatcher,
final MappingManager mappingManager) {
final MappingManager mappingManager,
final ConfigurableApplicationContext ctx) {

return new ReconciliationLogic(
anyUtilsFactory,
Expand All @@ -98,7 +100,8 @@ public ReconciliationLogic reconciliationLogic(
mappingManager,
inboundMatcher,
outboundMatcher,
connectorManager);
connectorManager,
ctx);
}

@ConditionalOnMissingBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.syncope.common.rest.api.beans.AbstractCSVSpec;
import org.apache.syncope.common.rest.api.beans.CSVPullSpec;
import org.apache.syncope.common.rest.api.beans.CSVPushSpec;
import org.apache.syncope.core.persistence.api.ApplicationContextProvider;
import org.apache.syncope.core.logic.AbstractTransactionalLogic.ProvisioningInfo;
import org.apache.syncope.core.persistence.api.dao.AnyDAO;
import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
Expand Down Expand Up @@ -101,12 +101,13 @@
import org.identityconnectors.framework.common.objects.Uid;
import org.identityconnectors.framework.common.objects.filter.Filter;
import org.identityconnectors.framework.spi.SearchResultsHandler;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;

public class ReconciliationLogic extends AbstractTransactionalLogic<EntityTO> {
public class ReconciliationLogic extends AbstractLogic<EntityTO> {

protected final AnyUtilsFactory anyUtilsFactory;

Expand All @@ -130,6 +131,8 @@ public class ReconciliationLogic extends AbstractTransactionalLogic<EntityTO> {

protected final ConnectorManager connectorManager;

protected final ConfigurableApplicationContext ctx;

public ReconciliationLogic(
final AnyUtilsFactory anyUtilsFactory,
final AnyTypeDAO anyTypeDAO,
Expand All @@ -141,7 +144,8 @@ public ReconciliationLogic(
final MappingManager mappingManager,
final InboundMatcher inboundMatcher,
final OutboundMatcher outboundMatcher,
final ConnectorManager connectorManager) {
final ConnectorManager connectorManager,
final ConfigurableApplicationContext ctx) {

this.anyUtilsFactory = anyUtilsFactory;
this.anyTypeDAO = anyTypeDAO;
Expand All @@ -154,6 +158,7 @@ public ReconciliationLogic(
this.inboundMatcher = inboundMatcher;
this.outboundMatcher = outboundMatcher;
this.connectorManager = connectorManager;
this.ctx = ctx;
}

protected ProvisioningInfo getProvisioningInfo(final String anyTypeKey, final String resourceKey) {
Expand Down Expand Up @@ -240,6 +245,7 @@ protected Any getAny(final Provision provision, final AnyTypeKind anyTypeKind, f
}

@PreAuthorize("hasRole('" + IdMEntitlement.RESOURCE_GET_CONNOBJECT + "')")
@Transactional(readOnly = true)
public ReconStatus status(
final String anyTypeKey,
final String resourceKey,
Expand Down Expand Up @@ -314,6 +320,7 @@ public void handleResult(final SearchResult sr) {
}

@PreAuthorize("hasRole('" + IdMEntitlement.RESOURCE_GET_CONNOBJECT + "')")
@Transactional(readOnly = true)
public ReconStatus status(
final String anyTypeKey,
final String resourceKey,
Expand Down Expand Up @@ -362,10 +369,11 @@ public ReconStatus status(
}

protected SyncopeSinglePushExecutor singlePushExecutor() {
return ApplicationContextProvider.getBeanFactory().createBean(SinglePushJobDelegate.class);
return ctx.getBeanFactory().createBean(SinglePushJobDelegate.class);
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(readOnly = true)
public List<ProvisioningReport> push(
final String anyTypeKey,
final String resourceKey,
Expand All @@ -388,6 +396,7 @@ public List<ProvisioningReport> push(
sce.getElements().add(results.getFirst().getMessage());
}
} catch (JobExecutionException e) {
LOG.error("Could not perform single push", e);
sce.getElements().add(e.getMessage());
}

Expand All @@ -399,6 +408,7 @@ public List<ProvisioningReport> push(
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(readOnly = true)
public List<ProvisioningReport> push(
final String anyTypeKey,
final String resourceKey,
Expand Down Expand Up @@ -448,6 +458,7 @@ public List<ProvisioningReport> push(
}
}
} catch (JobExecutionException e) {
LOG.error("Could not perform single push", e);
sce.getElements().add(e.getMessage());
}
});
Expand All @@ -467,16 +478,17 @@ protected List<ProvisioningReport> pull(
final Set<String> moreAttrsToGet,
final PullTaskTO pullTask) {

if (pullTask.getDestinationRealm() == null || realmSearchDAO.findByFullPath(pullTask.getDestinationRealm())
== null) {
if (pullTask.getDestinationRealm() == null
|| realmSearchDAO.findByFullPath(pullTask.getDestinationRealm()).isEmpty()) {

throw new NotFoundException("Realm " + pullTask.getDestinationRealm());
}

SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Reconciliation);
List<ProvisioningReport> results = new ArrayList<>();
try {
SyncopeSinglePullExecutor executor =
ApplicationContextProvider.getBeanFactory().createBean(SinglePullJobDelegate.class);
ctx.getBeanFactory().createBean(SinglePullJobDelegate.class);

results.addAll(executor.pull(
resource,
Expand All @@ -490,6 +502,7 @@ protected List<ProvisioningReport> pull(
sce.getElements().add(results.getFirst().getMessage());
}
} catch (JobExecutionException e) {
LOG.error("Could not perform single pull", e);
sce.getElements().add(e.getMessage());
}

Expand All @@ -501,7 +514,6 @@ protected List<ProvisioningReport> pull(
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(noRollbackFor = SyncopeClientException.class)
public List<ProvisioningReport> pull(
final String anyTypeKey,
final String resourceKey,
Expand Down Expand Up @@ -534,7 +546,6 @@ public List<ProvisioningReport> pull(
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(noRollbackFor = SyncopeClientException.class)
public List<ProvisioningReport> pull(
final String anyTypeKey,
final String resourceKey,
Expand Down Expand Up @@ -567,6 +578,7 @@ protected CsvSchema.Builder csvSchema(final AbstractCSVSpec spec) {
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(readOnly = true)
public List<ProvisioningReport> push(
final SearchCond searchCond,
final Pageable pageable,
Expand Down Expand Up @@ -650,7 +662,7 @@ public List<ProvisioningReport> push(
columns.toArray(String[]::new))) {

SyncopeStreamPushExecutor executor =
ApplicationContextProvider.getBeanFactory().createBean(StreamPushJobDelegate.class);
ctx.getBeanFactory().createBean(StreamPushJobDelegate.class);
return executor.push(
anyType,
matching,
Expand All @@ -668,7 +680,6 @@ public List<ProvisioningReport> push(
}

@PreAuthorize("hasRole('" + IdRepoEntitlement.TASK_EXECUTE + "')")
@Transactional(noRollbackFor = SyncopeClientException.class)
public List<ProvisioningReport> pull(final CSVPullSpec spec, final InputStream csv) {
AnyType anyType = anyTypeDAO.findById(spec.getAnyTypeKey()).
orElseThrow(() -> new NotFoundException("AnyType " + spec.getAnyTypeKey()));
Expand Down Expand Up @@ -697,8 +708,9 @@ public List<ProvisioningReport> pull(final CSVPullSpec spec, final InputStream c
}

SyncopeStreamPullExecutor executor =
ApplicationContextProvider.getBeanFactory().createBean(StreamPullJobDelegate.class);
return executor.pull(anyType,
ctx.getBeanFactory().createBean(StreamPullJobDelegate.class);
return executor.pull(
anyType,
spec.getKeyColumn(),
columns,
spec.getConflictResolutionAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ public ResourceTO create(final ResourceTO resourceTO) {
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;
}
ConnInstance connInstance = Optional.ofNullable(connInstanceDAO.authFind(resourceTO.getConnector())).
orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(
ClientExceptionType.InvalidExternalResource);
sce.getElements().add("Connector " + resourceTO.getConnector());
return sce;
});

Set<String> effectiveRealms = RealmUtils.getEffective(
AuthContextUtils.getAuthorizations().get(IdMEntitlement.RESOURCE_CREATE),
Expand Down Expand Up @@ -169,14 +170,7 @@ public void setLatestSyncToken(final String key, final String anyTypeKey) {
ExternalResource resource = Optional.ofNullable(resourceDAO.authFind(key)).
orElseThrow(() -> new NotFoundException("Resource '" + key + '\''));

Connector connector;
try {
connector = connectorManager.getConnector(resource);
} catch (Exception e) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
sce.getElements().add(e.getMessage());
throw sce;
}
Connector connector = connectorManager.getConnector(resource);

if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
if (resource.getOrgUnit() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public AccessTokenLogic(
this.accessTokenDAO = accessTokenDAO;
}

protected byte[] getAuthorities() {
byte[] authorities = null;
protected String getAuthorities() {
String authorities = null;
try {
authorities = encryptorManager.getInstance().
encode(POJOHelper.serialize(AuthContextUtils.getAuthorities()), CipherAlgorithm.AES).getBytes();
encode(POJOHelper.serialize(AuthContextUtils.getAuthorities()), CipherAlgorithm.AES);
} catch (Exception e) {
LOG.error("Could not fetch authorities", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
Expand Down Expand Up @@ -447,9 +448,10 @@ public SyncopeService syncopeService(
@Qualifier("batchExecutor")
final AsyncTaskExecutor batchExecutor,
final BatchDAO batchDAO,
final EntityFactory entityFactory) {
final EntityFactory entityFactory,
final ConfigurableApplicationContext ctx) {

return new SyncopeServiceImpl(syncopeLogic, batchExecutor, bus, batchDAO, entityFactory);
return new SyncopeServiceImpl(syncopeLogic, batchExecutor, bus, batchDAO, entityFactory, ctx);
}

@ConditionalOnMissingBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import org.apache.syncope.common.rest.api.batch.BatchRequestItem;
import org.apache.syncope.common.rest.api.service.SyncopeService;
import org.apache.syncope.core.logic.SyncopeLogic;
import org.apache.syncope.core.persistence.api.ApplicationContextProvider;
import org.apache.syncope.core.persistence.api.dao.BatchDAO;
import org.apache.syncope.core.persistence.api.entity.Batch;
import org.apache.syncope.core.persistence.api.entity.EntityFactory;
import org.apache.syncope.core.rest.cxf.batch.BatchProcess;
import org.apache.syncope.core.spring.security.AuthContextUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -69,18 +69,22 @@ public class SyncopeServiceImpl extends AbstractService implements SyncopeServic

protected final EntityFactory entityFactory;

protected final ConfigurableApplicationContext ctx;

public SyncopeServiceImpl(
final SyncopeLogic logic,
final AsyncTaskExecutor batchExecutor,
final Bus bus,
final BatchDAO batchDAO,
final EntityFactory entityFactory) {
final EntityFactory entityFactory,
final ConfigurableApplicationContext ctx) {

this.logic = logic;
this.batchExecutor = batchExecutor;
this.bus = bus;
this.batchDAO = batchDAO;
this.entityFactory = entityFactory;
this.ctx = ctx;
}

@Override
Expand Down Expand Up @@ -145,7 +149,7 @@ public Response batch(final InputStream input) {
batch.setExpiryTime(OffsetDateTime.now().plusMinutes(5));
batchDAO.save(batch);

BatchProcess batchProcess = ApplicationContextProvider.getBeanFactory().createBean(BatchProcess.class);
BatchProcess batchProcess = ctx.getBeanFactory().createBean(BatchProcess.class);
batchProcess.setBoundary(boundary);
batchProcess.setScheme(messageContext.getHttpServletRequest().getScheme());
batchProcess.setServerName(messageContext.getHttpServletRequest().getServerName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface AccessTokenDAO extends DAO<AccessToken> {
Page<? extends AccessToken> findAll(Pageable pageable);

int deleteExpired(OffsetDateTime now);

int deleteByOwner(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Optional;
import java.util.Set;
import org.apache.syncope.core.persistence.api.entity.Any;
import org.apache.syncope.core.persistence.api.entity.AnyType;
import org.apache.syncope.core.persistence.api.entity.ExternalResource;
import org.apache.syncope.core.persistence.api.entity.Relationship;
import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership;
Expand Down Expand Up @@ -56,9 +55,9 @@ public interface AnyObjectDAO extends AnyDAO<AnyObject> {
*
* @return the number of instances for each type
*/
Map<AnyType, Long> countByType();
Map<String, Long> countByType();

Map<String, Long> countByRealm(AnyType anyType);
Map<String, Long> countByRealm(String anyType);

void deleteMembership(AMembership membership);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ List<TaskExec<?>> findAll(

<T extends Task<T>> void saveAndAdd(TaskType type, String taskKey, TaskExec<T> execution);

<T extends Task<T>> void delete(TaskType type, String key);
void delete(TaskType type, String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface AccessToken extends ProvidedKeyEntity {

void setOwner(String owner);

byte[] getAuthorities();
String getAuthorities();

void setAuthorities(byte[] authorities);
void setAuthorities(String authorities);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

public interface ConnInstance extends Entity {

int DEFAULT_TIMEOUT = 10;

Realm getAdminRealm();

void setAdminRealm(Realm adminRealm);
Expand Down
Loading