Search in sources :

Example 16 with OUser

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

the class OServerCommandAuthenticatedDbAbstract method getProfiledDatabaseInstanceBasic.

protected ODatabaseDocumentInternal getProfiledDatabaseInstanceBasic(final OHttpRequest iRequest) throws InterruptedException {
    final OHttpSession session = OHttpSessionManager.getInstance().getSession(iRequest.sessionId);
    if (session == null)
        throw new OSecurityAccessException(iRequest.databaseName, "No session active");
    // 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, session.getUserName(), session.getUserPassword());
    } else {
        String currentUserId = iRequest.data.currentUserId;
        if (currentUserId != null && currentUserId.length() > 0 && localDatabase != null && localDatabase.getUser() != null) {
            if (!currentUserId.equals(localDatabase.getUser().getIdentity().toString())) {
                ODocument userDoc = localDatabase.load(new ORecordId(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 : OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ORecordId(com.orientechnologies.orient.core.id.ORecordId) 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