use of com.cosylab.acs.maci.Administrator in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfo.
public void testComponentInfo() {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (false) {
try {
//TODO get ComponentInfo
manager.getComponentInfo(0, null, null, null, false);
manager.getComponentInfo(Integer.MAX_VALUE, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, "non-null", null, true);
manager.getComponentInfo(dummyHandle, null, null, "non-null", true);
manager.getComponentInfo(dummyHandle, new int[0], null, null, false);
manager.getComponentInfo(dummyHandle, new int[0], "non-null", null, true);
manager.getComponentInfo(dummyHandle, new int[0], null, "non-null", false);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
manager.getComponentInfo(info.getHandle(), new int[0], "*MOUNT*", "*", false);
manager.logout(info.getHandle());
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = null;
try {
containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e1) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT1", "*", false);
assertEquals(1, infos.length);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
manager.logout(containerInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Administrator in project ACS by ACS-Community.
the class ManagerImplTest method testContainerShutdown.
public void testContainerShutdown() {
try {
manager.shutdownContainer(0, null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(0, "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail();
}
try {
manager.shutdownContainer(info.getHandle(), "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Administrator admin = new TestAdministrator("shutdownAdmin");
ClientInfo info2 = null;
try {
info2 = manager.login(admin);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.shutdownContainer(info2.getHandle(), null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(info2.getHandle(), "invalid", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (NoResourcesException nre) {
System.out.println("This is OK: " + nre.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestComponent mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", 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
ComponentInfo[] infos = null;
try {
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(1, infos.length);
try {
manager.shutdownContainer(info.getHandle(), "Container", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
try {
manager.shutdownContainer(info2.getHandle(), "Container", 1);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(0, container.getActivatedComponents().size());
}
use of com.cosylab.acs.maci.Administrator in project ACS by ACS-Community.
the class ManagerImplTest method testShutdown.
/**
*
* Test of ManagerImpl shutdown.
*
*/
public void testShutdown() {
try {
manager.shutdown(0, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.shutdown(info.getHandle(), 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Administrator admin = new TestAdministrator("shutdownAdmin");
ClientInfo info2 = null;
try {
info2 = manager.login(admin);
manager.shutdown(info2.getHandle(), 0);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
// already shutdown
try {
manager.shutdown(info2.getHandle(), 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
// already shutdown returns without exception
try {
manager.logout(info.getHandle());
System.out.println("This is OK");
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is NOT OK: " + npe.toString());
npe.printStackTrace();
}
// already shutdown
try {
manager.login(client);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
// tearDown should not shutdown
manager = null;
}
use of com.cosylab.acs.maci.Administrator in project ACS by ACS-Community.
the class ManagerImpl method login.
/**
* @see com.cosylab.acs.maci.Manager#login(Client)
*/
public ClientInfo login(Client reference) throws AcsJNoPermissionEx {
// check if already shutdown
if (shutdown.get()) {
// already shutdown
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Manager in shutdown state.");
throw npe;
}
if (reference == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'reference' expected.");
throw af;
}
/****************************************************************/
ClientInfo info = null;
try {
long executionId = generateExecutionId();
AuthenticationData reply = reference.authenticate(executionId, "Identify yourself");
if (reply == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null structure expected.");
throw af;
} else if (reply.getClientType() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null client type expected.");
throw af;
} else if (reply.getImplLang() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - no-null implementation language expected.");
throw af;
}
// get client's name
String name = reference.name();
if (name == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::name()' method - non-null string expected.");
throw af;
}
logger.log(Level.FINE, "'" + name + "' is logging in.");
final long timeStamp = reply.getTimeStamp() > 0 ? reply.getTimeStamp() : System.currentTimeMillis();
if (reply.getExecutionId() != 0)
executionId = generateExecutionId();
// delegate
switch(reply.getClientType()) {
// container
case CONTAINER:
if (reference instanceof Container) {
info = containerLogin(name, reply, (Container) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated container login, but given reference does not implement 'maci::Container' interface.");
npe.setID(name);
throw npe;
}
break;
// client
case CLIENT:
info = clientLogin(name, reply, reference, timeStamp, executionId);
break;
// supervisor (administrator)
case ADMINISTRATOR:
if (reference instanceof Administrator) {
info = administratorLogin(name, reply, (Administrator) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated administrator login, but given reference does not implement 'maci::Administrator' interface.");
npe.setID(name);
throw npe;
}
break;
default:
assert (false);
}
} catch (AcsJNoPermissionEx npe) {
throw npe;
} catch (BadParametersException bpe) {
throw bpe;
} catch (NoResourcesException nre) {
throw nre;
} catch (RemoteException re) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Exception caught while examining the client. Login rejected.", re);
throw rt;
} catch (Throwable ex) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Unexpected exception during login. Login rejected.", ex);
throw rt;
}
/****************************************************************/
logger.log(Level.FINE, "Client with handle '" + HandleHelper.toString(info.getHandle()) + "' has logged in.");
return info;
}
use of com.cosylab.acs.maci.Administrator 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) {
}
}
Aggregations