added scope consistent check to resource set service
parent
6703db234d
commit
d7af4b2cf9
|
@ -19,6 +19,7 @@ package org.mitre.uma.service.impl;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.mitre.uma.model.Policy;
|
||||||
import org.mitre.uma.model.ResourceSet;
|
import org.mitre.uma.model.ResourceSet;
|
||||||
import org.mitre.uma.repository.ResourceSetRepository;
|
import org.mitre.uma.repository.ResourceSetRepository;
|
||||||
import org.mitre.uma.service.ResourceSetService;
|
import org.mitre.uma.service.ResourceSetService;
|
||||||
|
@ -48,6 +49,10 @@ public class DefaultResourceSetService implements ResourceSetService {
|
||||||
throw new IllegalArgumentException("Can't save a new resource set with an ID already set to it.");
|
throw new IllegalArgumentException("Can't save a new resource set with an ID already set to it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkScopeConsistency(rs)) {
|
||||||
|
throw new IllegalArgumentException("Can't save a resource set with inconsistent claims.");
|
||||||
|
}
|
||||||
|
|
||||||
ResourceSet saved = repository.save(rs);
|
ResourceSet saved = repository.save(rs);
|
||||||
|
|
||||||
return saved;
|
return saved;
|
||||||
|
@ -69,6 +74,10 @@ public class DefaultResourceSetService implements ResourceSetService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkScopeConsistency(newRs)) {
|
||||||
|
throw new IllegalArgumentException("Can't save a resource set with inconsistent claims.");
|
||||||
|
}
|
||||||
|
|
||||||
newRs.setOwner(oldRs.getOwner()); // preserve the owner tag across updates
|
newRs.setOwner(oldRs.getOwner()); // preserve the owner tag across updates
|
||||||
newRs.setClientId(oldRs.getClientId()); // preserve the client id across updates
|
newRs.setClientId(oldRs.getClientId()); // preserve the client id across updates
|
||||||
|
|
||||||
|
@ -93,6 +102,14 @@ public class DefaultResourceSetService implements ResourceSetService {
|
||||||
return repository.getAllForOwnerAndClient(owner, clientId);
|
return repository.getAllForOwnerAndClient(owner, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkScopeConsistency(ResourceSet rs) {
|
||||||
|
for (Policy policy : rs.getPolicies()) {
|
||||||
|
if (!rs.getScopes().containsAll(policy.getScopes())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// we've checked everything, we're good
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue