Search in sources :

Example 1 with OTokenHandlerImpl

use of com.orientechnologies.orient.server.token.OTokenHandlerImpl in project orientdb by orientechnologies.

the class OServer method activate.

@SuppressWarnings("unchecked")
public OServer activate() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    try {
        serverSecurity = new ODefaultServerSecurity(this, serverCfg);
        Orient.instance().setSecurity(serverSecurity);
        // Checks to see if the OrientDB System Database exists and creates it if not.
        // Make sure this happens after setSecurityFactory() is called.
        initSystemDatabase();
        for (OServerLifecycleListener l : lifecycleListeners) l.onBeforeActivate();
        final OServerConfiguration configuration = serverCfg.getConfiguration();
        tokenHandler = new OTokenHandlerImpl(this);
        if (configuration.network != null) {
            // REGISTER/CREATE SOCKET FACTORIES
            if (configuration.network.sockets != null) {
                for (OServerSocketFactoryConfiguration f : configuration.network.sockets) {
                    Class<? extends OServerSocketFactory> fClass = (Class<? extends OServerSocketFactory>) loadClass(f.implementation);
                    OServerSocketFactory factory = fClass.newInstance();
                    try {
                        factory.config(f.name, f.parameters);
                        networkSocketFactories.put(f.name, factory);
                    } catch (OConfigurationException e) {
                        OLogManager.instance().error(this, "Error creating socket factory", e);
                    }
                }
            }
            // REGISTER PROTOCOLS
            for (OServerNetworkProtocolConfiguration p : configuration.network.protocols) networkProtocols.put(p.name, (Class<? extends ONetworkProtocol>) loadClass(p.implementation));
            // STARTUP LISTENERS
            for (OServerNetworkListenerConfiguration l : configuration.network.listeners) networkListeners.add(new OServerNetworkListener(this, networkSocketFactories.get(l.socket), l.ipAddress, l.portRange, l.protocol, networkProtocols.get(l.protocol), l.parameters, l.commands));
        } else
            OLogManager.instance().warn(this, "Network configuration was not found");
        try {
            loadStorages();
            loadUsers();
            loadDatabases();
        } catch (IOException e) {
            final String message = "Error on reading server configuration";
            OLogManager.instance().error(this, message, e);
            throw OException.wrapException(new OConfigurationException(message), e);
        }
        registerPlugins();
        for (OServerLifecycleListener l : lifecycleListeners) l.onAfterActivate();
        running = true;
        String httpAddress = "localhost:2480";
        for (OServerNetworkListener listener : getNetworkListeners()) {
            if (listener.getProtocolType().getName().equals(ONetworkProtocolHttpDb.class.getName()))
                httpAddress = listener.getListeningAddress(true);
        }
        OLogManager.instance().info(this, "OrientDB Studio available at $ANSI{blue http://%s/studio/index.html}", httpAddress);
        OLogManager.instance().info(this, "$ANSI{green:italic OrientDB Server is active} v" + OConstants.getVersion() + ".");
    } catch (ClassNotFoundException e) {
        running = false;
        throw e;
    } catch (InstantiationException e) {
        running = false;
        throw e;
    } catch (IllegalAccessException e) {
        running = false;
        throw e;
    } catch (RuntimeException e) {
        running = false;
        throw e;
    } finally {
        startupLatch.countDown();
    }
    return this;
}
Also used : OServerSocketFactory(com.orientechnologies.orient.server.network.OServerSocketFactory) IOException(java.io.IOException) OTokenHandlerImpl(com.orientechnologies.orient.server.token.OTokenHandlerImpl) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ODefaultServerSecurity(com.orientechnologies.orient.server.security.ODefaultServerSecurity) ONetworkProtocol(com.orientechnologies.orient.server.network.protocol.ONetworkProtocol) OServerNetworkListener(com.orientechnologies.orient.server.network.OServerNetworkListener) ONetworkProtocolHttpDb(com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb)

Example 2 with OTokenHandlerImpl

use of com.orientechnologies.orient.server.token.OTokenHandlerImpl in project orientdb by orientechnologies.

the class OLiveCommandResultListenerTest method before.

@Before
public void before() throws IOException {
    MockitoAnnotations.initMocks(this);
    db = new ODatabaseDocumentTx("memory:" + OLiveCommandResultListenerTest.class.getSimpleName());
    db.create();
    OClientConnectionManager manager = new OClientConnectionManager(server);
    protocol = new ONetworkProtocolBinary();
    protocol.initVariables(server, channelBinary);
    connection = manager.connect(protocol);
    OTokenHandlerImpl tokenHandler = new OTokenHandlerImpl(server);
    byte[] token = tokenHandler.getSignedBinaryToken(db, db.getUser(), connection.getData());
    connection = manager.connect(protocol, connection, token, tokenHandler);
    connection.setDatabase(db);
    connection.getData().serializationImpl = ORecordSerializerNetwork.NAME;
    Mockito.when(server.getClientConnectionManager()).thenReturn(manager);
}
Also used : ONetworkProtocolBinary(com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OTokenHandlerImpl(com.orientechnologies.orient.server.token.OTokenHandlerImpl) Before(org.junit.Before)

Example 3 with OTokenHandlerImpl

use of com.orientechnologies.orient.server.token.OTokenHandlerImpl in project orientdb by orientechnologies.

the class OClientConnectionTest method testAlreadyAuthenticatedButNotOnSpecificConnection.

@Test(expected = OTokenSecurityException.class)
public void testAlreadyAuthenticatedButNotOnSpecificConnection() throws IOException {
    OClientConnection conn = new OClientConnection(1, null);
    OTokenHandler handler = new OTokenHandlerImpl(null);
    byte[] tokenBytes = handler.getSignedBinaryToken(db, db.getUser(), conn.getData());
    conn.validateSession(tokenBytes, handler, protocol);
    assertTrue(conn.getTokenBased());
    assertEquals(tokenBytes, conn.getTokenBytes());
    assertNotNull(conn.getToken());
    // second validation don't need token
    ONetworkProtocolBinary otherConn = Mockito.mock(ONetworkProtocolBinary.class);
    conn.validateSession(null, handler, otherConn);
}
Also used : ONetworkProtocolBinary(com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary) OTokenHandlerImpl(com.orientechnologies.orient.server.token.OTokenHandlerImpl) Test(org.junit.Test)

Aggregations

OTokenHandlerImpl (com.orientechnologies.orient.server.token.OTokenHandlerImpl)3 ONetworkProtocolBinary (com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OServerNetworkListener (com.orientechnologies.orient.server.network.OServerNetworkListener)1 OServerSocketFactory (com.orientechnologies.orient.server.network.OServerSocketFactory)1 ONetworkProtocol (com.orientechnologies.orient.server.network.protocol.ONetworkProtocol)1 ONetworkProtocolHttpDb (com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb)1 ODefaultServerSecurity (com.orientechnologies.orient.server.security.ODefaultServerSecurity)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 Test (org.junit.Test)1