change from pattern based authentication to class based authentication
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Apr 2010 12:59:01 +0000 (12:59 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Apr 2010 12:59:01 +0000 (12:59 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@432 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

woc/phpout.cpp
woc/phpout.h

index a026a32..c29fc78 100644 (file)
@@ -31,18 +31,7 @@ WocPHPServerOut::WocPHPServerOut(const QDomElement&el)
        m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir",".");
        m_subdir=el.attribute("subDir","phpwob");
        m_fileext=el.attribute("extension",".inc");
-       QList<QDomElement> nl=elementsByTagName(el,"Authenticator");
-       if(nl.size()){
-               QDomElement el2=nl.at(0).toElement();
-               m_isauth=el2.attribute("isAuthenticated","false");
-               m_hasrole=el2.attribute("hasRole","false");
-               m_username=el2.attribute("userName","\"\"");
-               m_authinit=el2.attribute("init","");
-       }else{
-               m_isauth="false";
-               m_hasrole="false";
-               m_username="\"\"";
-       }
+       m_transbase=el.attribute("transactionBase","WobTransaction");
        //cleanup directory (remove normal files, assume remainder is harmless)
        QDir d(m_basedir+"/"+m_subdir);
        if(d.exists() && str2bool(el.attribute("clean","0"))){
@@ -803,25 +792,23 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
        
        ////
        //generate code
-       QString code="/* TRANSLATOR "+cn+" */\nclass "+cn+" extends WobTransaction{\n";
+       QString code="/* TRANSLATOR "+cn+" */\nclass "+cn+" extends "+m_transbase+"{\n";
        //constructor
        code+=trnConstruct(trn);
        tf.write(code.toAscii());
        
        //request handler:
-       code="public function handleRequest(){\n";
+       code="public function handleRequest(){\n\t$this->startTransaction();\n";
        
        //security handling
        switch(trn.authMode()){
                case WocTransaction::Checked:
                        code+="\t/*security check: authenticated and authorized*/\n";
-                       code+="\t"+m_authinit+";\n";
-                       code+="\tif(!"+m_isauth+"||!"+QString(m_hasrole).replace("%","\""+trn.name()+"\"")+")$this->notAuthenticated();\n";
+                       code+="\tif(!$this->isAuthorized(\""+trn.name()+"\""+"))$this->notAuthenticated();\n";
                        break;
                case WocTransaction::Auth:
                        code+="\t/*security check: authenticated*/\n";
-                       code+="\t"+m_authinit+";\n";
-                       code+="\tif(!"+m_isauth+")$this->notAuthenticated();\n";
+                       code+="\tif(!$this->isAuthenticated())$this->notAuthenticated();\n";
                        break;
                default:
                        code+="\t/*no security check, open function*/\n";
@@ -850,7 +837,7 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
        //encode outputs/handle errors
        code+=trnOutput(trn);
        
-       code+="}\n";
+       code+="\t$this->commitTransaction();\n}\n";
        tf.write(code.toAscii());
        
        //getters/setters
@@ -876,7 +863,8 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
 
 QString WocPHPServerOut::trnConstruct(const WocTransaction&trn)
 {
-       QString code="public function __construct(){\n\t$this->ainput=array(";
+       QString code="public function __construct(){\n\tparent::__construct();\n";
+       code+="\t$this->ainput=array(";
        QStringList sl=trn.inputNames();
        for(int i=0;i<sl.size();i++){
                if(i)code+=",";
@@ -1098,7 +1086,7 @@ QString WocPHPServerOut::trnPrivileges(const WocTransaction&trn)
        //check method
        code+="public function havePrivilege($priv){\n";
        code+="\tif(!in_array($priv,self::privileges()))return false;\n";
-       code+="\treturn "+QString(m_hasrole).replace("%","(\""+trn.name()+":\".$priv)")+";\n}\n";
+       code+="\treturn $this->isAuthorized(\""+trn.name()+":\".$priv);\n}\n";
        
        return code;
 }
index 186039e..7cb4819 100644 (file)
@@ -36,7 +36,8 @@ class WocPHPServerOut:public WocOutput
                virtual void newTransaction(const WocTransaction&);
        private:
                QString m_basedir,m_subdir,m_fileext;
-               QString m_isauth,m_hasrole,m_username,m_authinit;
+               //QString m_isauth,m_hasrole,m_username,m_authinit;
+               QString m_transbase;
                QFile m_loader,m_schema,m_transact;
                
                /**helper: adds a loader line for a class to autoload.php*/