Search in sources :

Example 1 with AttributeDefinitionExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException in project perun by CESNET.

the class AttributesManagerImpl method createAttribute.

@Override
public AttributeDefinition createAttribute(PerunSession sess, AttributeDefinition attribute) throws AttributeDefinitionExistsException {
    if (!attribute.getFriendlyName().matches(AttributesManager.ATTRIBUTES_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong attribute name " + attribute.getFriendlyName() + ", attribute name must match " + AttributesManager.ATTRIBUTES_REGEXP));
    }
    try {
        int attributeId = Utils.getNewId(jdbc, "attr_names_id_seq");
        jdbc.update("insert into attr_names (id, attr_name, type, dsc, namespace, friendly_name, display_name, is_unique, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid) " + "values (?,?,?,?,?,?,?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?)", attributeId, attribute.getName(), attribute.getType(), attribute.getDescription(), attribute.getNamespace(), attribute.getFriendlyName(), attribute.getDisplayName(), attribute.isUnique(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId());
        attribute.setId(attributeId);
        log.debug("Attribute created: {}.", attribute);
        return attribute;
    } catch (DataIntegrityViolationException e) {
        throw new AttributeDefinitionExistsException("Attribute " + attribute.getName() + " already exists", attribute, e);
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeDefinitionExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 2 with AttributeDefinitionExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException in project perun by CESNET.

the class AttributesManagerBlImpl method initialize.

protected void initialize() {
    log.debug("AttributesManagerBlImpl initialize started.");
    // Get PerunSession
    String attributesManagerInitializator = "attributesManagerBlImplInitializator";
    PerunPrincipal pp = new PerunPrincipal(attributesManagerInitializator, ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
    PerunSession sess = perunBl.getPerunSession(pp, new PerunClient());
    // Check if all core attributes exists, create if doesn't
    Map<AttributeDefinition, List<AttributeRights>> attributes = new HashMap<>();
    // Facility.id
    AttributeDefinition attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Facility id");
    // set attribute rights (with dummy id of attribute - not known yet)
    List<AttributeRights> rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Facility.name
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("name");
    attr.setDisplayName("Facility name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Resource.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Resource id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Resource.name
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("name");
    attr.setDisplayName("Resource name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Resource.description
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("description");
    attr.setDisplayName("Resource description");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Member.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Member id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("User id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.firstName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("firstName");
    attr.setDisplayName("User first name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.lastName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastName");
    attr.setDisplayName("User last name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.middleName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("middleName");
    attr.setDisplayName("User middle name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.titleBefore
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("titleBefore");
    attr.setDisplayName("User title before");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.titleAfter
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("titleAfter");
    attr.setDisplayName("User title after");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // User.serviceUser
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(Boolean.class.getName());
    attr.setFriendlyName("serviceUser");
    attr.setDisplayName("If user is service user or not.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // User.displayName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("displayName");
    attr.setDisplayName("Display name");
    attr.setDescription("Displayed user's name.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Group.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Group id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Group.name
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("name");
    attr.setDisplayName("Group full name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Group.trigger
    // this is a group attribute which contains ids of the groups to which deleted members are added from the group with the attribute
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(ArrayList.class.getName());
    attr.setFriendlyName("groupTrigger");
    attr.setDisplayName("Group Trigger");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Group.description
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("description");
    attr.setDisplayName("Group description");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Group.parentGroupId
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("parentGroupId");
    attr.setDisplayName("Id of group's parent group.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // Vo.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Vo id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // Vo.name
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("name");
    attr.setDisplayName("Vo full name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Vo.createdAt
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("createdAt");
    attr.setDisplayName("Vo created date");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // Vo.shortName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("shortName");
    attr.setDisplayName("Vo short name");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Host.id
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("id");
    attr.setDisplayName("Host id");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // Host.hostname
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
    attr.setType(String.class.getName());
    attr.setFriendlyName("hostname");
    attr.setDisplayName("Host hostname");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // *** Def attributes
    // urn:perun:user:attribute-def:def:organization
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("organization");
    attr.setDisplayName("Organization");
    attr.setDescription("Organization, from which user comes from. Provided by IDP.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:preferredMail
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("preferredMail");
    attr.setDisplayName("Preferred mail");
    attr.setDescription("E-mail address preferred for communication.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:phone
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("phone");
    attr.setDisplayName("Phone");
    attr.setDescription("Phone number in organization. Provided by IDP.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:workplace
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("workplace");
    attr.setDisplayName("Workplace");
    attr.setDescription("Workplace in organization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:note
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("note");
    attr.setDisplayName("Note");
    attr.setDescription("Contains special information about the user. It is used to be displayed in GUI");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ_PUBLIC)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:address
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("address");
    attr.setDisplayName("Address");
    attr.setDescription("Address in organization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:def:preferredLanguage
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("preferredLanguage");
    attr.setDisplayName("Preferred language");
    attr.setDescription("Language preferred in communication (notifications).");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:opt:researchGroup
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_OPT);
    attr.setType(String.class.getName());
    attr.setFriendlyName("researchGroup");
    attr.setDisplayName("Research group");
    attr.setDescription("Name of the research group where the user works.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:member:attribute-def:def:mail
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("mail");
    attr.setDisplayName("Mail");
    attr.setDescription("E-mail address in organization (VO wide).");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:member:attribute-def:def:organization
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("organization");
    attr.setDisplayName("Organization (for VO)");
    attr.setDescription("Organization, from which user comes from (VO wide).");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn_perun_member_attribute_def_def_suspensionInfo
    attr = (new urn_perun_member_attribute_def_def_suspensionInfo()).getAttributeDefinition();
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:member:attribute-def:def:membershipExpiration
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("membershipExpiration");
    attr.setDisplayName("Membership expiration");
    attr.setDescription("Date of VO membership expiration.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:member:attribute-def:def:sponzoredMember
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("sponzoredMember");
    attr.setDisplayName("Sponzored member");
    attr.setDescription("A note, which describes why the membership is sponzored.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:vo:attribute-def:def:membershipExpirationRules
    attr = new AttributeDefinition();
    attr.setDisplayName("Membership expiration rules");
    attr.setFriendlyName("membershipExpirationRules");
    attr.setNamespace("urn:perun:vo:attribute-def:def");
    attr.setDescription("Set of rules to determine date of membership expiration. If not set, membership is not limited.");
    attr.setType(LinkedHashMap.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupMembershipExpirationRules
    attr = new AttributeDefinition();
    attr.setDisplayName("Group membership expiration rules");
    attr.setFriendlyName("groupMembershipExpirationRules");
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setDescription("Set of rules to determine date of group membership expiration. If not set, membership is not limited.");
    attr.setType(LinkedHashMap.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:vo:attribute-def:def:applicationExpirationRules
    attr = new AttributeDefinition();
    attr.setDisplayName("Application expiration rules");
    attr.setFriendlyName("applicationExpirationRules");
    attr.setNamespace(AttributesManager.NS_VO_ATTR_DEF);
    attr.setDescription("Set of rules to determine date of application (to vo) expiration. If not set, application will not be auto rejected.");
    attr.setType(LinkedHashMap.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:applicationExpirationRules
    attr = new AttributeDefinition();
    attr.setDisplayName("Application expiration rules");
    attr.setFriendlyName("applicationExpirationRules");
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setDescription("Set of rules to determine date of application (to group) expiration. If not set, application will not be auto rejected.");
    attr.setType(LinkedHashMap.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:member:group:attribute-def:def:groupMembershipExpiration
    attr = new AttributeDefinition();
    attr.setDisplayName("Group membership expiration");
    attr.setFriendlyName("groupMembershipExpiration");
    attr.setNamespace(AttributesManager.NS_MEMBER_GROUP_ATTR_DEF);
    attr.setDescription("When the member expires in group, format YYYY-MM-DD.");
    attr.setType(String.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:vo:attribute-def:def:blockManualMemberAdding
    attr = new AttributeDefinition();
    attr.setDisplayName("Block manual member adding");
    attr.setFriendlyName("blockManualMemberAdding");
    attr.setNamespace(AttributesManager.NS_VO_ATTR_DEF);
    attr.setDescription("Block manual addition of Vo members. Users are expected to go through registration.");
    attr.setType(Boolean.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:blockManualMemberAdding
    attr = new AttributeDefinition();
    attr.setDisplayName("Block manual member adding");
    attr.setFriendlyName("blockManualMemberAdding");
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setDescription("Block manual addition of group members. Users are expected to go through registration.");
    attr.setType(Boolean.class.getName());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupExtSource
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupExtSource");
    attr.setDisplayName("Group extSource");
    attr.setDescription("External source from which group comes from. Used for groups synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupMembersExtSource
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupMembersExtSource");
    attr.setDisplayName("Group members extSource");
    attr.setDescription("External source from which group members comes from. Used for group synchronization. If not set, members are loaded from the same external source as group itself.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupMembersQuery
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupMembersQuery");
    attr.setDisplayName("Group members query");
    attr.setDescription("Query (SQL) on external source which retrieves list of it's members.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:synchronizationEnabled
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("synchronizationEnabled");
    attr.setDisplayName("Group synchronization enabled");
    attr.setDescription("Enables group synchronization from external source.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:synchronizationInterval
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("synchronizationInterval");
    attr.setDisplayName("Synchronization interval");
    attr.setDescription("Time between two successful synchronizations.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastSynchronizationState
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastSynchronizationState");
    attr.setDisplayName("Last synchronization state");
    attr.setDescription("If group is synchronized, there will be information about state of last synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastSynchronizationTimestamp
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastSynchronizationTimestamp");
    attr.setDisplayName("Last Synchronization timestamp");
    attr.setDescription("If group is synchronized, there will be the last timestamp of group synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lightweightSynchronization
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(Boolean.class.getName());
    attr.setFriendlyName("lightweightSynchronization");
    attr.setDisplayName("Lightweight Synchronization");
    attr.setDescription("If true, then do not update actual members.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastSuccessSynchronizationTimestamp
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastSuccessSynchronizationTimestamp");
    attr.setDisplayName("Last successful synchronization timestamp");
    attr.setDescription("If group is synchronized, there will be timestamp of last successful synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:startOfLastSuccessfulSynchronization
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("startOfLastSuccessfulSynchronization");
    attr.setDisplayName("Start of last successful synchronization");
    attr.setDescription("If group is synchronized, start time of last successful synchronization will be set.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:startOfLastSynchronization
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("startOfLastSynchronization");
    attr.setDisplayName("Start of last synchronization");
    attr.setDescription("If group started synchronization, start time of last synchronization will be set.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructureSynchronizationEnabled
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(Boolean.class.getName());
    attr.setFriendlyName("groupStructureSynchronizationEnabled");
    attr.setDisplayName("Group structure synchronization enabled");
    attr.setDescription("Enables group structure synchronization from external source.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructuresynchronizationInterval
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupStructureSynchronizationInterval");
    attr.setDisplayName("Group structure synchronization interval");
    attr.setDescription("Time between two successful group structure synchronizations.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastGroupStructureSynchronizationState
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastGroupStructureSynchronizationState");
    attr.setDisplayName("Last group structure synchronization state");
    attr.setDescription("If group structure is synchronized, there will be information about state of last synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastGroupStructureSynchronizationTimestamp
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastGroupStructureSynchronizationTimestamp");
    attr.setDisplayName("Last group structure Synchronization timestamp");
    attr.setDescription("If group structure is synchronized, there will be the last timestamp of group synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:flatGroupStructureEnabled
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(Boolean.class.getName());
    attr.setFriendlyName("flatGroupStructureEnabled");
    attr.setDisplayName("Flat group structure enabled");
    attr.setDescription("If true, then every synchronized group will be right under base group.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:lastSuccessGroupStructureSynchronizationTimestamp
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("lastSuccessGroupStructureSynchronizationTimestamp");
    attr.setDisplayName("Last successful group structure synchronization timestamp");
    attr.setDescription("If group structure is synchronized, there will be timestamp of last successful synchronization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupSynchronizationTimes
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(ArrayList.class.getName());
    attr.setFriendlyName("groupSynchronizationTimes");
    attr.setDisplayName("Group synchronization times");
    attr.setDescription("List of time values for group synchronization in format HH:MM rounded to 5 minute. For example 08:50 or 20:55");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructureSynchronizationTimes
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(ArrayList.class.getName());
    attr.setFriendlyName("groupStructureSynchronizationTimes");
    attr.setDisplayName("Group structure synchronization times");
    attr.setDescription("List of time values for group structure synchronization in format HH:MM rounded to 5 minute. For example 08:50 or 20:55");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructureLogin
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupStructureLogin");
    attr.setDisplayName("Group structure login");
    attr.setDescription("Name of attribute in perun used for identifying groups in a structure");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructureLoginPrefix
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupStructureLoginPrefix");
    attr.setDisplayName("Group structure login prefix");
    attr.setDescription("Prefix which will be used to set groups login as 'prefix'+'login'.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupsQuery
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("groupsQuery");
    attr.setDisplayName("Groups query");
    attr.setDescription("Query (SQL) on external source which retrieves list of it's groups.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:authoritativeGroup
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    attr.setType(Integer.class.getName());
    attr.setFriendlyName("authoritativeGroup");
    attr.setDisplayName("Authoritative Group");
    attr.setDescription("If group is authoritative for member. (for synchronization)");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:groupStructureResources
    attr = new urn_perun_group_attribute_def_def_groupStructureResources().getAttributeDefinition();
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:def:applicationAutoRejectMessages
    attr = new urn_perun_group_attribute_def_def_applicationAutoRejectMessages().getAttributeDefinition();
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:facility:attribute-def:def:login-namespace
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("login-namespace");
    attr.setDisplayName("Login namespace");
    attr.setDescription("Define namespace for all user's logins on Facility.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:resource:attribute-def:def:userSettingsName
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("userSettingsName");
    attr.setDisplayName("User settings name");
    attr.setDescription("Name displayed in user profile resource settings. To display certain resource in user profile settings this attribute value needs to be set.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:resource:attribute-def:def:userSettingsDescription
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("userSettingsDescription");
    attr.setDisplayName("User settings description");
    attr.setDescription("Description displayed in user profile resource settings.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:vo:attribute-def:def:aupLink
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_VO_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("aupLink");
    attr.setDisplayName("Link to AUP");
    attr.setDescription("Link to AUP of a virtual organization.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:vo:attribute-def:def:applicationAutoRejectMessages
    attr = new urn_perun_vo_attribute_def_def_applicationAutoRejectMessages().getAttributeDefinition();
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE)));
    attributes.put(attr, rights);
    // urn:perun:user_facility:attribute-def:virt:login
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_FACILITY_ATTR_VIRT);
    attr.setType(String.class.getName());
    attr.setFriendlyName("login");
    attr.setDisplayName("Login");
    attr.setDescription("User's logname at facility. Value is determined automatically from all user's logins by Facility's namespace.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:user:attribute-def:virt:groupNames
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_USER_ATTR_VIRT);
    attr.setType(ArrayList.class.getName());
    attr.setFriendlyName("groupNames");
    attr.setDisplayName("Group names");
    attr.setDescription("Names of groups where user is member");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn:perun:group:attribute-def:virt:autoRegistrationEnabled
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_GROUP_ATTR_VIRT);
    attr.setType(Boolean.class.getName());
    attr.setFriendlyName("autoRegistrationEnabled");
    attr.setDisplayName("Automatic registration enabled");
    attr.setDescription("If true, group can be selected for automatic registration.");
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn_perun_facility_attribute_def_virt_GIDRanges
    attr = new AttributeDefinition((new urn_perun_facility_attribute_def_virt_GIDRanges()).getAttributeDefinition());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn_perun_entityless_attribute_def_def_namespace_GIDRanges
    attr = new AttributeDefinition((new urn_perun_entityless_attribute_def_def_namespace_GIDRanges()).getAttributeDefinition());
    // set attribute rights (with dummy id of attribute - not known yet)
    rights = new ArrayList<>();
    rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
    rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
    attributes.put(attr, rights);
    // urn_perun_entityless_attribute_def_def_randomPwdResetTemplate
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("randomPwdResetTemplate");
    attr.setDisplayName("Random password reset templates");
    attr.setDescription("Random password reset templates. Each value should be String representing an HTML page." + " Keywords {password} and {login} will be replaced.");
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // urn:perun:entityless:attribute-def:def:identityAlerts
    attr = new urn_perun_entityless_attribute_def_def_identityAlertsTemplates().getAttributeDefinition();
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("preferredMailChangeMailSubject");
    attr.setDisplayName("PreferredMail change mail subject");
    attr.setDescription("Subject of the preferred mail change notification. Keyword {instanceName} will be replaced.");
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attr.setType(String.class.getName());
    attr.setFriendlyName("preferredMailChangeMailTemplate");
    attr.setDisplayName("PreferredMail change mail template");
    attr.setDescription("Template of the preferred mail change notification. Keyword {link} will be replaced with the link to verify new mail address.");
    rights = new ArrayList<>();
    attributes.put(attr, rights);
    // create namespaced attributes for each namespace
    for (String namespace : BeansUtils.getCoreConfig().getAutocreatedNamespaces()) {
        // skip if empty
        if (namespace == null || namespace.isEmpty())
            continue;
        // login-namespace
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("login-namespace:" + namespace);
        attr.setDisplayName("Login in namespace: " + namespace);
        attr.setDescription("Logname in namespace '" + namespace + "'.");
        rights = new ArrayList<>();
        rights.add(new AttributeRights(-1, Role.SELF, Collections.singletonList(ActionType.READ)));
        rights.add(new AttributeRights(-1, Role.VOADMIN, Collections.singletonList(ActionType.READ)));
        rights.add(new AttributeRights(-1, Role.GROUPADMIN, Collections.singletonList(ActionType.READ)));
        rights.add(new AttributeRights(-1, Role.FACILITYADMIN, Collections.singletonList(ActionType.READ)));
        attributes.put(attr, rights);
        // pwd-reset templates
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzPwdResetConfirmMailSubject:" + namespace);
        attr.setDisplayName("Non-Authz Pwd Reset Confirmation Mail Subject");
        attr.setDescription("Template of PWD reset confirmation mails subject.");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzPwdResetConfirmMailTemplate:" + namespace);
        attr.setDisplayName("Non-Authz Pwd Reset Confirmation Mail Template");
        attr.setDescription("Template of confirmation message in password reset notification.");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzPwdResetMailSubject:" + namespace);
        attr.setDisplayName("Non-Authz Pwd Reset Mail Subject");
        attr.setDescription("Non authz password reset mail subject for " + namespace + ".");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzPwdResetMailTemplate:" + namespace);
        attr.setDisplayName("Non-Authz Pwd Reset Mail Template");
        attr.setDescription("Non authz password reset mail template for " + namespace + ".");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzAccActivationMailSubject:" + namespace);
        attr.setDisplayName("Non-Authz Acc Activation Mail Subject");
        attr.setDescription("Non authz account activation mail subject for " + namespace + ".");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
        attr = new AttributeDefinition();
        attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
        attr.setType(String.class.getName());
        attr.setFriendlyName("nonAuthzAccActivationMailTemplate:" + namespace);
        attr.setDisplayName("Non-Authz Acc Activation Mail Template");
        attr.setDescription("Non authz account activation mail template for " + namespace + ".");
        rights = new ArrayList<>();
        attributes.put(attr, rights);
    }
    if (perunBl.isPerunReadOnly())
        log.debug("Loading attributes manager init in readOnly version.");
    for (Map.Entry<AttributeDefinition, List<AttributeRights>> entry : attributes.entrySet()) {
        AttributeDefinition attribute = entry.getKey();
        List<AttributeRights> listOfRights = entry.getValue();
        try {
            // If attribute definition is not found, catch exception and create this attribute definition
            getAttributeDefinition(sess, attribute.getName());
        } catch (AttributeNotExistsException e) {
            if (perunBl.isPerunReadOnly()) {
                throw new InternalErrorException("There is missing required attribute " + attribute + " and can't be created because this instance is read only.");
            } else {
                try {
                    attribute = createAttribute(sess, attribute, false);
                } catch (AttributeDefinitionExistsException ex) {
                    // should not happen
                    throw new InternalErrorException("Attribute " + attribute + " already exists in Perun when attributeInitializer tried to create it.");
                }
                // set correct id of attribute to rights
                for (AttributeRights listOfRight : listOfRights) {
                    listOfRight.setAttributeId(attribute.getId());
                }
                setAttributeRights(sess, listOfRights);
            }
        }
    }
    // Prepare all attribute definition from system perun
    Set<AttributeDefinition> allAttributesDef = new HashSet<>(this.getAttributesDefinition(sess));
    // Load all attributes modules
    ServiceLoader<AttributesModuleImplApi> attributeModulesLoader = ServiceLoader.load(AttributesModuleImplApi.class);
    getAttributesManagerImpl().initAndRegisterAttributeModules(sess, attributeModulesLoader, allAttributesDef);
    initializeModuleDependencies(sess, allAttributesDef);
    log.debug("AttributesManagerBlImpl initialize ended.");
}
Also used : cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_group_attribute_def_def_applicationAutoRejectMessages(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_group_attribute_def_def_applicationAutoRejectMessages) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_facility_attribute_def_virt_GIDRanges(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_facility_attribute_def_virt_GIDRanges) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_namespace_GIDRanges(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_namespace_GIDRanges) LinkedHashMap(java.util.LinkedHashMap) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_identityAlertsTemplates(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_identityAlertsTemplates) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_group_attribute_def_def_groupStructureResources(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_group_attribute_def_def_groupStructureResources) AttributeRights(cz.metacentrum.perun.core.api.AttributeRights) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) UserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleImplApi) AttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.AttributesModuleImplApi) VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi) PerunSession(cz.metacentrum.perun.core.api.PerunSession) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_applicationAutoRejectMessages(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_applicationAutoRejectMessages) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeDefinitionExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_member_attribute_def_def_suspensionInfo(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_member_attribute_def_def_suspensionInfo) PerunClient(cz.metacentrum.perun.core.api.PerunClient) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 3 with AttributeDefinitionExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException in project perun by CESNET.

the class ModulesUtilsEntryIntegrationTest method getUserByLoginInNamespace.

@Test
public void getUserByLoginInNamespace() throws Exception {
    System.out.println(CLASS_NAME + "getUserByLoginInNamespace");
    // create user
    User user = new User();
    user.setFirstName("Firstname");
    user.setLastName("Lastname");
    user = perun.getUsersManagerBl().createUser(sess, user);
    assertNotNull(user);
    // create "dummy" login namespace
    AttributeDefinition attributeDefinition = new AttributeDefinition();
    attributeDefinition.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attributeDefinition.setFriendlyName(AttributesManager.LOGIN_NAMESPACE + ":dummy");
    attributeDefinition.setDisplayName(AttributesManager.LOGIN_NAMESPACE + ":dummy");
    attributeDefinition.setDescription(AttributesManager.LOGIN_NAMESPACE + ":dummy");
    attributeDefinition.setType(String.class.getName());
    try {
        assertNotNull(perun.getAttributesManager().createAttribute(sess, attributeDefinition));
    } catch (AttributeDefinitionExistsException ex) {
    // this is OK
    }
    User userByLogin = perun.getModulesUtilsBl().getUserByLoginInNamespace(sess, "testlogin", "dummy");
    assertNull("No user should be found.", userByLogin);
    // create login in dummy namespace
    Attribute attribute = perun.getAttributesManager().getAttribute(sess, user, attributeDefinition.getName());
    assertNull(attribute.getValue());
    attribute.setValue("testlogin");
    perun.getAttributesManager().setAttribute(sess, user, attribute);
    userByLogin = perun.getModulesUtilsBl().getUserByLoginInNamespace(sess, "testlogin", "dummy");
    assertEquals(user, userByLogin);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeDefinitionExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with AttributeDefinitionExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException in project perun by CESNET.

the class PerunBlImpl method setUserExtSourceAttributes.

/**
 * Store values from map "additionalAttributes" as UserExtSource attributes to specified UES.
 * Used internally when session is initialized and when user is self-created through registration.
 * Only specific map keys are stored, based on Perun config for UES type.
 *
 * @param session PerunSession for authorization
 * @param ues UserExtSource to store attributes for
 * @param additionalAttributes Map of attribute names=values
 * @throws InternalErrorException When implementation fails
 */
public void setUserExtSourceAttributes(PerunSession session, UserExtSource ues, Map<String, String> additionalAttributes) {
    // update selected attributes for given extsourcetype
    List<AttributeDefinition> attrs = coreConfig.getAttributesForUpdate().get(ues.getExtSource().getType());
    if (attrs != null) {
        for (AttributeDefinition attr : attrs) {
            // get value from authentication
            String attrValue = additionalAttributes.get(attr.getFriendlyName());
            if ("".equals(attrValue))
                attrValue = null;
            // save the value to attribute (create the attribute if it does not exist)
            try {
                Attribute attributeWithValue;
                try {
                    attributeWithValue = attributesManagerBl.getAttribute(session, ues, attr.getName());
                } catch (AttributeNotExistsException ex) {
                    try {
                        attributeWithValue = new Attribute(attributesManagerBl.createAttribute(session, attr));
                    } catch (AttributeDefinitionExistsException e) {
                        attributeWithValue = attributesManagerBl.getAttribute(session, ues, attr.getName());
                    }
                }
                // for Array list attributes try to parse string value into individual fields
                if (attributeWithValue.getType().equals(ArrayList.class.getName())) {
                    List<String> value = new ArrayList<>();
                    if (attrValue != null) {
                        value = new ArrayList<>(Arrays.asList(attrValue.split(UsersManagerBl.MULTIVALUE_ATTRIBUTE_SEPARATOR_REGEX)));
                    }
                    attributeWithValue.setValue(value);
                } else {
                    attributeWithValue.setValue(attrValue);
                }
                log.debug("storing attribute {}='{}' for user {}", attributeWithValue.getFriendlyName(), attrValue, ues.getLogin());
                attributesManagerBl.setAttributeInNestedTransaction(session, ues, attributeWithValue);
            } catch (AttributeNotExistsException | WrongAttributeAssignmentException | WrongAttributeValueException | WrongReferenceAttributeValueException e) {
                log.error("Attribute " + attr.getName() + " with value '" + attrValue + "' cannot be saved", e);
            }
        }
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeDefinitionExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 5 with AttributeDefinitionExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException in project perun by CESNET.

the class urn_perun_ues_attribute_def_def_isCesnetEligibleLastSeenTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_ues_attribute_def_def_isCesnetEligibleLastSeen();
    mockedSession = mock(PerunSessionImpl.class);
    uesAttribute = new Attribute();
    setUpUser();
    userExtSource = new UserExtSource();
    userExtSource.setUserId(user.getId());
    AttributeDefinition def = new AttributeDefinition();
    def.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    def.setType(String.class.getName());
    def.setDescription("isCesnetEligibleLastSeen");
    def.setDisplayName("isCesnetEligibleLastSeen");
    def.setFriendlyName("isCesnetEligibleLastSeen");
    try {
        perun.getAttributesManagerBl().createAttribute(sess, def);
    } catch (AttributeDefinitionExistsException ex) {
    // OK
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeDefinitionExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Before(org.junit.Before)

Aggregations

AttributeDefinitionExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeDefinitionExistsException)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 Attribute (cz.metacentrum.perun.core.api.Attribute)3 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 ArrayList (java.util.ArrayList)2 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 AttributeRights (cz.metacentrum.perun.core.api.AttributeRights)1 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)1 PerunSession (cz.metacentrum.perun.core.api.PerunSession)1 User (cz.metacentrum.perun.core.api.User)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)1 cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_identityAlertsTemplates (cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_identityAlertsTemplates)1 cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_namespace_GIDRanges (cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_entityless_attribute_def_def_namespace_GIDRanges)1 cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_facility_attribute_def_virt_GIDRanges (cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_facility_attribute_def_virt_GIDRanges)1