Porovnávané verzie

Kľúč

  • Tento riadok sa pridal
  • Riadok je odstránený.
  • Formátovanie sa zmenilo.

Often it is necessary to return from the RPC method only those data to which the user calling the RPC method has authorization. Sending a userName of the current user as a parameter of the RPC method is not a sufficient security measure because the SmartWeb architecture cannot prevent the logged in user to call the allowed RPC method with any parameters. This means that the user could identify through the userName parameter as someone else. That is why it is necessary to identify the calling user in particular ways described below. 

The Smart Web supports authentication through D2000 users or through applicatively defined users in which case the SmartWeb server realizes the authentication through calling defined authentication RPC method. 

Identification of D2000 User in RPC Method

In the case that the Smart Web application realizes the authentication through D2000 users, it is possible to call the GetUserObjName function in any RPC method that will return the userName of currently logged in user. 

Identification of Applicatively Defined User in RPC Method

In the case of applicatively defined users, the process is more complicated and requires creating of a data container through the CNT_CREATE method where the key to container values will be the HOBJ of the logged in session and the value to the key userName. The container will be filled with calling CNT_INSERT in the so-called logon method which will be called by SmartWeb in every successful login. Acquiring a user name is then realized through calling CNT_GETITEM in the RPC method. A sample implementation of this functionality is presented below. RPC methods that need to identify a logged in user only have to call the method 

Často krát je potrebné vrátiť z RPC metódy iba tie dáta na ktoré má používateľ volajúci RPC metódu oprávnenie. Posielanie userName aktuálneho používateľa ako parametra RPC metódy nie je dostatočný spôsob zabezpečenia, pretože architektúra Smart Webu nevie zabrániť prihlásenému používateľovi zavolať povolenú RPC metódu s akýmikoľvek parametrami. To znamená že používateľ by sa vedel identifikovať cez parameter userName ako niekto úplne iný. Z tohto dôvodu je potrebné identifikovať volaného používateľa spôsobmi popísanými nižšie.

Smart Web podporuje autentifikáciu cez D2000 používateľov alebo prostredníctvom aplikačne definovaných používateľov, kedy Smart Web server realizuje autentifikáciu cez volanie definovanej autentifikačnej RPC metódy.

Identifikácia D2000 používateľa v RPC metóde

V prípade že Smart Web aplikácia realizuje autentifikáciu cez D2000 používateľov je možné v akejkoľvek RPC metóde zavolať funkciu GetUserObjName, ktorá vráti userName aktuálne prihláseného používateľa.

Identifikácia aplikačne definovaného používateľa v RPC metóde

V prípade aplikačne definovaných používateľov je postup zložitejší a vyžaduje si vytvorenia kontajnera dát cez metódu CNT_CREATE, kde kľúčom k hodnotám kontajnera bude HOBJ prihlásenej session a hodnotou ku kľúču userName. Kontainer sa bude plniť volaním CNT_INSERT v tzv logon metóde, ktorú bude Smart Web volať pri každom úspešnom prihlásení. V RPC metóde je potom získanie používateľského mena realizované cez volanie CNT_GETITEM. Vzorová implementácia tejto funkcionality je uvedená nižšie. RPC metódy, ktoré potrebujú identifikovať prihláseného používateľa stačí len zavolať metódu getCurrentUserName.

Blok kódu
languageesl
themeRDark
INT _CNT_sessions ;kontajner vsetkych aktivnych session vsetkych pouzivatelov container of all active sessions of all users 

; metodamethod jeis zaregistrovanaregistered vin Smart Web aplikaciiapplication akoas "logOn" metodamethod,
; ktorawhich sais volacalled poafter kazdejevery uspesnejsuccessful autentifikaciiauthentication
RPC PROCEDURE logOn(IN TEXT _UserName, BOOL _Ok) 
  INT _hobj_session
  BOOL _bFound
  _Ok := @TRUE

  _hobj_session := %GetRPCCallerProcess()
  ; kontrolacontrol existencieof session existence, nesmiecannot existovatexist, opacnyopposite stavstate jeis chybaerror
  CNT_FIND _CNT_sessions, _hobj_session, _UserName, _bFound
  IF _bFound THEN
    LOGEX "ERR: uzsame SESSION existujeof rovnakauser SESSIONalready pouzivatelaexists: " + %IToStr(_hobj_session) PRIORITY _LOG_PRTY_ERROR
    _Ok := @FALSE
    RETURN
  ENDIF
  ; registration registraciaof volaniecalling metodymethod onSessionClosed priin "zmenesession sessionchange", 
  ; t.j. bud standardne odhlasenie alebo akekolvek ine ukoncenie sessionmeaning either standard logout or any other session ending
  _Ok := %OpenRefToObject(_hobj_session, @TRUE)
  IF !_Ok THEN
    LOGEX "ERR: neznamaunknown SESSION prefor otvorenieopening: " + %IToStr(_hobj_session) PRIORITY _LOG_PRTY_ERROR   
    RETURN
  ENDIF  
  ON CHANGE (_hobj_session) GOTO onSessionClosed
  ; vlozenieinserting of mapovaniamapping "session HOBJ -> user name" doinot kontaineracontainer
  CNT_INSERT _CNT_sessions, _hobj_session, _UserName  
END logOn

; zrusenaended user session pouzivatela (odhlasenim alebo inym dovodom zrusenia session pouzivatela(by logout or by other ending of user session)
PROCEDURE onSessionClosed(IN INT _procValue, IN ALIAS _hobj, IN INT _row, _col)
  BOOL _bFound
  INT _hobj_session
  TEXT _userName
  _hobj_session := _hobj\HBJ

  CNT_FIND _CNT_sessions, _hobj_session, _userName, _bFound
  IF ! _bFound THEN
    LOGEX "ERR: neznamaunknown SESSION bolawas ukoncenaended " + %IToStr(_hobj_session) PRIORITY _LOG_PRTY_ERROR
    RETURN
  ENDIF
  CNT_DELETE _CNT_sessions, _hobj_session 
  %CloseRefToObject(_hobj_session)
  ON CHANGE (_hobj_session) GOTO onSessionClosed NONE
END onSessionClosed

; RPC metóda vráti meno aktuálne prihláseného používateľamethod returns name of currently logged in user
RPC PROCEDURE getCurrentUserName(TEXT _userName)
  INT _hobj_session
  BOOL _bFound
  _hobj_session := %GetRPCCallerProcess()  
  CNT_FIND _CNT_sessions, _hobj_session, _userName, _bFound
  IF ! _bFound THEN
    LOGEX "ERR: neznamaunknown SESSION bolawas ukoncenaended " + %IToStr(_hobj_session) PRIORITY _LOG_PRTY_ERROR
    RETURN
  ENDIF
END getCurrentUserName

BEGIN
  CNT_CREATE _CNT_sessions
END

...