Search in sources :

Example 6 with User

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);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 7 with User

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");
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) HashSet(java.util.HashSet)

Example 8 with User

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;
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Matcher(java.util.regex.Matcher)

Example 9 with User

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;
}
Also used : PerunBean(cz.metacentrum.perun.core.api.PerunBean) User(cz.metacentrum.perun.core.api.User)

Example 10 with 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
}
Also used : User(cz.metacentrum.perun.core.api.User) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

User (cz.metacentrum.perun.core.api.User)332 Test (org.junit.Test)192 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)168 Attribute (cz.metacentrum.perun.core.api.Attribute)131 Member (cz.metacentrum.perun.core.api.Member)87 Facility (cz.metacentrum.perun.core.api.Facility)81 RichUser (cz.metacentrum.perun.core.api.RichUser)78 ArrayList (java.util.ArrayList)62 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)56 Resource (cz.metacentrum.perun.core.api.Resource)55 Group (cz.metacentrum.perun.core.api.Group)46 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)38 Vo (cz.metacentrum.perun.core.api.Vo)32 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)31 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)27 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)24 PerunSession (cz.metacentrum.perun.core.api.PerunSession)22 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)20 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17