Search in sources :

Example 1 with AuthenticationData

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;
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(com.cosylab.acs.maci.Container) SynchronousAdministrator(com.cosylab.acs.maci.SynchronousAdministrator) Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) AuthenticationData(com.cosylab.acs.maci.AuthenticationData) ClientInfo(com.cosylab.acs.maci.ClientInfo) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Aggregations

AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)1 Administrator (com.cosylab.acs.maci.Administrator)1 AuthenticationData (com.cosylab.acs.maci.AuthenticationData)1 BadParametersException (com.cosylab.acs.maci.BadParametersException)1 ClientInfo (com.cosylab.acs.maci.ClientInfo)1 Container (com.cosylab.acs.maci.Container)1 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)1 RemoteException (com.cosylab.acs.maci.RemoteException)1 SynchronousAdministrator (com.cosylab.acs.maci.SynchronousAdministrator)1 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)1