Search in sources :

Example 1 with PerunSessionImpl

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));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with PerunSessionImpl

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));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with PerunSessionImpl

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));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with PerunSessionImpl

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);
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl)

Example 5 with PerunSessionImpl

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));
}
Also used : PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)7 Test (org.junit.Test)7 Attribute (cz.metacentrum.perun.core.api.Attribute)6 ArrayList (java.util.ArrayList)5 Group (cz.metacentrum.perun.core.api.Group)3 Resource (cz.metacentrum.perun.core.api.Resource)3 ExtSource (cz.metacentrum.perun.core.api.ExtSource)1 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)1 UserExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 Before (org.junit.Before)1