Skip to content

Commit

Permalink
Removed "replicator" user.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Aug 10, 2015
1 parent 97ae539 commit b294bc4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 88 deletions.
Expand Up @@ -19,11 +19,6 @@
*/
package com.orientechnologies.orient.server.hazelcast;

import java.io.Serializable;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

import com.hazelcast.core.HazelcastInstanceNotActiveException;
import com.hazelcast.core.IMap;
import com.hazelcast.core.IQueue;
Expand All @@ -38,7 +33,6 @@
import com.orientechnologies.orient.core.serialization.serializer.record.OSerializationSetThreadLocal;
import com.orientechnologies.orient.server.config.OServerUserConfiguration;
import com.orientechnologies.orient.server.distributed.ODiscardedResponse;
import com.orientechnologies.orient.server.distributed.ODistributedAbstractPlugin;
import com.orientechnologies.orient.server.distributed.ODistributedException;
import com.orientechnologies.orient.server.distributed.ODistributedRequest;
import com.orientechnologies.orient.server.distributed.ODistributedServerLog;
Expand All @@ -52,6 +46,11 @@
import com.orientechnologies.orient.server.distributed.task.OTxTask;
import com.orientechnologies.orient.server.distributed.task.OUpdateRecordTask;

import java.io.Serializable;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
* Hazelcast implementation of distributed peer. There is one instance per database. Each node creates own instance to talk with
* each others.
Expand Down Expand Up @@ -154,19 +153,15 @@ public void run() {
public void initDatabaseInstance() {
if (database == null) {
// OPEN IT
final OServerUserConfiguration replicatorUser = manager.getServerInstance().getUser(
ODistributedAbstractPlugin.REPLICATOR_USER);
database = (ODatabaseDocumentTx) manager.getServerInstance().openDatabase("document", databaseName, replicatorUser.name,
replicatorUser.password);
database = (ODatabaseDocumentTx) manager.getServerInstance().openDatabase("document", databaseName, "bypass", "bypass", null,
true);

// AVOID RELOADING DB INFORMATION BECAUSE OF DEADLOCKS
// database.reload();

} else if (database.isClosed()) {
// DATABASE CLOSED, REOPEN IT
final OServerUserConfiguration replicatorUser = manager.getServerInstance().getUser(
ODistributedAbstractPlugin.REPLICATOR_USER);
database.open(replicatorUser.name, replicatorUser.password);
manager.getServerInstance().openDatabase(database, "bypass", "bypass", null, true);

// AVOID RELOADING DB INFORMATION BECAUSE OF DEADLOCKS
// database.reload();
Expand Down
Expand Up @@ -65,8 +65,8 @@ protected static OrientGraphFactory getGraphFactory() throws Exception {
conf.put("storage.url", "remote:localhost/test");
conf.put("storage.pool-min", 1);
conf.put("storage.pool-max", 10);
conf.put("storage.user", "admin");
conf.put("storage.password", "admin");
conf.put("storage.user", "root");
conf.put("storage.password", "root");

OGlobalConfiguration.CLIENT_CONNECT_POOL_WAIT_TIMEOUT.setValue(15000);

Expand Down Expand Up @@ -125,7 +125,7 @@ public static void setup() throws Exception {
+ " <storages>\n"
+ " </storages>\n"
+ " <users>\n"
+ " <user name=\"admin\" password=\"admin\" resources=\"*\"/>\n"
+ " <user name=\"root\" password=\"root\" resources=\"*\"/>\n"
+ " </users>\n"
+ " <properties>\n"
+ "\n"
Expand Down
113 changes: 61 additions & 52 deletions server/src/main/java/com/orientechnologies/orient/server/OServer.java
Expand Up @@ -19,26 +19,6 @@
*/
package com.orientechnologies.orient.server;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;

import com.orientechnologies.common.console.DefaultConsoleReader;
import com.orientechnologies.common.console.OConsoleReader;
import com.orientechnologies.common.io.OFileUtils;
Expand Down Expand Up @@ -70,7 +50,6 @@
import com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.memory.ODirectMemoryStorage;
import com.orientechnologies.orient.server.config.*;
import com.orientechnologies.orient.server.distributed.ODistributedAbstractPlugin;
import com.orientechnologies.orient.server.distributed.ODistributedServerManager;
import com.orientechnologies.orient.server.handler.OConfigurableHooksManager;
import com.orientechnologies.orient.server.network.OServerNetworkListener;
Expand All @@ -82,6 +61,25 @@
import com.orientechnologies.orient.server.plugin.OServerPluginManager;
import com.orientechnologies.orient.server.security.OSecurityServerUser;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;

public class OServer {
private static final String ROOT_PASSWORD_VAR = "ORIENTDB_ROOT_PASSWORD";
private static ThreadGroup threadGroup;
Expand Down Expand Up @@ -724,15 +722,25 @@ public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, fina
}

public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, final String user, final String password) {
return openDatabase(iDbType, iDbUrl, user, password, null);
return openDatabase(iDbType, iDbUrl, user, password, null, false);
}

public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, final String user, final String password,
ONetworkProtocolData data) {
return openDatabase(iDbType, iDbUrl, user, password, data, false);
}

public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, final String user, final String password,
ONetworkProtocolData data, final boolean iBypassAccess) {
final String path = getStoragePath(iDbUrl);

final ODatabaseInternal<?> database = Orient.instance().getDatabaseFactory().createDatabase(iDbType, path);

return openDatabase(database, user, password, data, iBypassAccess);
}

public ODatabase<?> openDatabase(final ODatabaseInternal<?> database, final String user, final String password,
final ONetworkProtocolData data, final boolean iBypassAccess) {
final OStorage storage = database.getStorage();
if (database.isClosed()) {
if (database.getStorage() instanceof ODirectMemoryStorage && !storage.exists()) {
Expand All @@ -741,28 +749,27 @@ public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, fina
} catch (OStorageException e) {
}
} else {
try {
database.open(user, password);
if (data != null) {
data.serverUser = false;
data.serverUsername = null;
}
} catch (OSecurityException e) {
// TRY WITH SERVER'S USER
if (iBypassAccess) {
// BYPASS SECURITY
openDatabaseBypassingSecurity(database, data);
} else {
try {
serverLogin(user, password, "database.passthrough");
} catch (OSecurityException ex) {
throw e;
}
// TRY DATABASE AUTHENTICATION
database.open(user, password);
if (data != null) {
data.serverUser = false;
data.serverUsername = null;
}
} catch (OSecurityException e) {
// TRY WITH SERVER'S AUTHENTICATION
try {
serverLogin(user, password, "database.passthrough");
} catch (OSecurityException ex) {
throw e;
}

// SERVER AUTHENTICATED, BYPASS SECURITY
database.activateOnCurrentThread();
database.resetInitialization();
database.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecurityServerUser.class);
database.open(user, password);
if (data != null) {
data.serverUser = true;
data.serverUsername = user;
// SERVER AUTHENTICATED, BYPASS SECURITY
openDatabaseBypassingSecurity(database, data);
}
}
}
Expand All @@ -771,24 +778,26 @@ public ODatabase<?> openDatabase(final String iDbType, final String iDbUrl, fina
return database;
}

protected void openDatabaseBypassingSecurity(final ODatabaseInternal<?> database, final ONetworkProtocolData data) {
database.activateOnCurrentThread();
database.resetInitialization();
database.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecurityServerUser.class);
database.open("internal", "internal");
if (data != null) {
data.serverUser = true;
data.serverUsername = "internal";
}
}

public ODatabaseInternal openDatabase(final ODatabaseInternal database) {
database.activateOnCurrentThread();

if (database.isClosed())
if (database.getStorage() instanceof ODirectMemoryStorage)
database.create();
else {
final OServerUserConfiguration replicatorUser = getUser(ODistributedAbstractPlugin.REPLICATOR_USER);
try {
serverLogin(replicatorUser.name, replicatorUser.password, "database.passthrough");
} catch (OSecurityException ex) {
throw ex;
}

// SERVER AUTHENTICATED, BYPASS SECURITY
database.resetInitialization();
database.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecurityServerUser.class);
database.open(replicatorUser.name, replicatorUser.password);
openDatabaseBypassingSecurity(database, null);
}

return database;
Expand Down
Expand Up @@ -19,15 +19,6 @@
*/
package com.orientechnologies.orient.server.distributed;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.parser.OSystemVariableResolver;
import com.orientechnologies.orient.core.Orient;
Expand All @@ -45,6 +36,15 @@
import com.orientechnologies.orient.server.distributed.ODistributedServerLog.DIRECTION;
import com.orientechnologies.orient.server.plugin.OServerPluginAbstract;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

/**
* Abstract plugin to manage the distributed environment.
*
Expand All @@ -53,9 +53,6 @@
*/
public abstract class ODistributedAbstractPlugin extends OServerPluginAbstract implements ODistributedServerManager,
ODatabaseLifecycleListener {
public static final String REPLICATOR_USER = "replicator";
protected static final String MASTER_AUTO = "$auto";

protected static final String PAR_DEF_DISTRIB_DB_CONFIG = "configuration.db.default";
protected static final String FILE_DISTRIBUTED_DB_CONFIG = "distributed-config.json";

Expand Down Expand Up @@ -121,14 +118,6 @@ public void config(OServer oServer, OServerParameterConfiguration[] iParams) {
setDefaultDatabaseConfigFile(param.value);
}
}

if (serverInstance.getUser(REPLICATOR_USER) == null)
// CREATE THE REPLICATOR USER
try {
serverInstance.addUser(REPLICATOR_USER, null, "database.passthrough");
} catch (IOException e) {
throw new OConfigurationException("Error on creating 'replicator' user", e);
}
}

public void setDefaultDatabaseConfigFile(final String iFile) {
Expand Down

0 comments on commit b294bc4

Please sign in to comment.