@SuppressWarnings("unchecked")
public void grantPermissionOnlyTo(PersistentJetspeedPermission permission, String principalType, List<JetspeedPrincipal> principals) throws SecurityException
{
if (permission.getId() == null)
{
Criteria criteria = new Criteria();
criteria.addEqualTo("type", permission.getType());
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(); )
{