QxOrm and authentication

Forum for posting problems using QxOrm library

Re: QxOrm and authentication

Postby nickla » Tue Aug 07, 2012 2:46 pm

When i am trying to use this DLL my program fails before entering int main(int argc, char *argv[]).
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: QxOrm and authentication

Postby qxorm » Wed Aug 08, 2012 12:07 pm

When i am trying to use this DLL my program fails before entering int main(int argc, char *argv[]).

Strange !
Could you upload your project ? Maybe I could see what happens...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: QxOrm and authentication

Postby nickla » Wed Aug 08, 2012 5:54 pm

I want to show you how i modify QxOrm to create ability for authentication and permission check

This is my patch:
Code: Select all
Index: include/QxService/IxService.h
===================================================================
--- include/QxService/IxService.h   (revision 256)
+++ include/QxService/IxService.h   (revision 258)
@@ -61,6 +61,7 @@
 protected:
 
    QString m_sServiceName;                            //!< Service name <=> class name
+   QString m_sServiceMethodName;                      //!< Service method name
    IxParameter_ptr m_pInputParameter;                 //!< List of input parameters (request)
    IxParameter_ptr m_pOutputParameter;                //!< List of output parameters (reply)
    qx_bool m_bMessageReturn;                          //!< Message return to indicate if an error occured
@@ -79,6 +80,7 @@
    boost::shared_ptr<QxTransaction> getTransaction() const;
 
    void setServiceName(const QString & s)                               { qAssert(! s.isEmpty()); m_sServiceName = s; }
+   void setServiceMethodName(const QString & s)                         { qAssert(! s.isEmpty()); m_sServiceMethodName = s; }
    void setInputParameter(IxParameter_ptr p)                            { m_pInputParameter = p; }
    void setOutputParameter(IxParameter_ptr p)                           { m_pOutputParameter = p; }
    void setMessageReturn(const qx_bool & b)                             { m_bMessageReturn = b; }
Index: src/QxService/QxTransaction.cpp
===================================================================
--- src/QxService/QxTransaction.cpp   (revision 256)
+++ src/QxService/QxTransaction.cpp   (revision 258)
@@ -54,8 +54,9 @@
    qx::service::IxService * ptr = qx::create_nude_ptr<qx::service::IxService>(m_sServiceName);
    if (ptr == NULL) { m_bMessageReturn = qx_bool(0, "[QxOrm] invalid service name => cannot instantiate service and execute process"); return; }
    m_pServiceInstance = IxService_ptr(ptr);
-   m_pServiceInstance->registerClass();
    m_pServiceInstance->setInputParameter(m_pInputParameter);
+   m_pServiceInstance->setServiceMethodName(m_sServiceMethod);
+   m_pServiceInstance->registerClass();
 
    try
    {


This gives me ability to use your auth method where i can get input parameters, service name and service method. I can get user credentials from input parameters and auth, check user permission using service name and service method name. I fails - i throw exception. I used your second method of authentication:
Code: Select all
template <class INPUT, class OUTPUT>
class MyBaseService : public qx::service::QxService<INPUT, OUTPUT>
{

public:

   MyBaseService(const QString & sServiceName) : qx::service::QxService<INPUT, OUTPUT>(sServiceName) { ; }
   virtual ~MyBaseService() { ; }

   virtual void registerClass() const
   {
      // Call base class registerClass() method
      qx::service::QxService<INPUT, OUTPUT>::registerClass();

      // Here are your own checks
      if (fails) { throw my_exception; }
   }

};


Dont worry about errors. Everything is working. This is my fault - i forgot to init database
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: QxOrm and authentication

Postby nickla » Thu Aug 09, 2012 6:03 am

If you accept my patch, i can create test example of how to do authentication with permission check using QxOrm and send it to you for including to project.
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: QxOrm and authentication

Postby qxorm » Thu Aug 09, 2012 7:51 am

Thx for your patch !
Next time, please create a new topic in the "Submit a patch" forum, it's easier for me for the TODO list ;)

So, I will include the property m_sServiceMethodName in the qx::IxService interface => ok it's a good idea !
But override registerClass() method is the only way you have today, but I think I will add another virtual method, something like :
- virtual void onBeforeProcess();
- virtual void onAfterProcess();

What do you think about it ? I think it's easier to understand when you implement your own service...
I will prepare a BETA version with your patch and will add it in this topic when ready...

Just a note about your code : never include your precompiled.h in a header file : a precompiled header file must be included in the first line of all your *.cpp files only !
For more details about precompiled headers, search on the web ;)
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: QxOrm and authentication

Postby nickla » Thu Aug 09, 2012 2:15 pm

I think that it is better to reimplement service class then use events.
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: QxOrm and authentication

Postby qxorm » Tue Dec 11, 2012 1:25 pm

Done, you can test it with the following BETA version :
http://www.qxorm.com/version/QxOrm_1.2.5_BETA_04.zip
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Previous

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron