Search in sources :

Example 46 with AttributeDefinition

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

the class AttributesManagerEntry method getAttribute.

public Attribute getAttribute(PerunSession sess, Resource resource, String attributeName) throws PrivilegeException, ResourceNotExistsException, InternalErrorException, AttributeNotExistsException, WrongAttributeAssignmentException {
    Utils.checkPerunSession(sess);
    Utils.notNull(attributeName, "attributeName");
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    Attribute attr = getAttributesManagerBl().getAttribute(sess, resource, attributeName);
    //Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attr, resource, null))
        throw new PrivilegeException("Principal has no access to get attribute = " + new AttributeDefinition(attr));
    else
        attr.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attr, resource, null));
    return attr;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 47 with AttributeDefinition

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

the class AttributesManagerEntry method getAttributeById.

public Attribute getAttributeById(PerunSession sess, Group group, int id) throws PrivilegeException, InternalErrorException, AttributeNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    Attribute attr = getAttributesManagerBl().getAttributeById(sess, group, id);
    //Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attr, group, null))
        throw new PrivilegeException("Principal has no access to get attribute = " + new AttributeDefinition(attr));
    else
        attr.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attr, group, null));
    return attr;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 48 with AttributeDefinition

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

the class AttributesManagerEntry method removeAttribute.

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

Example 49 with AttributeDefinition

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

the class AttributesManagerEntry method removeAttribute.

public void removeAttribute(PerunSession sess, Group group, AttributeDefinition attribute) throws InternalErrorException, PrivilegeException, AttributeNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    Utils.checkPerunSession(sess);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    getAttributesManagerBl().checkAttributeExists(sess, attribute);
    //Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attribute, group, null))
        throw new PrivilegeException("Principal has no access to remove attribute = " + new AttributeDefinition(attribute));
    getAttributesManagerBl().removeAttribute(sess, group, attribute);
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 50 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)

Aggregations

AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)396 Attribute (cz.metacentrum.perun.core.api.Attribute)157 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)38 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)33 User (cz.metacentrum.perun.core.api.User)24 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)22 Vo (cz.metacentrum.perun.core.api.Vo)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Facility (cz.metacentrum.perun.core.api.Facility)12 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)12 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 Resource (cz.metacentrum.perun.core.api.Resource)10 LinkedHashMap (java.util.LinkedHashMap)10 Group (cz.metacentrum.perun.core.api.Group)8 Member (cz.metacentrum.perun.core.api.Member)8 PerunSession (cz.metacentrum.perun.core.api.PerunSession)7 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)6 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5