Use this class to determine if a user is logged in and if they have 'permission' to perform tasks. More...
#include <ms_security_session.hpp>
Public Member Functions | |
ms_session (const int timeout, const std::string prefix) | |
Use this constructor to start a new session independent of users and Mascot security. | |
ms_session (const std::string session_id="") | |
Use this constructor to open the current session. | |
ms_session (const std::string userName, const std::string connectionID, const std::string database) | |
This constructor is used by Mascot integra to login to Mascot. | |
ms_session (const std::string userName, const std::string userPassword) | |
Use this constructor to start a new secure session. | |
void | appendErrors (const ms_errors &src) |
Copies all errors from another instance and appends them at the end of own list. | |
bool | canResultsFileBeViewed (const int userID) const |
Check if a results file with the passed user ID can be viewed. | |
void | clearAllErrors () |
Remove all errors from the current list of errors. | |
bool | clearParam (const std::string name) |
Remove a custom parameter from the session file. | |
void | copyFrom (const ms_errors *right) |
Use this member to make a copy of another instance. | |
bool | destroy () |
Destroy the current session. Should be called when a user logs out. | |
bool | getBoolParam (const std::string name, bool ¶m) const |
Return a custom 'bool' parameter from the session file. | |
double | getDoubleParam (const std::string name) const |
Return a custom 'double' parameter from the session file. | |
bool | getDoubleParam (const std::string name, double ¶m) const |
Return a custom 'double' parameter from the session file. | |
std::string | getEmailAddress () const |
Return the email address for the currently logged in user. | |
const ms_errs * | getErrorHandler () const |
Retrive the error object using this function to get access to all errors and error parameters. | |
std::string | getFullUserName () const |
Return the full name for the currently logged in user. | |
std::string | getID () const |
Return the sessionID for this session file. | |
int | getIntParam (const std::string name) const |
Return a custom 'integer' parameter from the session file. | |
bool | getIntParam (const std::string name, int ¶m) const |
Return a custom 'integer' parameter from the session file. | |
std::string | getIPAddress () const |
Return ip address of the currently logged in user. | |
time_t | getLastAccessed () const |
Returns the time that the session was last updated. | |
int | getLastError () const |
Return the error description of the last error that occurred. | |
std::string | getLastErrorString () const |
Return the error description of the last error that occurred. | |
long | getLongParam (const std::string name) const |
Return a custom 'long' parameter from the session file. | |
bool | getLongParam (const std::string name, long ¶m) const |
Return a custom 'long' parameter from the session file. | |
std::map< std::string, std::string > | getParams () const |
Returns a list of all the parameters saved in the session file. | |
matrix_science::ms_security_tasks | getPermittedTasks () const |
Returns the permitted tasks for the currently logged in user. | |
std::vector< int > | getSpoofableUsers () const |
Returns a list of user IDs that can be spoofed. | |
std::string | getStringParam (const std::string name) const |
Return a custom 'string' parameter from the session file. | |
bool | getStringParam (const std::string name, std::string ¶m) const |
Return a custom 'string' parameter from the session file. | |
time_t | getTimeout () const |
Returns the time when the session times out. | |
time_t | getTimeParam (const std::string name) const |
Return a custom 'time' parameter from the session file. | |
bool | getTimeParam (const std::string name, time_t ¶m) const |
Return a custom 'time' parameter from the session file. | |
int | getUserID () const |
Return the unique userid for the currently logged in user. | |
std::string | getUserName () const |
Return the user 'login' name for the currently logged in user. | |
matrix_science::ms_user::usertype | getUserType () const |
Returns the type of user. | |
bool | isFastaPermitted (const std::string database) const |
Check if a particular fasta file can be accessed. | |
bool | isPermitted (const int taskID) const |
Check if the task is permitted. | |
bool | isPermitted_double (const int taskID, const double value) const |
Check if the value is in the floating point parameter list. | |
bool | isPermitted_long (const int taskID, const long value) const |
Check if the value is in the long integer parameter list. | |
bool | isPermitted_string (const int taskID, const std::string value) const |
Check if the value is in the string parameter list. | |
bool | isSecurityEnabled () const |
Return true if the security system is enabled. | |
bool | isTimedOut () const |
Returns true if the current session has timed out. | |
bool | isValid () const |
Call this function to determine if there have been any errors. | |
bool | saveBoolParam (const std::string name, bool param) |
Save a custom 'bool' parameter in the session file. | |
bool | saveDoubleParam (const std::string name, double param) |
Save a custom 'double' parameter in the session file. | |
bool | saveIntParam (const std::string name, int param) |
Save a custom 'integer' parameter in the session file. | |
bool | saveLongParam (const std::string name, long param) |
Save a custom 'long integer' parameter in the session file. | |
bool | saveStringParam (const std::string name, const std::string param) |
Save a custom 'string' parameter in the session file. | |
bool | saveTimeParam (const std::string name, time_t param) |
Save a custom 'time' parameter in the session file. | |
bool | setPermittedTasks (const matrix_science::ms_security_tasks &val) |
Sets the permitted tasks for the currently logged in user. | |
bool | update (const ms_security &sec) |
Only needs to be called by administration applications after user rights have changed. | |
Use this class to determine if a user is logged in and if they have 'permission' to perform tasks.
This is the only security class that most applications will need to use. This class should be used even if security is disabled because the underlying structure deals with this. If security is disabled, then isValid() and isPermitted() will both return true.
Session information is saved in files in the ../sessions
directory. The session files have the same name as the session id which will be of the general form 'username_uniquenumber'. The unique number is assigned by the system and the username is the login name.
Special cases are as follows:
Session Name | Description |
---|---|
[username]_[random_number] | Session name for a normal user. |
[username]_webserverauth | Session name for a user logged in using web authentication. This session file is created/modified when the user is modified. It is not possible to use this session id unless the user is 'logged into' the web server using the name 'username' |
all_secdisabledsession | The Mascot security system is not enabled. This session file will only exist if security is disabled. Attempts to use it when security is enabled will fail. |
cmd_cmdlinesession | Any applications run directly from a shell or command prompt will use this session id. Any script run directly as a cgi application (or chained from a cgi script) will not be able to use this session id. |
guest_guestsession | Any user who is logged in as 'guest'. If the guest account is not enabled, this session will not be available |
[name]_computername | for 3rd party applications that have not implemented Mascot security, it is possible to specify a computer name rather than a login name and password. |
[ipaddr]_computeripaddress | For 3rd party applications that have not implemented Mascot security, it is possible to specify an ip address rather than a login name and password. |
[string]_agentstring | Agent string such as 'Mozilla'. Will only be used a last resort by third party applications. |
integradb@name_session | Mascot integra user. The integradb is the value returned by: ms_security_options::getIntegraDatabaseName(). Internally, this session id will be translated into a Mascot Integra session string by replacing the @ with a pipe symbol, and removing the underscore between the name and the session. The Mascot cookie will be this session id, and not the Integra connection string. There is a special case of the user being (system) . |
ms_session | ( | const std::string | session_id = "" | ) |
Use this constructor to open the current session.
Call isValid() to check that a session was opened. If isValid() returns false, then getLastError() should be called to determine an appropriate action, such as asking a user to login.
A successful call to this constructor will cause the last accessed time to be updated (for ms_user::USER_NORMAL only).
If the session_id parameter is empty, then this constructor will try the following in turn:
MASCOT_SESSION=
). REMOTE_USER
environment variable set) use cmd_cmdlinesession
, with all access rights. REMOTE_USER
– if that fails, try guest. isPermitted() should be then be called as required to determine if the user can perform certain actions.
Possible errors, and suitable actions for an interactive application, are:
session_id | If session_id is empty, then this constructor will try to find session_id from a cookie (MASCOT_SESSION= ). |
ms_session | ( | const std::string | userName, |
const std::string | userPassword | ||
) |
Use this constructor to start a new secure session.
The value from getID() should the be saved in a cookie.
Possible errors, and suitable actions for an interactive application, are:
userName | is the user name entered by the user. |
userPassword | is the unencrypted password. |
ms_session | ( | const std::string | userName, |
const std::string | connectionID, | ||
const std::string | database | ||
) |
This constructor is used by Mascot integra to login to Mascot.
This constructor should only be used from Mascot Integra, or an application running in the Integra environment. The Integra application will have access to the currently logged in user name, and also to the Integra connectionID.
Possible errors, and suitable actions for an interactive application, are:
If this function succeeds, it will set session_id
to a session variable of the form database@userName_connectionID
.
userName | is the Integra user name. |
connectionID | is the Integra connection string. |
database | is the name of the Mascot integra database. |
ms_session | ( | const int | timeout, |
const std::string | prefix | ||
) |
Use this constructor to start a new session independent of users and Mascot security.
timeout | is the inactivity time in seconds before the session becomes timed out. A value of zero indicates it will never time out. |
prefix | is a prefix to be used as the session id: will be of the form prefix_randomnumber . |
|
inherited |
Copies all errors from another instance and appends them at the end of own list.
src | The object to copy the errors across from. See Maintaining object references: two rules of thumb. |
bool canResultsFileBeViewed | ( | const int | userID | ) | const |
Check if a results file with the passed user ID can be viewed.
This is a helper function to make end user programs simpler.
userID | is the USERID value from the results file. Old results files don't have this value, in which case ms_searchparams::getUSERID() will return 0. |
|
inherited |
Remove all errors from the current list of errors.
The list of 'errors' can include fatal errors, warning messages, information messages and different levels of debugging messages.
All messages are accumulated into a list in this object, until clearAllErrors() is called.
See Error Handling.
bool clearParam | ( | const std::string | name | ) |
Remove a custom parameter from the session file.
Use this function when you no longer want a value associated with a key name.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
|
inherited |
Use this member to make a copy of another instance.
right | is the source to initialise from |
bool destroy | ( | ) |
Destroy the current session. Should be called when a user logs out.
The session file is deleted and all user parameters are removed. Don't attempt to use the object after calling destroy().
bool getBoolParam | ( | const std::string | name, |
bool & | param | ||
) | const |
Return a custom 'bool' parameter from the session file.
See also Using custom parameters
name | name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
double getDoubleParam | ( | const std::string | name | ) | const |
Return a custom 'double' parameter from the session file.
If a value of 0 is returned, it is not possible to determine if this is because there is no key value or if a value of zero was set for the key.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
bool getDoubleParam | ( | const std::string | name, |
double & | param | ||
) | const |
Return a custom 'double' parameter from the session file.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
std::string getEmailAddress | ( | ) | const |
Return the email address for the currently logged in user.
Note that there is no guarantee that this is a valid email address.
|
inherited |
Retrive the error object using this function to get access to all errors and error parameters.
See Error Handling.
std::string getFullUserName | ( | ) | const |
Return the full name for the currently logged in user.
std::string getID | ( | ) | const |
Return the sessionID for this session file.
This the same as the session filename. If isValid() returns false, this will return an empty string. System session ids are described in ms_session::ms_session.
int getIntParam | ( | const std::string | name | ) | const |
Return a custom 'integer' parameter from the session file.
If a value of 0 is returned, it is not possible to determine if this is because there is no key value or if a value of zero was set for the key.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
bool getIntParam | ( | const std::string | name, |
int & | param | ||
) | const |
Return a custom 'integer' parameter from the session file.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
std::string getIPAddress | ( | ) | const |
Return ip address of the currently logged in user.
Will be 'UNKNOWN' if authentication is turned off and for the guest account.
time_t getLastAccessed | ( | ) | const |
Returns the time that the session was last updated.
Note that this time is not valid if authentication is turned off or the guest account is in use.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
long getLongParam | ( | const std::string | name | ) | const |
Return a custom 'long' parameter from the session file.
If a value of 0 is returned, it is not possible to determine if this is because there is no key value or if a value of zero was set for the key.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
bool getLongParam | ( | const std::string | name, |
long & | param | ||
) | const |
Return a custom 'long' parameter from the session file.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
std::map< std::string, std::string > getParams | ( | ) | const |
Returns a list of all the parameters saved in the session file.
ms_security_tasks getPermittedTasks | ( | ) | const |
Returns the permitted tasks for the currently logged in user.
std::vector< int > getSpoofableUsers | ( | ) | const |
Returns a list of user IDs that can be spoofed.
This will return an empty list if ms_security_tasks::SECTASK_ALLOWSPOOFOTHERUSER has not been specified.
If ms_security_tasks::SECTASK_SPOOFNAMEDGROUPSONLY is not specified, then this function returns all users by calling ms_security::getAllUserIDs().
If ms_security_tasks::SECTASK_SPOOFNAMEDGROUPSONLY is specified, then only users belonging to the names groups will be returned. This could be an empty list if the named groups don't contain any users or if there is no list of groups.
When ms-status.exe
(or get_params.pl
) is called with the parameter Show=MS_USERS
, this function is called to create a list of users. The output format from these programs is:
"username","user id","user type","full name","email address"
For example:
C:\Inetpub\mascot\x-cgi>ms-status.exe Show=MS_USERS Content-type: text/plain "guest","1","1","Guest user","guest@localhost" "admin","2","1","Administrator","admin@localhost" "daemon","4","1","Mascot Daemon","daemon@localhost" "(system)","6","2","Mascot Integra system account","integra@localhost"
std::string getStringParam | ( | const std::string | name | ) | const |
Return a custom 'string' parameter from the session file.
If an empty string is returned, it is not possible to determine if this is because there is no key value or if an empty string was set for the key.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
bool getStringParam | ( | const std::string | name, |
std::string & | param | ||
) | const |
Return a custom 'string' parameter from the session file.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
time_t getTimeout | ( | ) | const |
Returns the time when the session times out.
Note that the timeout is not valid if authentication is turned off or the guest account is in use.
A value of zero indicates it will never time out.
Note also that the timeout is set globally in the security settings, so the return value of this function is the same as calling ms_security_options::getSessionTimeout() . The only case where the two can differ is if 1) the user logs in and 2) the session timeout is changed globally after that.
time_t getTimeParam | ( | const std::string | name | ) | const |
Return a custom 'time' parameter from the session file.
If a value of 0 is returned, it is not possible to determine if this is because there is no key value or if a value of zero was set for the key.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
bool getTimeParam | ( | const std::string | name, |
time_t & | param | ||
) | const |
Return a custom 'time' parameter from the session file.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | Is the value of the parameter associated with the key name. |
int getUserID | ( | ) | const |
Return the unique userid for the currently logged in user.
std::string getUserName | ( | ) | const |
Return the user 'login' name for the currently logged in user.
Note that this will not include spaces. The full user name is available by calling: getFullUserName().
ms_user::usertype getUserType | ( | ) | const |
Returns the type of user.
bool isFastaPermitted | ( | const std::string | database | ) | const |
Check if a particular fasta file can be accessed.
Check if a user has rights to search against a particular database This is a special case because SECTASK_NAMEDFASTA is the only 'negative' task (and only if SECTASK_ALLFASTA is set), so this specific call makes end user programs simpler.
database | is the database name – for example MSDB. |
bool isPermitted | ( | const int | taskID | ) | const |
Check if the task is permitted.
Returns true if the user is allowed to perform the task. If security is disabled, then this always returns true.
taskID | Task IDs are stored in security_tasks.xml file. |
bool isPermitted_double | ( | const int | taskID, |
const double | value | ||
) | const |
Check if the value is in the floating point parameter list.
taskID | The taskID normally from the matrix_science::ms_security_tasks::TASKID enumeration – for example, matrix_science::ms_security_tasks::SECTASK_MAXQUERIES. |
value | is the value for comparison. |
bool isPermitted_long | ( | const int | taskID, |
const long | value | ||
) | const |
Check if the value is in the long integer parameter list.
For example, this could called by an application to determine if a user has rights to run a search with 1000 spectra.
taskID | The taskID normally from the matrix_science::ms_security_tasks::TASKID enumeration – for example, matrix_science::ms_security_tasks::SECTASK_MAXQUERIES. |
value | is the value for comparison. |
bool isPermitted_string | ( | const int | taskID, |
const std::string | value | ||
) | const |
Check if the value is in the string parameter list.
For example, this could called by an application to determine if a user has rights to run a search against the MSDB database.
taskID | The taskID normally from the matrix_science::ms_security_tasks::TASKID enumeration – for example, matrix_science::ms_security_tasks::SECTASK_NAMEDFASTA. |
value | is the value for comparison. |
bool isSecurityEnabled | ( | ) | const |
Return true if the security system is enabled.
If this returns false, then isPermitted() will also always return true.
bool isTimedOut | ( | ) | const |
Returns true if the current session has timed out.
Some sessions such as the commandline session will never time out.
|
inherited |
Call this function to determine if there have been any errors.
This will return true unless there have been any fatal errors.
See Error Handling.
bool saveBoolParam | ( | const std::string | name, |
bool | param | ||
) |
Save a custom 'bool' parameter in the session file.
This can be useful for saving additional information that will be available to a cgi program later on in the same session. The value can be retrieved using getBoolParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool saveDoubleParam | ( | const std::string | name, |
double | param | ||
) |
Save a custom 'double' parameter in the session file.
This can be useful for saving additional information that will be available to a cgi program later on in the same session. The value can be retrieved using getDoubleParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool saveIntParam | ( | const std::string | name, |
int | param | ||
) |
Save a custom 'integer' parameter in the session file.
This can be useful for saving additional information that will be available to a CGI program later on in the same session. The value can be retrieved using getIntParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool saveLongParam | ( | const std::string | name, |
long | param | ||
) |
Save a custom 'long integer' parameter in the session file.
This can be useful for saving additional information that will be available to a cgi program later on in the same session. The value can be retrieved using getLongParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool saveStringParam | ( | const std::string | name, |
const std::string | param | ||
) |
Save a custom 'string' parameter in the session file.
This can be useful for saving additional information that will be available to a CGI program later on in the same session. The value can be retrieved using getStringParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool saveTimeParam | ( | const std::string | name, |
time_t | param | ||
) |
Save a custom 'time' parameter in the session file.
This can be useful for saving additional information that will be available to a cgi program later on in the same session. The value can be retrieved using getTimeParam().
This function will fail if isValid() is false.
There is just one list of parameters saved in the session for all types, so the same name shouldn't be used for say both integer and string values.
See also Using custom parameters
name | Name of the key value. Do not use an name with a leading underscore as these are reserved for system values. |
param | The value to be assigned to the key. |
bool setPermittedTasks | ( | const matrix_science::ms_security_tasks & | val | ) |
Sets the permitted tasks for the currently logged in user.
This function is called by the administration utility so that it can save a list of tasks in a temporary session. It shouldn't normally be called by other applications.
val | is the 'list' of the tasks that can be performed by the user. |