criteria.addEqualTo("name", permission.getName());
Query query = QueryFactory.newQuery(PersistentJetspeedPermissionImpl.class, criteria);
PersistentJetspeedPermission p = (PersistentJetspeedPermission)getPersistenceBrokerTemplate().getObjectByQuery(query);
if (p == null)
{
throw new SecurityException(SecurityException.PERMISSION_DOES_NOT_EXIST.create(permission.getName()));
}
permission = p;
}
Criteria criteria = new Criteria();
criteria.addEqualTo("permissions.permissionId", permission.getId());
if (principalType != null)
{
criteria.addEqualTo("type", principalType);
}
criteria.addEqualTo("domainId", getDefaultSecurityDomainId());
QueryByCriteria query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria);
List<JetspeedPrincipal> currentList = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query));
List<JetspeedPrincipal> targetList = new ArrayList<JetspeedPrincipal>(principals);
for (Iterator<JetspeedPrincipal> i = currentList.iterator(); i.hasNext(); )
{
JetspeedPrincipal current = i.next();
for (Iterator<JetspeedPrincipal> j = targetList.iterator(); j.hasNext(); )
{
JetspeedPrincipal target = j.next();
if (principalType != null && !target.getType().getName().equals(principalType))
{
throw new SecurityException(SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
"grantPermissionOnlyTo",
"Specified "+target.getType().getName()+" principal: "+target.getName()+" is not of type: "+principalType));
}
if (current.getType().getName().equals(target.getType().getName()) && current.getName().equals(target.getName()))
{