Search in sources :

Example 1 with SecurityTeamExistsException

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

Aggregations

SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 SecurityTeamExistsException (cz.metacentrum.perun.core.api.exceptions.SecurityTeamExistsException)1 SecurityTeamNotExistsException (cz.metacentrum.perun.core.api.exceptions.SecurityTeamNotExistsException)1