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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations