You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2017/11/02 14:36:45 UTC
[3/4] syncope git commit: [SYNCOPE-1232] Prevent AnyType removal if
AnyObject instances are found
[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/cd731aa1
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/cd731aa1
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/cd731aa1
Branch: refs/heads/master
Commit: cd731aa1b81664539bc7f818d6e111ad4e697d1a
Parents: 3a9d872
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Thu Nov 2 14:33:47 2017 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Thu Nov 2 15:36:21 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/cd731aa1/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 783d356..a0c70d0 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
@@ -27,6 +27,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;
@@ -46,6 +47,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) {
@@ -84,6 +88,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());
}
@@ -103,6 +108,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);