public void addAssociationHandler(JetspeedPrincipalAssociationHandler jpah) { if (jpah.getAssociationType().getFromPrincipalType().getName().equals(principalType.getName()) || jpah.getAssociationType().getToPrincipalType().getName().equals(principalType.getName())) { AssociationHandlerKey key = new AssociationHandlerKey(jpah); if (assHandlers.containsKey(key)) { throw new IllegalStateException("An AssociationHandler for " + jpah.getAssociationType().getAssociationName() + " already defined"); } assHandlers.put(key, jpah); associationTypes.add(jpah.getAssociationType()); if (jpah.getAssociationType().isRequired() && jpah.getAssociationType().getFromPrincipalType().getName().equals(principalType.getName())) { reqAssociations.put(key,jpah.getAssociationType()); } } else { throw new IllegalArgumentException("AssociationHandler is not handling a " + principalType.getName() + " JetspeedPrincipal"); } }
@SuppressWarnings("unchecked") public void beforeRemoveTo(JetspeedPrincipal to) throws SecurityException { if (associationType.isDependent()) { List<JetspeedPrincipal> fromList = (List<JetspeedPrincipal>)getManagerTo().getAssociatedTo(to.getName(), to.getType(), associationType.getAssociationName()); for (JetspeedPrincipal from : fromList) { getManagerFrom().removePrincipal(from); } } else if (associationType.isRequired() && !isSynchronizing()) { if (!getManagerTo().getAssociatedTo(to.getName(), to.getType(), associationType.getAssociationName()).isEmpty()) { throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_REQUIRED.createScoped(to.getType().getName(), to.getName(), associationType.getFromPrincipalType().getName(), associationType.getAssociationName())); } } }
if (jpah.getAssociationType().isRequired() && !isSynchronizing())