Search in sources :

Example 1 with IllegalArgumentException

use of cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException 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 2 with IllegalArgumentException

use of cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException in project perun by CESNET.

the class GroupsManagerEntry method updateGroup.

public Group updateGroup(PerunSession sess, Group group) throws GroupNotExistsException, InternalErrorException, PrivilegeException {
    Utils.checkPerunSession(sess);
    getGroupsManagerBl().checkGroupExists(sess, group);
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.name");
    if (!group.getShortName().matches(GroupsManager.GROUP_SHORT_NAME_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong group shortName, group shortName must matches " + GroupsManager.GROUP_SHORT_NAME_REGEXP));
    }
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, group) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
        throw new PrivilegeException(sess, "updateGroup");
    }
    return getGroupsManagerBl().updateGroup(sess, group);
}
Also used : 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 3 with IllegalArgumentException

use of cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException in project perun by CESNET.

the class GroupsManagerEntry method getGroupByName.

public Group getGroupByName(PerunSession sess, Vo vo, String name) throws GroupNotExistsException, InternalErrorException, PrivilegeException, VoNotExistsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    Utils.notNull(name, "name");
    if (!name.matches(GroupsManager.GROUP_FULL_NAME_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong group name, group name must matches " + GroupsManager.GROUP_FULL_NAME_REGEXP));
    }
    Group group = getGroupsManagerBl().getGroupByName(sess, vo, name);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.TOPGROUPCREATOR, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
        throw new PrivilegeException(sess, "getGroupByName");
    }
    return group;
}
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 4 with IllegalArgumentException

use of cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException in project perun by CESNET.

the class GroupsManagerEntry method createGroup.

public Group createGroup(PerunSession sess, Group parentGroup, Group group) throws GroupNotExistsException, GroupExistsException, PrivilegeException, InternalErrorException, GroupOperationsException, GroupRelationNotAllowed, GroupRelationAlreadyExists {
    Utils.checkPerunSession(sess);
    getGroupsManagerBl().checkGroupExists(sess, parentGroup);
    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));
    }
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, parentGroup) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, parentGroup)) {
        throw new PrivilegeException(sess, "createGroup - subGroup");
    }
    Group createdGroup = getGroupsManagerBl().createGroup(sess, parentGroup, 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 5 with IllegalArgumentException

use of cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException in project perun by CESNET.

the class AttributesManagerEntry method createAttribute.

public AttributeDefinition createAttribute(PerunSession sess, AttributeDefinition attribute) throws PrivilegeException, InternalErrorException, AttributeExistsException {
    Utils.checkPerunSession(sess);
    Utils.notNull(attribute, "attributeDefinition");
    if (!AuthzResolver.isAuthorized(sess, Role.PERUNADMIN))
        throw new PrivilegeException("Only perunAdmin can create new Attribute.");
    if (!attribute.getFriendlyName().matches(AttributesManager.ATTRIBUTES_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong attribute name " + attribute.getFriendlyName() + ", attribute name must match " + AttributesManager.ATTRIBUTES_REGEXP));
    }
    return getAttributesManagerBl().createAttribute(sess, attribute);
}
Also used : IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)

Aggregations

IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)4 Group (cz.metacentrum.perun.core.api.Group)3 RichGroup (cz.metacentrum.perun.core.api.RichGroup)3