Search in sources :

Example 6 with OUser

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();
}
Also used : ORole(com.orientechnologies.orient.core.metadata.security.ORole) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OUser

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OUser(com.orientechnologies.orient.core.metadata.security.OUser)

Example 8 with OUser

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));
}
Also used : DocumentWrapperTransformer(ru.ydn.wicket.wicketorientdb.utils.DocumentWrapperTransformer) ORID(com.orientechnologies.orient.core.id.ORID) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 9 with OUser

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();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Collection(java.util.Collection) List(java.util.List) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 10 with OUser

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;
}
Also used : OUser(com.orientechnologies.orient.core.metadata.security.OUser) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Aggregations

OUser (com.orientechnologies.orient.core.metadata.security.OUser)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)10 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 Test (org.junit.Test)5 ORole (com.orientechnologies.orient.core.metadata.security.ORole)4 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)3 ORID (com.orientechnologies.orient.core.id.ORID)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OSecurityUser (com.orientechnologies.orient.core.metadata.security.OSecurityUser)2 OToken (com.orientechnologies.orient.core.metadata.security.OToken)2 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 Collection (java.util.Collection)2 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OIndex (com.orientechnologies.orient.core.index.OIndex)1