use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, User user) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, user);
if (getAttributesManagerImpl().removeAllAttributes(sess, user)) {
getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForUser(user));
}
log.info("{} removed all attributes from user {}.", sess.getLogId(), user.getId());
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesSemantics(sess, user, attributes);
checkAttributesDependencies(sess, user, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, user, new Attribute(attribute));
} catch (WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
@Override
public boolean setAttributeWithoutCheck(PerunSession sess, Resource resource, Group group, Attribute attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed;
if (isVirtAttribute(sess, attribute)) {
// FIXME Zatim je zakazane nastavovani virtualnich atributu group_resource
Attribute storedAttribute;
try {
storedAttribute = getAttribute(sess, resource, group, attribute.getName());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (!(storedAttribute.getValue() == null ? attribute.getValue() == null : storedAttribute.getValue().equals(attribute.getValue()))) {
// FIXME
if (attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGID") || attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGroupName")) {
return getAttributesManagerImpl().setVirtualAttribute(sess, resource, group, attribute);
} else {
throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute. " + attribute);
}
} else {
return false;
}
} else {
changed = getAttributesManagerImpl().setAttribute(sess, resource, group, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, new AttributeSetForGroupAndResource(attribute, group, resource));
getAttributesManagerImpl().changedAttributeHook(sess, resource, group, attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class FacilitiesManagerBlImpl method createFacility.
@Override
public Facility createFacility(PerunSession sess, Facility facility) throws FacilityExistsException {
// check facility name, it can contain only a-zA-Z.0-9_-
if (!facility.getName().matches("^[ a-zA-Z.0-9_-]+$")) {
throw 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, new FacilityCreated(facility));
// set creator as Facility manager
if (sess.getPerunPrincipal().getUser() != null) {
try {
AuthzResolverBlImpl.setRole(sess, sess.getPerunPrincipal().getUser(), facility, Role.FACILITYADMIN);
} catch (AlreadyAdminException ex) {
throw new ConsistencyErrorException("Add manager to newly created Facility failed because there is particular manager already assigned", ex);
} catch (RoleCannotBeManagedException e) {
throw new InternalErrorException(e);
}
} 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.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, Group group) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, group);
if (getAttributesManagerImpl().removeAllAttributes(sess, group)) {
getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForGroup(group));
}
log.info("{} removed all attributes from group {}.", sess.getLogId(), group.getId());
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesSemantics(sess, group, attributes);
checkAttributesDependencies(sess, group, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, group, new Attribute(attribute));
} catch (WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class MembersManagerBlImpl method createMember.
// MAIN METHOD
@Override
public Member createMember(PerunSession sess, Vo vo, SpecificUserType specificUserType, Candidate candidate, List<Group> groups, List<String> overwriteUserAttributes) throws WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException {
log.debug("Creating member for VO {} from candidate {}", vo, candidate);
// Get the user
User user = null;
if (candidate.getUserExtSources() != null) {
for (UserExtSource ues : candidate.getUserExtSources()) {
// Check if the extSource exists
ExtSource tmpExtSource = getPerunBl().getExtSourcesManagerBl().checkOrCreateExtSource(sess, ues.getExtSource().getName(), ues.getExtSource().getType());
// Set the extSource ID
ues.getExtSource().setId(tmpExtSource.getId());
try {
// Try to find the user by userExtSource
user = getPerunBl().getUsersManagerBl().getUserByExtSourceNameAndExtLogin(sess, ues.getExtSource().getName(), ues.getLogin());
} catch (UserExtSourceNotExistsException e) {
// This is OK, non-existent userExtSource will be assigned later
} catch (UserNotExistsException | ExtSourceNotExistsException e) {
// Ignore, we are only checking if the user exists
}
}
}
// If user hasn't been found, then create him
if (user == null) {
user = new User();
user.setFirstName(candidate.getFirstName());
user.setLastName(candidate.getLastName());
user.setMiddleName(candidate.getMiddleName());
user.setTitleAfter(candidate.getTitleAfter());
user.setTitleBefore(candidate.getTitleBefore());
if (specificUserType.equals(SpecificUserType.SERVICE))
user.setServiceUser(true);
if (specificUserType.equals(SpecificUserType.SPONSORED))
user.setSponsoredUser(true);
// Store the user, this must be done in separate transaction
user = getPerunBl().getUsersManagerBl().createUser(sess, user);
log.debug("createMember: new user: {}", user);
}
// Assign missing userExtSource and update LoA
if (candidate.getUserExtSources() != null) {
for (UserExtSource userExtSource : candidate.getUserExtSources()) {
try {
UserExtSource currentUserExtSource = getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, userExtSource.getExtSource(), userExtSource.getLogin());
// Update LoA
currentUserExtSource.setLoa(userExtSource.getLoa());
getPerunBl().getUsersManagerBl().updateUserExtSource(sess, currentUserExtSource);
} catch (UserExtSourceNotExistsException e) {
// Create userExtSource
try {
getPerunBl().getUsersManagerBl().addUserExtSource(sess, user, userExtSource);
} catch (UserExtSourceExistsException e1) {
throw new ConsistencyErrorException("Adding userExtSource which already exists: " + userExtSource);
}
} catch (UserExtSourceExistsException e1) {
throw new ConsistencyErrorException("Updating login of userExtSource to value which already exists: " + userExtSource);
}
}
}
try {
Member member = getMemberByUser(sess, vo, user);
throw new AlreadyMemberException(member);
} catch (MemberNotExistsException IGNORE) {
}
// Create the member
Member member = getMembersManagerImpl().createMember(sess, vo, user);
getPerunBl().getAuditer().log(sess, new MemberCreated(member));
// Create the member's attributes
List<Attribute> membersAttributes = new ArrayList<>();
List<Attribute> usersAttributesToMerge = new ArrayList<>();
List<Attribute> usersAttributesToModify = new ArrayList<>();
if (candidate.getAttributes() != null) {
for (String attributeName : candidate.getAttributes().keySet()) {
AttributeDefinition attributeDefinition;
try {
attributeDefinition = getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attributeName);
} catch (AttributeNotExistsException ex) {
throw new InternalErrorException(ex);
}
Attribute attribute = new Attribute(attributeDefinition);
attribute.setValue(getPerunBl().getAttributesManagerBl().stringToAttributeValue(candidate.getAttributes().get(attributeName), attribute.getType()));
if (getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR_DEF) || getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR_OPT)) {
// This is member's attribute
membersAttributes.add(attribute);
} else if (getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR_DEF) || getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR_OPT)) {
if (overwriteUserAttributes != null && !overwriteUserAttributes.isEmpty() && overwriteUserAttributes.contains(attribute.getName())) {
usersAttributesToModify.add(attribute);
} else {
usersAttributesToMerge.add(attribute);
}
}
}
}
// Store the attributes
try {
// If empty, skip setting or merging empty arrays of attributes at all
if (!membersAttributes.isEmpty())
getPerunBl().getAttributesManagerBl().setAttributes(sess, member, membersAttributes);
if (!usersAttributesToMerge.isEmpty())
getPerunBl().getAttributesManagerBl().mergeAttributesValues(sess, user, usersAttributesToMerge);
if (!usersAttributesToModify.isEmpty())
getPerunBl().getAttributesManagerBl().setAttributes(sess, user, usersAttributesToModify);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
// Set the initial membershipExpiration
// Get user LOA
String memberLoa = null;
try {
Attribute loa = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_VIRT + ":loa");
memberLoa = Integer.toString((Integer) loa.getValue());
} catch (AttributeNotExistsException e) {
// user has no loa defined - if required by VO, it will be stopped in checking method later
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
// Check if user can be member
this.canBeMemberInternal(sess, vo, user, memberLoa, true);
// set initial membership expiration
this.extendMembership(sess, member);
insertToMemberGroup(sess, member, vo);
// Add member also to all groups in list
if (groups != null && !groups.isEmpty()) {
for (Group group : groups) {
try {
perunBl.getGroupsManagerBl().addMember(sess, group, member);
} catch (GroupNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
}
return member;
}
Aggregations