use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class Utils method parseAdditionalUserExtSource.
/**
* Returns additional user ext source either found in Perun or creates new. Parameter userExtSourceRaw is array of
* Strings containing name, type and extLogin. If any of the required parts is empty, ParserException is thrown.
* Used in extractAdditionalUserExtSources to get ues.
*
* @param sess perun session
* @param userExtSourceRaw array of strings containing all parts of ues
* @return UserExtSource additional ues
*/
private static UserExtSource parseAdditionalUserExtSource(PerunSession sess, String[] userExtSourceRaw) {
// Get extLogin from 3rd part of userExtSourceRaw as well as ues attributes, so it needs to be parsed from it
String extLogin = userExtSourceRaw[2].split(";")[0];
// Check whether any of the required parts of ues are not empty
if (userExtSourceRaw[0].isEmpty() || userExtSourceRaw[1].isEmpty() || extLogin.isEmpty()) {
throw new ParserException("Some of the required parts of userExtSource are empty.");
}
ExtSource additionalExtSource;
try {
// Try to get extSource, with full extSource object (containg ID)
additionalExtSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, userExtSourceRaw[0]);
} catch (ExtSourceNotExistsException e) {
try {
// Create new one if not exists
additionalExtSource = new ExtSource(userExtSourceRaw[0], userExtSourceRaw[1]);
additionalExtSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().createExtSource(sess, additionalExtSource, null);
} catch (ExtSourceExistsException e1) {
throw new ConsistencyErrorException("Creating existing extSource: " + userExtSourceRaw[0]);
}
}
// Get optional LoA (0 if not stated)
int loa = parseAdditionalUESLoa(userExtSourceRaw);
return new UserExtSource(additionalExtSource, loa, extLogin);
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_entityless_attribute_def_def_namespace_maxUID method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, String key, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Integer maxUID = attribute.valueAsInteger();
if (maxUID == null)
return;
try {
Attribute minUIDAttr = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, key, A_E_namespaceMinUID);
Integer minUID = minUIDAttr.valueAsInteger();
if (minUID != null) {
if (maxUID < minUID)
throw new WrongReferenceAttributeValueException(attribute, minUIDAttr, key, null, key, null, "Attribute value must be more than minUID. MinUID = " + minUID + ", and maxUID try to set = " + maxUID);
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute namespace-minUID is supposed to exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class UsersManagerImpl method updateNameTitles.
@Override
public User updateNameTitles(PerunSession sess, User user) {
try {
User userDb = jdbc.queryForObject("select " + userMappingSelectQuery + " from users where id=? ", USER_MAPPER, user.getId());
if (userDb == null) {
throw new ConsistencyErrorException("Updating titles for non existing user");
}
if ((user.getTitleBefore() != null && !user.getTitleBefore().equals(userDb.getTitleBefore())) || (user.getTitleBefore() == null && userDb.getTitleBefore() != null)) {
jdbc.update("update users set title_before=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", user.getTitleBefore(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), user.getId());
userDb.setTitleBefore(user.getTitleBefore());
}
if ((user.getTitleAfter() != null && !user.getTitleAfter().equals(userDb.getTitleAfter())) || ((user.getTitleAfter() == null && userDb.getTitleAfter() != null))) {
jdbc.update("update users set title_after=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", user.getTitleAfter(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), user.getId());
userDb.setTitleAfter(user.getTitleAfter());
}
return userDb;
} catch (RuntimeException err) {
throw new InternalErrorException(err);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class UsersManagerImpl method userExtSourceExists.
@Override
public boolean userExtSourceExists(PerunSession sess, UserExtSource userExtSource) {
Utils.notNull(userExtSource, "userExtSource");
Utils.notNull(userExtSource.getLogin(), "userExtSource.getLogin");
Utils.notNull(userExtSource.getExtSource(), "userExtSource.getExtSource");
try {
// check by ext identity (login/ext source ID)
if (userExtSource.getUserId() >= 0) {
int numberOfExistences = jdbc.queryForInt("select count(1) from user_ext_sources where login_ext=? and ext_sources_id=? and user_id=?", userExtSource.getLogin(), userExtSource.getExtSource().getId(), userExtSource.getUserId());
if (numberOfExistences == 1) {
return true;
} else if (numberOfExistences > 1) {
throw new ConsistencyErrorException("UserExtSource " + userExtSource + " exists more than once.");
}
return false;
} else {
int numberOfExistences = jdbc.queryForInt("select count(1) from user_ext_sources where login_ext=? and ext_sources_id=?", userExtSource.getLogin(), userExtSource.getExtSource().getId());
if (numberOfExistences == 1) {
return true;
} else if (numberOfExistences > 1) {
throw new ConsistencyErrorException("UserExtSource " + userExtSource + " exists more than once.");
}
return false;
}
} catch (EmptyResultDataAccessException ex) {
return false;
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class VosManagerImpl method deleteVo.
@Override
public Vo deleteVo(PerunSession sess, Vo vo) {
try {
// Delete authz entries for this VO
AuthzResolverBlImpl.removeAllAuthzForVo(sess, vo);
vo = jdbc.queryForObject("delete from vos where id=? returning " + voMappingSelectQuery, VO_MAPPER, vo.getId());
} catch (EmptyResultDataAccessException e) {
throw new ConsistencyErrorException("no record was deleted from the DB.");
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
log.debug("Vo {} deleted", vo);
return vo;
}
Aggregations