use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_member_attribute_def_def_phone method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
if (attribute.getValue() != null) {
Attribute userPhone = null;
try {
userPhone = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_phone);
if (userPhone.getValue() == null) {
userPhone.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPhone);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userPhone, "Mismatch in checking of member phone and user phone (different checking rules)", ex);
}
}
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_user_attribute_def_def_cnCeitecAD method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
if (attribute.getValue() == null) {
throw new WrongAttributeValueException(attribute, user, "Value can't be null");
}
// check existing DN
Set<User> usersWithSameCN = new HashSet<User>(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, attribute));
// check existing DN without accents
String normalizedValue = java.text.Normalizer.normalize((String) attribute.getValue(), java.text.Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
if (!Objects.equals(normalizedValue, (String) attribute.getValue())) {
Attribute changedAttribute = new Attribute(attribute);
changedAttribute.setValue(normalizedValue);
usersWithSameCN.addAll(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, changedAttribute));
}
//remove self
usersWithSameCN.remove(user);
if (!usersWithSameCN.isEmpty()) {
if (usersWithSameCN.size() > 1)
throw new ConsistencyErrorException("FATAL ERROR: Duplicated CN detected." + attribute + " " + usersWithSameCN);
throw new WrongAttributeValueException(attribute, user, "This CN " + attribute.getValue() + " is already occupied for CEITEC AD");
}
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertDNs method resolveVirtualAttributeValueChange.
@Override
public List<String> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, String message) throws InternalErrorException, WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException {
List<String> resolvingMessages = new ArrayList<String>();
if (message == null)
return resolvingMessages;
User user = null;
Attribute attrVirtUserCertDNs = null;
Matcher extSourceTypeX509Matcher = extSourceTypeX509.matcher(message);
Matcher addUserExtSourceMatcher = addUserExtSource.matcher(message);
Matcher removeUserExtSourceMatcher = removeUserExtSource.matcher(message);
Matcher userAttributeSetMatcher = userAttributeSet.matcher(message);
Matcher userAttributeRemovedMatcher = userAttributeRemoved.matcher(message);
if (extSourceTypeX509Matcher.find()) {
if (addUserExtSourceMatcher.find() || removeUserExtSourceMatcher.find()) {
user = getUserFromMessage(message);
if (user != null) {
attrVirtUserCertDNs = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_VIRT + ":userCertDNs");
String messageAttributeSet = attrVirtUserCertDNs.serializeToString() + " set for " + user.serializeToString() + ".";
resolvingMessages.add(messageAttributeSet);
}
}
}
return resolvingMessages;
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertDNs method getUserFromMessage.
/**
* Get User from message if exists or if there is only one. In other case return null instead.
*
* @param message
* @return user or null
* @throws InternalErrorException
*/
private User getUserFromMessage(String message) throws InternalErrorException {
User user = null;
List<PerunBean> perunBeans = AuditParser.parseLog(message);
for (PerunBean pb : perunBeans) {
if (pb instanceof User) {
if (user != null) {
return null;
} else {
user = (User) pb;
}
}
}
return user;
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method removeUserAttributeWhenAttributeNotExists.
@Test(expected = AttributeNotExistsException.class)
public void removeUserAttributeWhenAttributeNotExists() throws Exception {
System.out.println(CLASS_NAME + "removeUserAttributeWhenAttributeNotExists");
vo = setUpVo();
member = setUpMember();
User user = perun.getUsersManager().getUserByMember(sess, member);
attributes = setUpUserAttribute();
attributes.get(0).setId(0);
attributesManager.removeAttribute(sess, user, attributes.get(0));
// shouldn't find attribute
}
Aggregations