Hello Andrey,

i tried to install a application side hook to add credential flags to a 
vertex on the fly... depending on user session data and security data in 
the db. With the following test code the lifecycle callback onCreate and 
onClose are called but onRecordAfterRead and onRecordBeforeRead are not 
called... probably because i used a remode DB.
Meanwhile i found an other solution without hooks so this is not that 
important anymore.

/**
 * Evaluates access for the current user and adds a transient accessFlags
 * property on the fly.
 * 
 *
 */
public class SecurityHook extends ORecordHookAbstract implements 
ODatabaseLifecycleListener {

    private final OrientService orientService;
    private final Instance<SessionContextData> sessionContextData;

    public SecurityHook(OrientService orientService, Instance<
SessionContextData> sessionContextData) {
        super();

        this.orientService = orientService;
        this.sessionContextData = sessionContextData;

        // 
setIncludeClasses(ETypeConfigBaseVertices.V_BaseItem.getOrientClassName());

        // Register SecurityHook as lifecycle listener
        Orient.instance().addDbLifecycleListener(this);
    }

    @Override
    public void onRecordAfterRead(final ORecord iDocument) {
        ORID identity = iDocument.getIdentity();
        int access = orientService.getAccess(identity);
        // iDocument.field(AF.ACCESS_FLAGS, access);
    }

    @Override
    public RESULT onRecordBeforeRead(final ORecord iDocument) {
        ORID identity = iDocument.getIdentity();
        int access = orientService.getAccess(identity);
        // iDocument.field(AF.ACCESS_FLAGS, access);
        return RESULT.RECORD_NOT_CHANGED;
    }

    @Override
    public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
        return DISTRIBUTED_EXECUTION_MODE.TARGET_NODE;
    }

    @Override
    public PRIORITY getPriority() {
        return PRIORITY.FIRST;
    }

    @Override
    public void onCreate(ODatabaseInternal iDatabase) {
        iDatabase.registerHook(this);
    }

    @Override
    public void onOpen(ODatabaseInternal iDatabase) {
        iDatabase.registerHook(this);
    }

    @Override
    public void onClose(ODatabaseInternal iDatabase) {
        iDatabase.unregisterHook(this);
    }

    @Override
    public void onCreateClass(ODatabaseInternal iDatabase, OClass iClass) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onDropClass(ODatabaseInternal iDatabase, OClass iClass) {
        // TODO Auto-generated method stub

    }

}






Am Freitag, 26. Dezember 2014 16:37:53 UTC+1 schrieb Andrey Lomakin:
>
> Hi Thomas,
> Could you give us more details about your issue ?
>
> Do you want to create callback hook on client side and track events of 
> this hook for client operations do not yout ?
>
> On Thu, Dec 25, 2014 at 2:33 AM, Thomas Müller <[email protected] 
> <javascript:>> wrote:
>
>> Hello,
>>
>> Is it possible to use a selfregistered Hook inside my application with a 
>> remote DB?
>>
>> I can see that ODatabaseLifecycleListener callbacks onCreate and onClose 
>> are called on each request which reads data from the DB but 
>> onRecordAfterRead or onRecordBeforeRead is not called.
>>
>> In the hook i want to access thread local data so a server side hook is 
>> not usable for me. I could use an embedded DB but probably its not possible 
>> to use the studio with the embedded DB at the same time.
>>
>> regards and happy christmas,
>> thomas
>>
>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Best regards,
> Andrey Lomakin.
>
> 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to