Session
Session objects are returned by the Session
command. These objects provide the developer with an interface allowing to manage the current user session and execute actions such as store contextual data, share information between session processes, launch session-related preemptive processes, or (web only) manage privileges.
Tipos de sessão
Três tipos de sessões são suportados por essa classe:
- Web user sessions: Web user sessions are available when scalable sessions are enabled in your project. Eles são usados para conexões Web e REST e podem receber privilégios.
- Remote client user sessions: In client/server applications, remote users have their own sessions managed on the server.
- Stored procedures session: All stored procedures executed on the server share the same virtual user session.
The availability of properties and functions in the Session
object depend on the session type.
Resumo
.clearPrivileges() : Boolean removes all the privileges associated to the session and returns True if the execution was successful |
.expirationDate : Text the expiration date and time of the session cookie |
.hasPrivilege( privilege : Text ) : Boolean returns True if the privilege is associated to the session, and False otherwise |
.id : Text the unique identifier (UUID) of the session on the server |
.idleTimeout : Integer the inactivity session timeout (in minutes), after which the session is automatically closed by 4D |
.info : Object describes the remote client or stored procedure session on the server |
.isGuest() : Boolean returns True if the session is a Guest session (i.e. it has no privileges) |
.setPrivileges( privilege : Text ) : Boolean .setPrivileges( privileges : Collection ) .setPrivileges( settings : Object ) : Boolean associates the privilege(s) and/or role(s) defined in the parameter to the session and returns True if the execution was successful |
.storage : Object a shared object that can be used to store information available to all processes of the session |
.userName : Text the user name associated to the session |
Session
História
Release | Mudanças |
---|---|
20 R5 | Support of remote client and stored procedure sessions |
18 R6 | Adicionado |
Session : 4D.Session
Parâmetro | Tipo | Descrição | |
---|---|---|---|
Resultados | 4D. Session | <- | Objecto Session |
Descrição
The Session
command returns the Session
object corresponding to the current user session.
Dependendo do processo a partir do qual o comando é chamado, a sessão atual do usuário pode ser:
- a web session (when scalable sessions are enabled),
- uma sessão de cliente remoto,
- a sessão de procedimentos armazenados.
For more information, see the Session types paragraph.
If the command is called from a non supported context (single-user application, scalable sessions disabled...), it returns Null.
Sessões web
The Session
object of web sessions is available from any web process:
On Web Authentication
,On Web Connection
, andOn REST Authentication
database methods,- código processado a través das etiquetas 4D nas páginas semidinâmicas (4DTEXT, 4DHTML, 4DEVAL, 4DSCRIPT/, 4DCODE)
- os métodos projeto com o atributo "Available through 4D tags and URLs (4DACTION...)" e chamados através de 4DACTION/ urls,
On Mobile App Authentication
andOn Mobile App Action
database methods for mobile requests,- Funções ORDA chamadas com solicitações REST.
For more information on web user sessions, please refer to the Web Server Sessions section.
Sessões cliente remoto
The Session
object of remote client sessions is available from:
- Project methods that have the Execute on Server attribute (they are executed in the "twinned" process of the client process),
- Triggers,
On Server Open Connection
andOn Server Shutdown Connection
database methods.
For more information on remote user sessions, please refer to the Remote client user sessions paragraph.
a sessão de procedimentos armazenados
Todos os processos de procedimento armazenado compartilham a mesma sessão de usuário virtual. The Session
object of stored procedures is available from:
- methods called with the
Execute on server
command, On Server Startup
,On Server Shutdown
,On Backup Startup
,On Backup Shutdown
, andOn System event
database methods
For information on stored procedures virtual user session, please refer to the 4D Server and the 4D Language page.
Exemplo
You have defined the action_Session
method with attribute "Available through 4D tags and URLs". Pode chamar ao método introduzindo a URL abaixo no navegador:
IP:port/4DACTION/action_Session
//action_Session method
Case of
:(Session#Null)
If(Session.hasPrivilege("WebAdmin")) //calling the hasPrivilege function
WEB SEND TEXT("4DACTION --> Session is WebAdmin")
Else
WEB SEND TEXT("4DACTION --> Session is not WebAdmin")
End if
Else
WEB SEND TEXT("4DACTION --> Session is null")
End case
.clearPrivileges()
História
Release | Mudanças |
---|---|
18 R6 | Adicionado |
.clearPrivileges() : Boolean
Parâmetro | Tipo | Descrição | |
---|---|---|---|
Resultados | Parâmetros | <- | True se a execução for bem-sucedida |
Descrição
This function does nothing and always returns False with remote client and stored procedure sessions.
The .clearPrivileges()
function removes all the privileges associated to the session and returns True if the execution was successful. Como resultado, a sessão torna-se automaticamente uma sessão de convidado.
Exemplo
//Invalidate a web user session
var $isGuest : Boolean
var $isOK : Boolean
$isOK:=Session.clearPrivileges()
$isGuest:=Session.isGuest() //$isGuest is True
.expirationDate
História
Release | Mudanças |
---|---|
18 R6 | Adicionado |
.expirationDate : Text
Descrição
Essa propriedade só está disponível com sessões de usuário da Web.
The .expirationDate
property contains the expiration date and time of the session cookie. The value is expressed as text in the ISO 8601 format: YYYY-MM-DDTHH:MM:SS.mmmZ
.
Essa propriedade é somente leitura. It is automatically recomputed if the .idleTimeout
property value is modified.