Search in sources :

Example 1 with OUser

use of com.orientechnologies.orient.core.metadata.security.OUser in project wicket-orientdb by OrienteerBAP.

the class TestModels method testOQueryProvider.

@Test
public void testOQueryProvider() {
    OQueryDataProvider<OUser> provider = new OQueryDataProvider<OUser>("select from OUser where name <> :other", OUser.class);
    provider.setSort("name", SortOrder.ASCENDING);
    provider.setParameter("other", Model.of("blalba"));
    Iterator<OUser> it = provider.iterator(0, -1);
    List<ODocument> allUsers = wicket.getTester().getMetadata().getSecurity().getAllUsers();
    assertTrue(provider.size() == allUsers.size());
    while (it.hasNext()) {
        OUser oUser = it.next();
        assertTrue(allUsers.contains(provider.model(oUser).getObject().getDocument()));
    }
    provider.detach();
    assertTrue(provider.size() == allUsers.size());
}
Also used : OQueryDataProvider(ru.ydn.wicket.wicketorientdb.model.OQueryDataProvider) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 2 with OUser

use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.

the class OTokenHandlerImplTest method testBinartTokenCreationValidation.

@Test
public void testBinartTokenCreationValidation() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
    db.create();
    try {
        OSecurityUser original = db.getUser();
        OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
        ONetworkProtocolData data = new ONetworkProtocolData();
        data.driverName = "aa";
        data.driverVersion = "aa";
        data.serializationImpl = "a";
        data.protocolVersion = 2;
        byte[] token = handler.getSignedBinaryToken(db, original, data);
        OToken tok = handler.parseBinaryToken(token);
        assertNotNull(tok);
        assertTrue(tok.getIsVerified());
        OUser user = tok.getUser(db);
        assertEquals(user.getName(), original.getName());
        boolean boole = handler.validateBinaryToken(tok);
        assertTrue(boole);
        assertTrue(tok.getIsValid());
    } finally {
        db.drop();
    }
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Test(org.junit.Test)

Example 3 with OUser

use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.

the class SQLFunctionsTest method queryCountExtendsRestricted.

public void queryCountExtendsRestricted() {
    OClass restricted = database.getMetadata().getSchema().getClass("ORestricted");
    Assert.assertNotNull(restricted);
    database.getMetadata().getSchema().createClass("QueryCountExtendsRestrictedClass", restricted);
    OUser admin = database.getMetadata().getSecurity().getUser("admin");
    OUser reader = database.getMetadata().getSecurity().getUser("reader");
    ORole byPassRestrictedRole = database.getMetadata().getSecurity().createRole("byPassRestrictedRole", ORole.ALLOW_MODES.DENY_ALL_BUT);
    byPassRestrictedRole.addRule(ORule.ResourceGeneric.BYPASS_RESTRICTED, null, ORole.PERMISSION_READ);
    byPassRestrictedRole.save();
    database.getMetadata().getSecurity().createUser("superReader", "superReader", "reader", "byPassRestrictedRole");
    ODocument docAdmin = new ODocument("QueryCountExtendsRestrictedClass");
    docAdmin.field("_allowRead", new HashSet<OIdentifiable>(Arrays.asList(admin.getDocument().getIdentity())));
    docAdmin.save();
    ODocument docReader = new ODocument("QueryCountExtendsRestrictedClass");
    docReader.field("_allowRead", new HashSet<OIdentifiable>(Arrays.asList(reader.getDocument().getIdentity())));
    docReader.save();
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
    ODocument count = result.get(0);
    Assert.assertEquals(2L, count.field("count"));
    database.close();
    database.open("admin", "admin");
    result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
    count = result.get(0);
    Assert.assertEquals(2L, count.field("count"));
    database.close();
    database.open("reader", "reader");
    result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
    count = result.get(0);
    Assert.assertEquals(1L, count.field("count"));
    database.close();
    database.open("superReader", "superReader");
    result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
    count = result.get(0);
    Assert.assertEquals(2L, count.field("count"));
}
Also used : ORole(com.orientechnologies.orient.core.metadata.security.ORole) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OUser

use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.

the class OSymmetricKeySecurity method authenticate.

public OUser authenticate(final String username, final String password) {
    if (delegate == null)
        throw new OSecurityAccessException("OSymmetricKeySecurity.authenticate() Delegate is null for username: " + username);
    if (database == null)
        throw new OSecurityAccessException("OSymmetricKeySecurity.authenticate() Database is null for username: " + username);
    final String dbName = database.getName();
    OUser user = delegate.getUser(username);
    if (user == null)
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Username or Key is invalid for username: " + username);
    if (user.getAccountStatus() != OSecurityUser.STATUSES.ACTIVE)
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() User '" + username + "' is not active");
    try {
        OUserSymmetricKeyConfig userConfig = new OUserSymmetricKeyConfig(user);
        OSymmetricKey sk = OSymmetricKey.fromConfig(userConfig);
        String decryptedUsername = sk.decryptAsString(password);
        if (OSecurityManager.instance().checkPassword(username, decryptedUsername))
            return user;
    } catch (Exception ex) {
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Exception for database: " + dbName + ", username: " + username + " " + ex.getMessage());
    }
    throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Username or Key is invalid for database: " + dbName + ", username: " + username);
}
Also used : OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OSymmetricKey(com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OUserSymmetricKeyConfig(com.orientechnologies.orient.core.security.symmetrickey.OUserSymmetricKeyConfig)

Example 5 with OUser

use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.

the class OServerCommandAuthenticatedDbAbstract method getProfiledDatabaseInstanceToken.

protected ODatabaseDocumentInternal getProfiledDatabaseInstanceToken(final OHttpRequest iRequest) throws InterruptedException {
    // after authentication, if current login user is different compare with current DB user, reset DB user to login user
    ODatabaseDocumentInternal localDatabase = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (localDatabase == null) {
        localDatabase = (ODatabaseDocumentTx) server.openDatabase(iRequest.databaseName, iRequest.bearerToken);
    } else {
        ORID currentUserId = iRequest.bearerToken.getUserId();
        if (currentUserId != null && localDatabase != null && localDatabase.getUser() != null) {
            if (!currentUserId.equals(localDatabase.getUser().getDocument().getIdentity())) {
                ODocument userDoc = localDatabase.load(currentUserId);
                localDatabase.setUser(new OUser(userDoc));
            }
        }
    }
    iRequest.data.lastDatabase = localDatabase.getName();
    iRequest.data.lastUser = localDatabase.getUser() != null ? localDatabase.getUser().getName() : null;
    return (ODatabaseDocumentTx) localDatabase.getDatabaseOwner();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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