use of cz.metacentrum.perun.core.api.exceptions.SecurityTeamNotExistsException in project perun by CESNET.
the class SecurityTeamsManagerEntry method updateSecurityTeam.
@Override
public SecurityTeam updateSecurityTeam(PerunSession sess, SecurityTeam securityTeam) throws InternalErrorException, PrivilegeException, SecurityTeamNotExistsException, SecurityTeamExistsException {
Utils.checkPerunSession(sess);
Utils.notNull(securityTeam, "securityTeam");
Utils.notNull(securityTeam.getName(), "securityTeam.name");
if (!AuthzResolver.isAuthorized(sess, Role.SECURITYADMIN, securityTeam)) {
throw new PrivilegeException(sess, "updateSecurityTeam");
}
if (securityTeam.getName().length() > 128) {
throw new InternalErrorException("Security Team name is too long, >128 characters");
}
if (!securityTeam.getName().matches("^[-_a-zA-z0-9.]{1,128}$")) {
throw new InternalErrorException("Wrong Security name - must matches [-_a-zA-z0-9.]+ and not be longer than 128 characters.");
}
getSecurityTeamsManagerBl().checkSecurityTeamExists(sess, securityTeam);
try {
SecurityTeam existingTeam = getSecurityTeamsManagerBl().getSecurityTeamByName(sess, securityTeam.getName());
if (existingTeam != null && existingTeam.getId() != securityTeam.getId()) {
throw new SecurityTeamExistsException("SecurityTeam with name='" + securityTeam.getName() + "' already exists.");
}
} catch (SecurityTeamNotExistsException ex) {
// OK since we are renaming security team to non-taken value
}
// don't store empty description
if (securityTeam.getDescription() != null && securityTeam.getDescription().trim().isEmpty()) {
securityTeam.setDescription(null);
}
return getSecurityTeamsManagerBl().updateSecurityTeam(sess, securityTeam);
}
Aggregations