use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.
the class MembersManagerEntry method getRichMemberWithAttributes.
public RichMember getRichMemberWithAttributes(PerunSession sess, Member member) throws InternalErrorException, PrivilegeException, MemberNotExistsException {
Utils.checkPerunSession(sess);
getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
Vo vo = getPerunBl().getMembersManagerBl().getMemberVo(sess, member);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.SELF, member)) {
throw new PrivilegeException(sess, "getRichMemberWithAttributes");
}
return getPerunBl().getMembersManagerBl().filterOnlyAllowedAttributes(sess, getMembersManagerBl().getRichMemberWithAttributes(sess, member));
}
use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.
the class MembersManagerEntry method findCompleteRichMembers.
@Override
public List<RichMember> findCompleteRichMembers(PerunSession sess, List<String> attrsNames, List<String> allowedStatuses, String searchString) throws InternalErrorException, MemberNotExistsException, PrivilegeException, VoNotExistsException, AttributeNotExistsException {
Utils.checkPerunSession(sess);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN) && !AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN)) {
throw new PrivilegeException(sess, "findCompleteRichMembers");
}
List<RichMember> richMembers = getMembersManagerBl().findCompleteRichMembers(sess, attrsNames, allowedStatuses, searchString);
Iterator<RichMember> richMemberIter = richMembers.iterator();
while (richMemberIter.hasNext()) {
RichMember richMember = richMemberIter.next();
//if voadmin or voobserver or groupadmin has right to this member, its ok
if (AuthzResolver.isAuthorized(sess, Role.VOADMIN, richMember) || AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, richMember) || AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, richMember))
continue;
//if not, then try facility admin rights
List<Resource> membersResources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, richMember);
boolean found = false;
for (Resource resource : membersResources) {
if (AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, resource)) {
found = true;
break;
}
}
if (found)
continue;
richMemberIter.remove();
}
return getPerunBl().getMembersManagerBl().filterOnlyAllowedAttributes(sess, richMembers, false);
}
use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.
the class FacilitiesManagerEntry method getBansForFacility.
public List<BanOnFacility> getBansForFacility(PerunSession sess, int facilityId) throws InternalErrorException, PrivilegeException, FacilityNotExistsException {
Utils.checkPerunSession(sess);
Facility facility = this.getFacilitiesManagerBl().getFacilityById(sess, facilityId);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "getBansForFacility");
}
return getFacilitiesManagerBl().getBansForFacility(sess, facilityId);
}
use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.
the class FacilitiesManagerEntry method getFacilityById.
public Facility getFacilityById(PerunSession sess, int id) throws InternalErrorException, FacilityNotExistsException, PrivilegeException {
Utils.checkPerunSession(sess);
Facility facility = getFacilitiesManagerBl().getFacilityById(sess, id);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility) && !AuthzResolver.isAuthorized(sess, Role.ENGINE) && !AuthzResolver.isAuthorized(sess, Role.RPC)) {
throw new PrivilegeException(sess, "getFacilityById");
}
return facility;
}
use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.
the class FacilitiesManagerEntry method getHostsByHostname.
public List<Host> getHostsByHostname(PerunSession sess, String hostname) throws InternalErrorException, PrivilegeException {
Utils.checkPerunSession(sess);
Utils.notNull(hostname, "hostname");
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN)) {
throw new PrivilegeException(sess, "getHostsByHostname");
}
List<Host> hostsByHostname = getFacilitiesManagerBl().getHostsByHostname(sess, hostname);
//need to remove those hosts, which are not from facilities of this facility admin
if (!AuthzResolver.hasRole(sess.getPerunPrincipal(), Role.PERUNADMIN) && AuthzResolver.hasRole(sess.getPerunPrincipal(), Role.FACILITYADMIN)) {
//get all complementary facilities for this perunPrincipal
List<Facility> authorizedFacilities = new ArrayList<>();
List<PerunBean> complementaryObjects = AuthzResolver.getComplementaryObjectsForRole(sess, Role.FACILITYADMIN);
for (PerunBean pb : complementaryObjects) {
if (pb instanceof Facility)
authorizedFacilities.add((Facility) pb);
}
//remove hosts which has not facility from authorized facilities
Iterator<Host> hostIterator = hostsByHostname.iterator();
while (hostIterator.hasNext()) {
Host host = hostIterator.next();
Facility fac = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
if (!authorizedFacilities.contains(fac))
hostIterator.remove();
}
}
return hostsByHostname;
}
Aggregations