Search in sources :

Example 56 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method testRegisterComponent.

public void testRegisterComponent() {
    try {
        //test invalid
        try {
            manager.registerComponent(0, null, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, null, type, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, dummyURI, type, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, null, null, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //register with empty curl
        ClientInfo cinfo = manager.login(new TestClient(clientName));
        try {
            manager.registerComponent(cinfo.getHandle(), new URI(""), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: empty URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register with wrong domain
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("curl://other/KIKI"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: URI does not exist " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        // wrong schema
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("KIKI://other/KIKI"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        // no path
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("KIKI://other/"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register valid but from other domain
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("curl://other/GIZMO1"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register valid
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO1"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO2"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("GIZMO3"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        // duplicate
        try {
            TestComponent cob = new TestComponent(cobName);
            int handle1 = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO4"), type, cob);
            assertTrue(handle1 != 0);
            assertTrue((handle1 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            int handle2 = manager.registerComponent(cinfo.getHandle(), new URI("GIZMO4"), type, cob);
            assertTrue(handle2 != 0);
            assertTrue((handle2 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            assertEquals(handle1, handle2);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        // duplicate name, different type
        try {
            TestComponent cob = new TestComponent(cobName);
            int handle1 = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO4"), type, cob);
            assertTrue(handle1 != 0);
            assertTrue((handle1 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            manager.registerComponent(cinfo.getHandle(), new URI("GIZMO4"), type + "!", cob);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        manager.logout(cinfo.getHandle());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 57 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method testAllComponentNames.

public void testAllComponentNames() {
    TestContainer container = new TestContainer("Container");
    Map supportedComponents = new HashMap();
    TestComponent mount1COB = new TestComponent("Default");
    supportedComponents.put("Default", mount1COB);
    container.setSupportedComponents(supportedComponents);
    try {
        ClientInfo containerInfo = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
    // test activated Components
    try {
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", false);
        assertEquals(14, infos.length);
        boolean thereisDefault = false;
        for (int i = 0; i < infos.length; i++) if (infos[i].getName().equals("Default")) {
            thereisDefault = true;
            break;
        }
        if (!thereisDefault)
            fail();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission 2");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) HashMap(java.util.HashMap) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method testLogin.

public void testLogin() {
    // test null
    try {
        manager.login(null);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test null name
    try {
        manager.login(new TestClient(null));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test null autheticate
    try {
        manager.login(new TestClient("null-auth", null));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test invalid autheticate
    try {
        manager.login(new TestClient("container-invalid-auth", ClientType.ADMINISTRATOR));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    // test wrong container ImplLang (CDB vs reported by authenticate method)
    try {
        manager.login(new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.cpp, false));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    //test client login
    Client client = new TestClient(clientName);
    ClientInfo info = null;
    try {
        info = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.CLIENT_MASK) == HandleConstants.CLIENT_MASK);
    assertEquals(info.getClient(), client);
    //test duplicate login
    ClientInfo info2 = null;
    try {
        info2 = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info, info2);
    /* 
		// THIS TAKES WAY TOO MUCH TIME
		// DoS attack, there should be no handle left...
		try
		{
			Client differentClient = new TestAlwaysNotEqualClient("different");
			for (int i=0; i<HandleConstants.HANDLE_MASK-1; i++)
			{
				System.out.println(i);
				manager.login(differentClient);			
			}
			
			fail();
		}
		catch (NoResourcesException nre)
		{

			System.out.println("This is OK: "+nre.getMessage());
		}
		*/
    //test administrator login
    Administrator administrator = new TestAdministrator(administratorName);
    try {
        info = manager.login(administrator);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.ADMINISTRATOR_MASK) == HandleConstants.ADMINISTRATOR_MASK);
    assertEquals(info.getClient(), administrator);
    //test duplicate login
    try {
        info2 = manager.login(administrator);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info, info2);
    //test container login
    TestContainer container = new TestContainer(containerName);
    try {
        info = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.CONTAINER_MASK) == HandleConstants.CONTAINER_MASK);
    assertEquals(info.getClient(), container);
    //test duplicate login (same instance) - allowed
    try {
        info2 = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info.getHandle(), info2.getHandle());
    container.setHandle(info2.getHandle());
    //test duplicate login (same instance name, previous container alive) - reject
    TestContainer containerSameName = new TestContainer(containerName);
    try {
        info2 = manager.login(containerSameName);
        fail("No permission expected");
    } catch (AcsJNoPermissionEx e) {
        System.out.println("This is OK: " + e.toString());
    }
    // ... now make first instance return handle 0
    // this should allow the login
    container.setHandle(0);
    try {
        info2 = manager.login(containerSameName);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info.getHandle(), info2.getHandle());
    // wait for some time, so that manager reports passes postponed start-up component activation
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
}
Also used : Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) Client(com.cosylab.acs.maci.Client) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 59 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method internalTestGetHierarchicalComponent.

public void internalTestGetHierarchicalComponent(boolean activateOnActivation) {
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, false, activateOnActivation);
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT4" }, false, activateOnActivation);
        Component mount4COB = new TestComponent("MOUNT4");
        supportedComponents.put("MOUNT2", mount2HierCOB);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        // test case when container is unable to activate startup Component - MOUNT1
        ClientInfo containerInfo = manager.login(container);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // test ordinary activation
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
        // container logout and login
        manager.logout(containerInfo.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be no Components activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(0, infos.length);
        manager.login(container);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be all three Components activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
        // logout client
        manager.logout(info.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method testContainerInfo.

public void testContainerInfo() {
    try {
        //test invalid
        try {
            manager.getContainerInfo(0, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(Integer.MAX_VALUE, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, new int[0], null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, new int[0], "non-null");
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        /*
			//test invalid regular expression
			try {
				manager.getContainerInfo(dummyHandle, new int[0], ")");		
				fail();
			}
			catch (BadParametersException bpe)
			{
	
				System.out.println("This is OK: "+bpe.getMessage());
			}
			*/
        //test valid
        ClientInfo info = manager.login(new TestContainer(containerName));
        int[] handles = { info.getHandle() };
        ContainerInfo[] infos = manager.getContainerInfo(info.getHandle(), handles, null);
        assertNotNull(infos);
        assertEquals(infos.length, 1);
        assertEquals(infos[0].getHandle(), info.getHandle());
        manager.logout(info.getHandle());
        //test inaccessible
        info = manager.login(new TestContainer(containerName));
        ClientInfo anotherInfo = manager.login(new TestContainer(anotherName));
        handles[0] = anotherInfo.getHandle();
        try {
            infos = manager.getContainerInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        try {
            manager.getClientInfo(info.getHandle(), new int[0], anotherName);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test with INTROSPECTION_MANAGER rights
        info = manager.login(new TestContainer(containerName));
        ClientInfo adminInfo = manager.login(new TestAdministrator(administratorName));
        handles = new int[3];
        handles[0] = adminInfo.getHandle();
        handles[1] = info.getHandle();
        handles[2] = dummyHandle;
        infos = manager.getContainerInfo(adminInfo.getHandle(), handles, null);
        assertNotNull(infos);
        assertNull(infos[0]);
        assertEquals(infos[1].getHandle(), info.getHandle());
        assertNull(infos[2]);
        manager.logout(info.getHandle());
        manager.logout(adminInfo.getHandle());
        // test wildcard search		
        info = manager.login(new TestContainer("container1"));
        assertNotNull(info);
        ClientInfo info2 = manager.login(new TestContainer("container2a"));
        assertNotNull(info2);
        ClientInfo info3 = manager.login(new TestContainer("container3aa"));
        assertNotNull(info3);
        ClientInfo info4 = manager.login(new TestContainer("other4"));
        assertNotNull(info4);
        adminInfo = manager.login(new TestAdministrator("admin"));
        assertNotNull(adminInfo);
        //infos = manager.getContainerInfo(adminInfo.getHandle(), new int[0], "container.*");
        infos = manager.getContainerInfo(adminInfo.getHandle(), new int[0], "container*");
        assertNotNull(infos);
        assertEquals(3, infos.length);
        assertEquals(info.getHandle(), infos[0].getHandle());
        assertEquals(info2.getHandle(), infos[1].getHandle());
        assertEquals(info3.getHandle(), infos[2].getHandle());
        manager.logout(info.getHandle());
        manager.logout(info2.getHandle());
        manager.logout(info3.getHandle());
        manager.logout(info4.getHandle());
        manager.logout(adminInfo.getHandle());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Aggregations

AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)63 ClientInfo (com.cosylab.acs.maci.ClientInfo)39 BadParametersException (com.cosylab.acs.maci.BadParametersException)37 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)33 URI (java.net.URI)25 Component (com.cosylab.acs.maci.Component)24 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)24 URISyntaxException (java.net.URISyntaxException)24 HashMap (java.util.HashMap)21 Map (java.util.Map)21 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)20 RemoteException (com.cosylab.acs.maci.RemoteException)18 StatusHolder (com.cosylab.acs.maci.StatusHolder)18 CoreException (com.cosylab.acs.maci.CoreException)14 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 Object (org.omg.CORBA.Object)9