use of cz.metacentrum.perun.core.impl.PerunSessionImpl in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method getCommonGIDOfResourcesWithSameNameInSameNamespace.
@Test
public void getCommonGIDOfResourcesWithSameNameInSameNamespace() throws Exception {
System.out.println(CLASS_NAME + "getCommonGIDOfResourcesWithSameNameInSameNamespace");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
List<Resource> resources = new ArrayList<Resource>();
resources.add(resource);
Attribute minGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minGID"));
Attribute maxGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-maxGID"));
minGID.setValue(100);
maxGID.setValue(100500);
perun.getAttributesManagerBl().setAttribute(sess, namespace, minGID);
perun.getAttributesManagerBl().setAttribute(sess, namespace, maxGID);
List<Attribute> attributes = setUpGroupNamesAndGIDForGroupAndResource();
Attribute resourceGID = null;
for (Attribute a : attributes) {
if (a.getName().equals(AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespace)) {
resourceGID = a;
break;
}
}
perun.getAttributesManagerBl().setAttribute(sess, resource, resourceGID);
assertEquals(new Integer(112), modulesUtilsBl.getCommonGIDOfResourcesWithSameNameInSameNamespace((PerunSessionImpl) sess, resources, namespace, null));
}
use of cz.metacentrum.perun.core.impl.PerunSessionImpl in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method isGroupUnixGIDNamespaceFillable.
@Test
public void isGroupUnixGIDNamespaceFillable() throws Exception {
System.out.println(CLASS_NAME + "isGroupUnixGIDNamespaceFillable");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
group = setUpGroup();
Attribute minGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minGID"));
Attribute maxGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-maxGID"));
minGID.setValue(100);
maxGID.setValue(100500);
perun.getAttributesManagerBl().setAttribute(sess, namespace, minGID);
perun.getAttributesManagerBl().setAttribute(sess, namespace, maxGID);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
List<Attribute> attributes = setUpGroupNamesAndGIDForGroupAndResource();
List<Attribute> facilityAttributes = setUpFacilityGroupNameAndGIDNamespaceAttributes();
for (Attribute a : facilityAttributes) {
perun.getAttributesManagerBl().setAttribute(sess, facility, a);
}
Attribute unixGIDNamespace = null;
for (Attribute a : attributes) {
if (a.getNamespace().equals(AttributesManager.NS_GROUP_ATTR_DEF)) {
perun.getAttributesManagerBl().setAttribute(sess, group, a);
if (a.getFriendlyName().startsWith("unixGID"))
unixGIDNamespace = a;
}
}
assertTrue(modulesUtilsBl.isGroupUnixGIDNamespaceFillable((PerunSessionImpl) sess, group, unixGIDNamespace));
}
use of cz.metacentrum.perun.core.impl.PerunSessionImpl in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method getCommonGIDOfGroupsWithSameNameInSameNamespace.
@Test
public void getCommonGIDOfGroupsWithSameNameInSameNamespace() throws Exception {
System.out.println(CLASS_NAME + "getCommonGIDOfGroupsWithSameNameInSameNamespace");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
group = setUpGroup();
List<Group> groups = new ArrayList<Group>();
groups.add(group);
Attribute minGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minGID"));
Attribute maxGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-maxGID"));
minGID.setValue(100);
maxGID.setValue(100500);
perun.getAttributesManagerBl().setAttribute(sess, namespace, minGID);
perun.getAttributesManagerBl().setAttribute(sess, namespace, maxGID);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
List<Attribute> attributes = setUpGroupNamesAndGIDForGroupAndResource();
Attribute groupGID = null;
for (Attribute a : attributes) {
if (a.getName().equals(AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + namespace)) {
groupGID = a;
break;
}
}
perun.getAttributesManagerBl().setAttribute(sess, group, groupGID);
assertEquals(new Integer(111), modulesUtilsBl.getCommonGIDOfGroupsWithSameNameInSameNamespace((PerunSessionImpl) sess, groups, namespace, null));
}
use of cz.metacentrum.perun.core.impl.PerunSessionImpl in project perun by CESNET.
the class PerunBlImpl method getPerunSession.
public PerunSession getPerunSession(PerunPrincipal principal, PerunClient client) throws InternalErrorException {
if (principal.getUser() == null && this.getUsersManagerBl() != null && !dontLookupUsersForLogins.contains(principal.getActor())) {
// Get the user if we are completely initialized
try {
principal.setUser(this.getUsersManagerBl().getUserByExtSourceNameAndExtLogin(getPerunSession(), principal.getExtSourceName(), principal.getActor()));
// Try to update LoA for userExtSource
ExtSource es = this.getExtSourcesManagerBl().getExtSourceByName(getPerunSession(), principal.getExtSourceName());
UserExtSource ues = this.getUsersManagerBl().getUserExtSourceByExtLogin(getPerunSession(), es, principal.getActor());
if (ues.getLoa() != principal.getExtSourceLoa()) {
ues.setLoa(principal.getExtSourceLoa());
this.getUsersManagerBl().updateUserExtSource(getPerunSession(), ues);
}
// Update last access for userExtSource
this.getUsersManagerBl().updateUserExtSourceLastAccess(getPerunSession(), ues);
} catch (ExtSourceNotExistsException | UserExtSourceNotExistsException | UserNotExistsException e) {
// OK - We don't know user yet
}
}
return new PerunSessionImpl(this, principal, client);
}
use of cz.metacentrum.perun.core.impl.PerunSessionImpl in project perun by CESNET.
the class AuthzResolverIntegrationTest method isAuthorizedInvalidPrincipal.
@Test
public void isAuthorizedInvalidPrincipal() throws Exception {
System.out.println(CLASS_NAME + "isAuthorizedInvalidPrincipal");
assertTrue(!AuthzResolver.isAuthorized(new PerunSessionImpl(perun, new PerunPrincipal("pepa", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient()), Role.PERUNADMIN));
}
Aggregations