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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations