Search in sources :

Example 21 with InternalErrorException

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)

Example 22 with InternalErrorException

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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 23 with InternalErrorException

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 24 with InternalErrorException

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);
    }
}
Also used : ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 25 with InternalErrorException

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)376 Attribute (cz.metacentrum.perun.core.api.Attribute)119 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)104 ArrayList (java.util.ArrayList)94 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)89 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)78 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)68 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)67 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)44 User (cz.metacentrum.perun.core.api.User)37 Group (cz.metacentrum.perun.core.api.Group)36 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)33 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)33 HashMap (java.util.HashMap)30 IOException (java.io.IOException)28 Member (cz.metacentrum.perun.core.api.Member)24 Map (java.util.Map)24 Facility (cz.metacentrum.perun.core.api.Facility)23 List (java.util.List)23 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)22