use of com.cosylab.acs.maci.AuthenticationData 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;
}
Aggregations