Search in sources :

Example 6 with AttributeDefinition

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

the class AttributesManagerEntry method checkAttributeValue.

public void checkAttributeValue(PerunSession sess, Resource resource, Attribute attribute) throws PrivilegeException, InternalErrorException, ResourceNotExistsException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException, AttributeNotExistsException {
    Utils.checkPerunSession(sess);
    getAttributesManagerBl().checkAttributeExists(sess, attribute);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    //Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attribute), resource, null))
        throw new PrivilegeException("Principal has no access to check attribute = " + new AttributeDefinition(attribute));
    getAttributesManagerBl().checkAttributeValue(sess, resource, attribute);
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 7 with AttributeDefinition

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

the class AttributesManagerEntry method checkAttributesValue.

public void checkAttributesValue(PerunSession sess, Facility facility, User user, List<Attribute> attributes) throws PrivilegeException, InternalErrorException, FacilityNotExistsException, UserNotExistsException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException, AttributeNotExistsException {
    Utils.checkPerunSession(sess);
    getAttributesManagerBl().checkAttributesExists(sess, attributes);
    getPerunBl().getFacilitiesManagerBl().checkFacilityExists(sess, facility);
    getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
    //Choose to which attributes has the principal access
    for (Attribute attr : attributes) {
        if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attr), facility, user))
            throw new PrivilegeException("Principal has no access to check attribute = " + new AttributeDefinition(attr));
    }
    getAttributesManagerBl().checkAttributesValue(sess, facility, user, attributes);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 8 with AttributeDefinition

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

the class SearcherImpl method getMembersByExpiration.

@Override
public List<Member> getMembersByExpiration(PerunSession sess, String operator, Calendar date, int days) throws InternalErrorException {
    // this would default to now
    if (date == null)
        date = Calendar.getInstance();
    date.add(Calendar.DAY_OF_MONTH, days);
    // create sql toDate()
    String compareDate = BeansUtils.getDateFormatterWithoutTime().format(date.getTime());
    compareDate = "TO_DATE('" + compareDate + "','YYYY-MM-DD')";
    if (operator == null || operator.isEmpty())
        operator = "=";
    if (!operator.equals("<") && !operator.equals("<=") && !operator.equals("=") && !operator.equals(">=") && !operator.equals(">"))
        throw new InternalErrorException("Operator '" + operator + "' is not allowed in SQL.");
    try {
        AttributeDefinition def = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:member:attribute-def:def:membershipExpiration");
        String query = "select distinct " + MembersManagerImpl.memberMappingSelectQuery + " from members left join member_attr_values val on " + "val.member_id=members.id and val.attr_id=? where TO_DATE(val.attr_value, 'YYYY-MM-DD')" + operator + compareDate;
        return jdbcTemplate.query(query.toString(), MembersManagerImpl.MEMBER_MAPPER, def.getId());
    } catch (Exception e) {
        throw new InternalErrorException(e);
    }
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 9 with AttributeDefinition

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

the class urn_perun_entityless_attribute_def_def_namespace_maxGID method getAttributeDefinition.

@Override
public AttributeDefinition getAttributeDefinition() {
    AttributeDefinition attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attr.setFriendlyName("namespace_maxGID");
    attr.setDisplayName("Max GID in namespace");
    attr.setType(Integer.class.getName());
    attr.setDescription("Maximal value of Group ID.");
    return attr;
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 10 with AttributeDefinition

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

the class urn_perun_entityless_attribute_def_def_namespace_minGID method getAttributeDefinition.

@Override
public AttributeDefinition getAttributeDefinition() {
    AttributeDefinition attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attr.setFriendlyName("namespace_minGID");
    attr.setDisplayName("Min GID in namespace");
    attr.setType(Integer.class.getName());
    attr.setDescription("Minimal value of Group ID.");
    return attr;
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Aggregations

AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)764 Attribute (cz.metacentrum.perun.core.api.Attribute)311 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)171 ArrayList (java.util.ArrayList)111 Test (org.junit.Test)99 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)59 LinkedHashMap (java.util.LinkedHashMap)59 User (cz.metacentrum.perun.core.api.User)58 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)56 HashMap (java.util.HashMap)42 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)40 Facility (cz.metacentrum.perun.core.api.Facility)38 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)37 Resource (cz.metacentrum.perun.core.api.Resource)28 Member (cz.metacentrum.perun.core.api.Member)25 Group (cz.metacentrum.perun.core.api.Group)24 Vo (cz.metacentrum.perun.core.api.Vo)23 HashSet (java.util.HashSet)23 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)20