urn_perun_user_facility_attribute_def_def_basicDefaultGID extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, User user, Facility facility, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { Attribute namespaceAttribute; try { namespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException(ex); } if (namespaceAttribute.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, namespaceAttribute, "Reference attribute is null"); } String namespaceName = namespaceAttribute.valueAsString(); Attribute resourceGidAttribute; try { resourceGidAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespaceName)); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Namespace from value of " + namespaceAttribute + " doesn't exists. (Resource attribute " + AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespaceName + " doesn't exists", ex); } resourceGidAttribute.setValue(attribute.getValue()); List<Resource> allowedResources = sess.getPerunBl().getUsersManagerBl().getAllowedResources(sess, facility, user); List<Resource> resourcesWithSameGid = sess.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, resourceGidAttribute); if (resourcesWithSameGid.isEmpty() && allowedResources.isEmpty() && resourceGidAttribute.getValue() == null) return; if (resourcesWithSameGid.isEmpty() && resourceGidAttribute.getValue() != null) throw new WrongReferenceAttributeValueException(attribute, null, user, facility, "Resource with required unix GID doesn't exist."); if (allowedResources.isEmpty()) throw new WrongReferenceAttributeValueException(attribute, null, user, facility, "User has not access to required resource"); resourcesWithSameGid.retainAll(allowedResources); if (resourcesWithSameGid.isEmpty()) { throw new WrongReferenceAttributeValueException(attribute, null, user, facility, "User has not access to resource with required group id"); } }  @Override void checkAttributeSemantics(PerunSessionImpl sess, User user, Facility facility, Attribute attribute); @Override Attribute fillAttribute(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test ( expected = WrongReferenceAttributeValueException.class) public void checkValueAttributeIsNotSetTest() throws Exception{ System.out.println("urn_perun_user_facility_attribute_def_def_basicDefaultGID.checkValueAttributeIsNotSetTest()"); allowedResources.clear(); allowedResourcesWithSameGid.clear(); allowedResources.add(resource1); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), eq(AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"))).thenReturn(namespaceAttribute); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSessionImpl.class), any(Facility.class), any(User.class))).thenReturn(allowedResources); when(session.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(any(PerunSessionImpl.class), any(Attribute.class))).thenReturn(allowedResourcesWithSameGid); classInstance.checkAttributeSemantics(session, user, facility, basic); }
@Test public void checkValueAttributeIsSetTest() throws Exception{ System.out.println("urn_perun_user_facility_attribute_def_def_basicDefaultGID.checkValueAttributeIsSetTest()"); basic.setValue(1); allowedResources.clear(); allowedResourcesWithSameGid.clear(); allowedResources.add(resource1); allowedResources.add(resource2); allowedResourcesWithSameGid.add(resource2); allowedResourcesWithSameGid.add(resource3); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), eq(AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"))).thenReturn(namespaceAttribute); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSessionImpl.class), any(Facility.class), any(User.class))).thenReturn(allowedResources); when(session.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(any(PerunSessionImpl.class), any(Attribute.class))).thenReturn(allowedResourcesWithSameGid); classInstance.checkAttributeSemantics(session, user, facility, basic); }
@Test(expected = WrongReferenceAttributeValueException.class) public void checkValueAttributeIsSetWithoutAllowedResourcesTest() throws Exception{ System.out.println("urn_perun_user_facility_attribute_def_def_basicDefaultGID.checkValueAttributeIsSetWithoutAllowedResourcesTest()"); basic.setValue(1); allowedResources.clear(); allowedResourcesWithSameGid.clear(); allowedResourcesWithSameGid.add(resource2); allowedResourcesWithSameGid.add(resource3); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), eq(AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"))).thenReturn(namespaceAttribute); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSessionImpl.class), any(Facility.class), any(User.class))).thenReturn(allowedResources); when(session.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(any(PerunSessionImpl.class), any(Attribute.class))).thenReturn(allowedResourcesWithSameGid); classInstance.checkAttributeSemantics(session, user, facility, basic); }
@Test(expected = WrongReferenceAttributeValueException.class) public void checkValueAttributeIsSetWithBadValueTest() throws Exception{ System.out.println("urn_perun_user_facility_attribute_def_def_basicDefaultGID.checkValueAttributeIsSetWithBadValueTest()"); basic.setValue(1); allowedResources.clear(); allowedResourcesWithSameGid.clear(); allowedResources.add(resource1); allowedResources.add(resource2); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), eq(AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"))).thenReturn(namespaceAttribute); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSessionImpl.class), any(Facility.class), any(User.class))).thenReturn(allowedResources); when(session.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(any(PerunSessionImpl.class), any(Attribute.class))).thenReturn(allowedResourcesWithSameGid); classInstance.checkAttributeSemantics(session, user, facility, basic); }