use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class GroupsManagerEntry method createGroup.
public Group createGroup(PerunSession sess, Vo vo, Group group) throws GroupExistsException, PrivilegeException, InternalErrorException, VoNotExistsException {
Utils.checkPerunSession(sess);
Utils.notNull(group, "group");
Utils.notNull(group.getName(), "group.name");
if (!group.getName().matches(GroupsManager.GROUP_SHORT_NAME_REGEXP)) {
throw new InternalErrorException(new IllegalArgumentException("Wrong group name, group name must matches " + GroupsManager.GROUP_SHORT_NAME_REGEXP));
}
if (group.getParentGroupId() != null)
throw new InternalErrorException("Top-level groups can't have parentGroupId set!");
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.TOPGROUPCREATOR, vo)) {
throw new PrivilegeException(sess, "createGroup");
}
getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
Group createdGroup = getGroupsManagerBl().createGroup(sess, vo, group);
//Refresh authz
AuthzResolver.refreshAuthz(sess);
return createdGroup;
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class MembersManagerEntry method createMember.
public Member createMember(PerunSession sess, Vo vo, Candidate candidate, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, VoNotExistsException, PrivilegeException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
Utils.checkPerunSession(sess);
// if any group is not from the vo, throw an exception
if (groups != null) {
for (Group group : groups) {
perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
if (group.getVoId() != vo.getId())
throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where candidate " + candidate + " should be added.");
}
}
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
throw new PrivilegeException(sess, "createMember - from candidate");
}
Utils.notNull(candidate, "candidate");
getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
return getMembersManagerBl().createMember(sess, vo, candidate, groups);
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class MembersManagerEntry method createMember.
public Member createMember(PerunSession sess, Vo vo, ExtSource extSource, String login, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, VoNotExistsException, ExtSourceNotExistsException, PrivilegeException, GroupNotExistsException, GroupOperationsException {
Utils.checkPerunSession(sess);
getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
getPerunBl().getExtSourcesManagerBl().checkExtSourceExists(sess, extSource);
// if any group is not from the vo, throw an exception
if (groups != null) {
for (Group group : groups) {
perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
if (group.getVoId() != vo.getId())
throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where user with login " + login + " from ExtSource " + extSource + " should be added.");
}
}
// Authorization for vo admin and perun admin automatic
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
//also group admin of all affected groups is ok
if (groups != null && !groups.isEmpty()) {
boolean groupAdminOfAllGroups = true;
boolean authorizedToExtSource = false;
for (Group group : groups) {
//User in session has to be GroupAdmin of all affected groups
if (!AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
groupAdminOfAllGroups = false;
break;
}
//User in session has to have at least one right to work with the ExtSource
List<ExtSource> groupExtSources = getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group);
if (groupExtSources.contains(extSource))
authorizedToExtSource = true;
}
if (!groupAdminOfAllGroups || !authorizedToExtSource) {
throw new PrivilegeException(sess, "createMember - from login and extSource -- authorized to extSource=" + authorizedToExtSource + " and groupAdmin in all groups=" + groupAdminOfAllGroups);
}
} else {
throw new PrivilegeException(sess, "createMember - from login and extSource");
}
}
// we run async validation
Member member = getMembersManagerBl().createMember(sess, vo, extSource, login, groups);
getMembersManagerBl().validateMemberAsync(sess, member);
return member;
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method deleteAttribute.
public void deleteAttribute(PerunSession sess, AttributeDefinition attribute) throws InternalErrorException {
//TODO prevest do BL?
try {
jdbc.update("delete from facility_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from resource_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from member_resource_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from user_facility_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from user_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from entityless_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from host_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from member_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from group_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from vo_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from group_resource_attr_values where attr_id=?", attribute.getId());
jdbc.update("delete from attr_names where id=?", attribute.getId());
log.info("Attribute deleted [{}]", attribute);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
public List<Attribute> getAttributes(PerunSession sess, Member member, List<String> attrNames) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("mId", member.getId());
parameters.addValue("nSC", AttributesManager.NS_MEMBER_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_MEMBER_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_MEMBER_ATTR_DEF);
parameters.addValue("nSV", AttributesManager.NS_MEMBER_ATTR_VIRT);
parameters.addValue("attrNames", attrNames);
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("mem") + " from attr_names " + "left join member_attr_values mem on id=mem.attr_id and member_id=:mId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, member));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
Aggregations