github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/azcore/session.go (about)

     1  package azcore
     2  
     3  import "github.com/alloyzeus/go-azfl/azid"
     4  
     5  // Session represents information about a session. Every action can
     6  // only be performed with an active session. A session is obtained through
     7  // authorization, or authentication, of a Terminal.
     8  //
     9  //TODO: scope, expiry.
    10  type Session[
    11  	SessionIDNumT SessionIDNum, SessionIDT SessionID[SessionIDNumT],
    12  	TerminalIDNumT TerminalIDNum, TerminalIDT TerminalID[TerminalIDNumT],
    13  	UserIDNumT UserIDNum, UserIDT UserID[UserIDNumT],
    14  	SessionSubjectT SessionSubject[
    15  		TerminalIDNumT, TerminalIDT, UserIDNumT, UserIDT,
    16  	],
    17  	SessionT any, // should be Session[...]
    18  ] interface {
    19  	// ID returns the identifier of this Session instance.
    20  	ID() SessionIDT
    21  
    22  	// DelegateSession returns the session that is a delegate of
    23  	// this session. It returns nil if this session is not a delegated session.
    24  	//
    25  	// A delegation is commonly used when a service is accessing another
    26  	// service on the behalf of a user.
    27  	DelegateSession() *SessionT
    28  
    29  	// ImpersonatorSession returns the session that is impersonating
    30  	// the subject of this session, i.e., the session that was used to create
    31  	// this session. It returns nil if this session is not an impersonation.
    32  	ImpersonatorSession() *SessionT
    33  
    34  	// Subject returns the subject of this session.
    35  	Subject() SessionSubjectT
    36  
    37  	// IsTerminal returns true if the authorized terminal is the same as termRef.
    38  	IsTerminal(termRef TerminalIDT) bool
    39  
    40  	// HasUserAsSubject returns true if the subject is a user instead of
    41  	// a service application.
    42  	HasUserAsSubject() bool
    43  
    44  	// IsUser checks if this session is represeting a particular user.
    45  	IsUser(userRef UserIDT) bool
    46  }
    47  
    48  type SessionIDNumMethods interface {
    49  	AZSessionIDNum()
    50  }
    51  
    52  // SessionIDNum abstracts the identifiers of Session entity instances.
    53  type SessionIDNum interface {
    54  	azid.IDNum
    55  
    56  	SessionIDNumMethods
    57  }
    58  
    59  // SessionID is used to refer to a Session entity instance.
    60  type SessionID[IDNumT SessionIDNum] interface {
    61  	azid.ID[IDNumT]
    62  
    63  	// SessionIDNum returns only the ID part of this ref-key.
    64  	SessionIDNum() IDNumT
    65  }