Repository: syncope Updated Branches: refs/heads/2_0_X f9aed7b8d -> edb004d8d refs/heads/master 3a9d872f1 -> 81a030bd7
[SYNCOPE-1232] Prevent AnyType removal if AnyObject instances are found Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c3acdc3e Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c3acdc3e Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c3acdc3e Branch: refs/heads/2_0_X Commit: c3acdc3e57699af236c915bd2c8fb05bca7bcd92 Parents: f9aed7b Author: Francesco Chicchiriccò <ilgro...@apache.org> Authored: Thu Nov 2 14:33:47 2017 +0100 Committer: Francesco Chicchiriccò <ilgro...@apache.org> Committed: Thu Nov 2 14:33:47 2017 +0100 ---------------------------------------------------------------------- .../org/apache/syncope/core/logic/AnyTypeLogic.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/c3acdc3e/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java index f967da8..a7a41ff 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java @@ -29,6 +29,7 @@ import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.AnyTypeTO; import org.apache.syncope.common.lib.types.ClientExceptionType; import org.apache.syncope.common.lib.types.StandardEntitlement; +import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; import org.apache.syncope.core.persistence.api.dao.NotFoundException; import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO; import org.apache.syncope.core.persistence.api.dao.DuplicateException; @@ -48,6 +49,9 @@ public class AnyTypeLogic extends AbstractTransactionalLogic<AnyTypeTO> { @Autowired private AnyTypeDAO anyTypeDAO; + @Autowired + private AnyObjectDAO anyObjectDAO; + @PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_READ + "')") @Transactional(readOnly = true) public AnyTypeTO read(final String key) { @@ -92,6 +96,7 @@ public class AnyTypeLogic extends AbstractTransactionalLogic<AnyTypeTO> { AnyType anyType = anyTypeDAO.find(anyTypeTO.getKey()); if (anyType == null) { LOG.error("Could not find anyType '" + anyTypeTO.getKey() + "'"); + throw new NotFoundException(anyTypeTO.getKey()); } @@ -111,6 +116,13 @@ public class AnyTypeLogic extends AbstractTransactionalLogic<AnyTypeTO> { } try { + Integer anyObjects = anyObjectDAO.countByType().get(anyType); + if (anyObjects != null && anyObjects > 0) { + LOG.error("{} AnyObject instances found for {}, aborting", anyObjects, anyType); + + throw new IllegalArgumentException("AnyObject instances found for " + key); + } + return binder.delete(anyType); } catch (IllegalArgumentException e) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);