Search in sources :

Example 1 with AlreadyAdminException

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

the class FacilitiesManagerBlImpl method createFacility.

public Facility createFacility(PerunSession sess, Facility facility) throws InternalErrorException, FacilityExistsException {
    //check facility name, it can contain only a-zA-Z.0-9_-
    if (!facility.getName().matches("^[ a-zA-Z.0-9_-]+$")) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong facility name, facility name can contain only a-Z0-9.-_ and space characters"));
    }
    //check if facility have uniq name
    try {
        this.getFacilityByName(sess, facility.getName());
        throw new FacilityExistsException(facility);
    } catch (FacilityNotExistsException ex) {
    /* OK */
    }
    // create facility
    facility = getFacilitiesManagerImpl().createFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, "Facility created {}.", facility);
    //set creator as Facility manager
    if (sess.getPerunPrincipal().getUser() != null) {
        try {
            addAdmin(sess, facility, sess.getPerunPrincipal().getUser());
        } catch (AlreadyAdminException ex) {
            throw new ConsistencyErrorException("Add manager to newly created Facility failed because there is particular manager already assigned", ex);
        }
    } else {
        log.warn("Can't set Facility manager during creating of the Facility. User from perunSession is null. {} {}", facility, sess);
    }
    return facility;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) FacilityExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Example 2 with AlreadyAdminException

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

the class VosManagerBlImpl method createVo.

public Vo createVo(PerunSession sess, Vo vo) throws VoExistsException, InternalErrorException {
    // Create entries in the DB and Grouper
    vo = getVosManagerImpl().createVo(sess, vo);
    getPerunBl().getAuditer().log(sess, "{} created.", vo);
    try {
        // Create group containing VO members
        Group members = new Group(VosManager.MEMBERS_GROUP, VosManager.MEMBERS_GROUP_DESCRIPTION + " for VO " + vo.getName());
        getPerunBl().getGroupsManagerBl().createGroup(sess, vo, members);
        log.debug("Members group created, vo '{}'", vo);
    } catch (GroupExistsException e) {
        throw new ConsistencyErrorException("Group already exists", e);
    }
    // create empty application form
    getVosManagerImpl().createApplicationForm(sess, vo);
    //set creator as VO manager
    if (sess.getPerunPrincipal().getUser() != null) {
        try {
            addAdmin(sess, vo, sess.getPerunPrincipal().getUser());
        } catch (AlreadyAdminException ex) {
            throw new ConsistencyErrorException("Add manager to newly created VO failed because there is a particular manager already assigned", ex);
        }
    } else {
        log.error("Can't set VO manager during creating of the VO. User from perunSession is null. {} {}", vo, sess);
    }
    log.debug("Vo {} created", vo);
    return vo;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Example 3 with AlreadyAdminException

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

the class VosManagerBlImpl method addAdmin.

public void addAdmin(PerunSession sess, Vo vo, User user) throws InternalErrorException, AlreadyAdminException {
    List<User> adminsOfVo = this.getAdmins(sess, vo);
    if (adminsOfVo.contains(user))
        throw new AlreadyAdminException(user, vo);
    AuthzResolverBlImpl.setRole(sess, user, vo, Role.VOADMIN);
    log.debug("User [{}] added like administrator to VO [{}]", user, vo);
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Example 4 with AlreadyAdminException

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

the class VosManagerBlImpl method addAdmin.

@Override
public void addAdmin(PerunSession sess, Vo vo, Group group) throws InternalErrorException, AlreadyAdminException {
    List<Group> adminsOfVo = this.getAdminGroups(sess, vo);
    if (adminsOfVo.contains(group))
        throw new AlreadyAdminException(group, vo);
    AuthzResolverBlImpl.setRole(sess, group, vo, Role.VOADMIN);
    log.debug("Group [{}] added like administrator to VO [{}]", group, vo);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Example 5 with AlreadyAdminException

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

the class SecurityTeamsManagerBlImpl method createSecurityTeam.

@Override
public SecurityTeam createSecurityTeam(PerunSession sess, SecurityTeam securityTeam) throws SecurityTeamExistsException, InternalErrorException {
    securityTeam = getSecurityTeamsManagerImpl().createSecurityTeam(sess, securityTeam);
    getPerunBl().getAuditer().log(sess, "{} was created.", securityTeam);
    // set creator as security team admin
    User user = sess.getPerunPrincipal().getUser();
    if (user != null) {
        //user can be null in tests
        try {
            AuthzResolverBlImpl.setRole(sess, user, securityTeam, Role.SECURITYADMIN);
        } catch (AlreadyAdminException e) {
            throw new ConsistencyErrorException("Newly created securityTeam already have an admin.", e);
        }
    }
    return securityTeam;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Aggregations

AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)6 Group (cz.metacentrum.perun.core.api.Group)3 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)3 User (cz.metacentrum.perun.core.api.User)2 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 FacilityExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityExistsException)1 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)1 GroupExistsException (cz.metacentrum.perun.core.api.exceptions.GroupExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1