use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class OServerCommandGetDatabase method exportSecurityInfo.
private void exportSecurityInfo(ODatabaseDocument db, OJSONWriter json) throws IOException {
json.beginCollection("users");
for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
OUser user = new OUser(doc);
json.beginObject();
json.writeAttribute("name", user.getName());
json.writeAttribute("roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
json.endObject();
}
json.endCollection();
json.beginCollection("roles");
ORole role;
for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
role = new ORole(doc);
json.beginObject();
json.writeAttribute("name", role.getName());
json.writeAttribute("mode", role.getMode().toString());
json.beginCollection("rules");
if (role.getRules() != null) {
for (Map.Entry<String, Byte> rule : role.getRules().entrySet()) {
json.beginObject();
json.writeAttribute("name", rule.getKey());
json.writeAttribute("create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
json.writeAttribute("read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
json.writeAttribute("update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
json.writeAttribute("delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
json.endObject();
}
}
json.endCollection();
json.endObject();
}
json.endCollection();
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project guice-persist-orient by xvik.
the class UserManager method executeWithTxUser.
/**
* Changes current connection user. See {@link #executeWithTxUser(
*com.orientechnologies.orient.core.metadata.security.OSecurityUser, SpecificUserAction)}.
* <p>
* LIMITATION: current user must have read right on users table.
*
* @param user user login
* @param userAction logic to execute with specific user
* @param <T> type of returned result (may be Void)
* @return action result (may be null)
*/
public <T> T executeWithTxUser(final String user, final SpecificUserAction<T> userAction) {
final boolean userChanged = checkSpecificUserConditions(user);
final ODatabaseDocumentTx db = connectionProvider.get();
final T res;
if (userChanged) {
// this may cause security exception if current user has no access rights to users table
final OUser specificUser = db.getMetadata().getSecurity().getUser(user);
Preconditions.checkState(specificUser != null, "User '%s' not found", user);
res = executeWithTxUser(specificUser, userAction);
} else {
res = executeWithTxUser(db.getUser(), userAction);
}
return res;
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project wicket-orientdb by OrienteerBAP.
the class MainUtilsTest method testDocumentWrapper.
@Test
public void testDocumentWrapper() throws Exception {
// Admin ORID
ORID orid = new ORecordId("#5:0");
ODocument adminDocument = orid.getRecord();
OUser admin = wicket.getTester().getMetadata().getSecurity().getUser("admin");
DocumentWrapperTransformer<OUser> transformer = new DocumentWrapperTransformer<OUser>(OUser.class);
assertEquals(admin, transformer.apply(adminDocument));
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class OCommandCacheTest method testCommandCache.
@Test
public void testCommandCache() {
OGlobalConfiguration.COMMAND_CACHE_ENABLED.setValue(true);
OGlobalConfiguration.COMMAND_CACHE_MIN_EXECUTION_TIME.setValue(1);
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + OCommandCacheTest.class.getSimpleName());
db.create();
try {
db.getMetadata().getSchema().createClass("OCommandCache");
for (int i = 0; i < 200; i++) {
ODocument doc = new ODocument("OCommandCache");
db.save(doc);
}
OSQLSynchQuery<List<ODocument>> query = new OSQLSynchQuery<List<ODocument>>("select from OCommandCache");
query.setCacheableResult(true);
List<ODocument> results = db.query(query);
OCommandCache commandCache = db.getMetadata().getCommandCache();
Collection cachedResults = (Collection) commandCache.get(new OUser("admin"), "select from OCommandCache", -1);
Assert.assertNotNull(cachedResults);
Assert.assertEquals(results.size(), cachedResults.size());
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method createDatabase.
protected ODatabaseDocumentInternal createDatabase(final ODatabaseDocumentInternal iDatabase, String dbUser, final String dbPasswd, final String backupPath) {
if (iDatabase.exists())
throw new ODatabaseException("Database '" + iDatabase.getURL() + "' already exists");
if (backupPath == null)
iDatabase.create();
else
iDatabase.create(backupPath);
if (dbUser != null) {
OUser oUser = iDatabase.getMetadata().getSecurity().getUser(dbUser);
if (oUser == null) {
iDatabase.getMetadata().getSecurity().createUser(dbUser, dbPasswd, new String[] { ORole.ADMIN });
} else {
oUser.setPassword(dbPasswd);
oUser.save();
}
}
OLogManager.instance().info(this, "Created database '%s' of type '%s'", iDatabase.getName(), iDatabase.getStorage().getUnderlying() instanceof OAbstractPaginatedStorage ? iDatabase.getStorage().getUnderlying().getType() : "memory");
return iDatabase;
}
Aggregations