Initializing a session for the SmartFramework Authorization subsystem
The following code demonstrates how a session can be initialized programatically so that the autorization API's will function properly. The code might be used using (Unit-)Tests, data imports or similar batch routines.
/* *************************** Definitions ************************** */ ROUTINE-LEVEL ON ERROR UNDO, THROW. USING Consultingwerk.Framework.Session.* FROM PROPATH . USING Consultingwerk.OERA.* FROM PROPATH . USING Consultingwerk.SmartFramework.Authentication.* FROM PROPATH . USING Consultingwerk.SmartFramework.System.* FROM PROPATH . USING Progress.Lang.* FROM PROPATH . {Consultingwerk/SmartFramework/Authorization/ttSecurityItemKeys.i} DEFINE VARIABLE oLoginCompany AS LoginCompanyDatasetModel NO-UNDO . DEFINE VARIABLE oUser AS UserDatasetModel NO-UNDO . DEFINE VARIABLE oGetGroupsParameter AS GetUserGroupAssignmentsParameter NO-UNDO . DEFINE VARIABLE hDataset AS HANDLE NO-UNDO . /* *************************** Main Block *************************** */ oLoginCompany = NEW LoginCompanyDatasetModel() . oUser = NEW UserDatasetModel() . oLoginCompany:SmartLoginCompany:Filter:LoginCompanyShort:EQ("Consultingwerk"):Run() . IF NOT oLoginCompany:SmartLoginCompany:Available THEN UNDO, THROW NEW AppError ("Invalid login company.", 0) . oUser:SmartUser:Filter:UserName:EQ("mikefe"):Run() . IF NOT oUser:SmartUser:Available THEN UNDO, THROW NEW AppError ("Invalid user.", 0) . ASSIGN SessionManager:LoginCompanyKey = oLoginCompany:SmartLoginCompany:LoginCompanyGuid SessionManager:LoginCompanyName = oLoginCompany:SmartLoginCompany:LoginCompanyName SessionManager:UserName = oUser:SmartUser:UserName SessionManager:UserKey = oUser:SmartUser:UserGuid . oGetGroupsParameter = NEW GetUserGroupAssignmentsParameter (SessionManager:UserName, SessionManager:LoginCompanyKey) . ServiceInterface:InvokeMethod ("Consultingwerk.SmartFramework.Authentication.UserBusinessEntity":U, "GetUserGroupAssignments":U, INPUT-OUTPUT DATASET-HANDLE hDataset, oGetGroupsParameter) . ASSIGN SessionManager:UserGroupKeys = oGetGroupsParameter:GroupGuids SessionManager:UserGroupNames = oGetGroupsParameter:GroupNames .