public final class SessionControl extends Object
DbControl
objects which are needed to access the database.Application.newSessionControl(String, String, String)
,
Application.getSessionControl(String, String)
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
Clean up if a bad client application forgets to logout.
|
int |
getActiveProjectId()
Get the id of the active project, or 0 if no project is active.
|
String |
getChallenge()
Generate a new random string to be used for password encryption in the
login method.
|
String |
getClientDefaultSetting(String name)
Get the value of the ClientDefaultSetting with the specified name.
|
int |
getClientId()
Get the id of the
Client application in use. |
String |
getExternalClientId()
Get the external id of the
Client application in use. |
Set<Integer> |
getFriends()
Get the id of all friends to logged in user.
|
Set<Integer> |
getGroups()
Get the id of all groups where the logged in user is a member, directly
or indirectly.
|
String |
getId()
Get the id of this
SessionControl . |
Set<Integer> |
getItemKeys()
Get the id of all item keys where the logged in user has a permission.
|
int |
getLoggedInUserId()
Get the id of the logged in user, or 0 if no user is logged in.
|
int |
getLoggedInUserIdAdminInfo()
Get the id of the logged in user, or 0 if no user is logged in.
|
int |
getProjectKeyId()
Get the id of the
ProjectKey that can be used to share an item to
the active project with full permission, or 0 if no project is active or
the logged in user only has read permission to the active project. |
Set<Integer> |
getProjectKeys()
Get the id of all project keys where the logged in user has a permission.
|
Set<Integer> |
getProjects()
Get the id of all projects where the logged in user is a member, directly
or indirectly.
|
Set<Integer> |
getRoles()
Get the id of all roles where the logged in user is a member.
|
Object |
getSessionSetting(String name)
Get the value of a session setting with the specified name.
|
String |
getUserClientSetting(String name)
Get the value of the UserClientSetting with the specified name.
|
String |
getUserDefaultSetting(String name)
Get the value of the UserDefaultSetting with the specified name.
|
boolean |
hasPermission(Permission permission,
Item itemType)
Check if the logged in user has the specfied permission for all item of
the specified type.
|
boolean |
hasSystemPermission(Permission permission)
Check if the logged in user has the specified system permission.
|
SessionControl |
impersonateLogin(int userId,
String comment)
Log in as another user.
|
boolean |
isFriendOf(User user)
Check if the logged in user is a friend of of the specified user.
|
boolean |
isImpersonated()
Check if the logged in user was impersonated by another user.
|
boolean |
isLoggedIn()
Checks if a user is logged in or not.
|
boolean |
isLoggedInAdminInfo()
Checks if a user is logged in or not.
|
boolean |
isMemberOf(Group group)
Check if the logged in user is a member, directly or indirectly, of the
specified group.
|
boolean |
isMemberOf(Project project)
Check if the logged in user is a member, directly or indirectly, of the
specified project.
|
boolean |
isMemberOf(Role role)
Check if the logged in user is a member of the specified role.
|
void |
login(String login,
String password,
String comment,
boolean encryptedPassword)
Log in to Proteios.
|
void |
logout()
Log out of Proteios.
|
DbControl |
newDbControl()
Create a new
DbControl object for this session. |
void |
reloadPermissions()
Tell the core to reload the logged in users permission the next time the
client application needs to check the permissions.
|
void |
reloadSettings(boolean onlyClientDefaultSettings,
boolean saveCurrentUserSettings)
Reloads user- and client-specific settings.
|
void |
setActiveProject(Project project)
Set the active project.
|
Object |
setSessionSetting(String name,
Object value)
Set the value of a session setting.
|
String |
setUserClientSetting(String name,
String value)
Set the value of a UserClientSetting.
|
String |
setUserDefaultSetting(String name,
String value)
Set the value of a UserDefaultSetting.
|
public String getId()
SessionControl
. Use this value for
retrieving the object from the Application
cache.Application.getSessionControl(String,String)
public int getClientId()
Client
application in use.public String getExternalClientId()
Client
application in use.getClientId()
public DbControl newDbControl() throws BaseException
DbControl
object for this session.DbControl
objectBaseException
- If there is an errorpublic String getChallenge()
MD5:challenge
login(String, String, String, boolean)
public void login(String login, String password, String comment, boolean encryptedPassword) throws ItemNotFoundException, PermissionDeniedException, InvalidPasswordException, BaseException
The encryptedPassword
parameter is used if the client
application sends the password encrypted. See getChallenge()
for
information about how to encrypt the password.
login
- The login of the userpassword
- The password for the usercomment
- A comment for the login, which will show in the
Session
encryptedPassword
- A flag indicating if the password has been
encrypted or notItemNotFoundException
- If a user with the specified username is
not foundInvalidPasswordException
- If the specified password is incorrectPermissionDeniedException
- If the user doesn't have
Permission.USE
permission for the current client
application or if a user is already logged inBaseException
- If there is any other errorlogout()
,
isLoggedIn()
,
getLoggedInUserId()
public SessionControl impersonateLogin(int userId, String comment) throws ItemNotFoundException, PermissionDeniedException, BaseException
SessionControl
object which is equivalent to a
SessionControl
where that user logged in by normal means.
This method requires that the logged in user has
Permission.ACT_AS_ANOTHER_USER
permission.userId
- The id of the user to login ascomment
- A comment that will be placed in the Session
informationSessionControl
objectItemNotFoundException
- If no user with the specified id existsPermissionDeniedException
- If the logged in user doesn't have
Permission.ACT_AS_ANOTHER_USER
permissionBaseException
- If there is another errorpublic void logout() throws BaseException
DbControl
objects still open, they
will be closed. Changes made to items managed by those
DbControl
objects will be lost unless the items are
connected to a new DbControl
object.BaseException
- If there is an errorlogin(String, String, String, boolean)
,
isLoggedIn()
,
impersonateLogin(int, String)
,
isImpersonated()
public boolean isLoggedIn()
login(String, String, String, boolean)
,
logout()
,
getLoggedInUserId()
public boolean isLoggedInAdminInfo()
login(String, String, String, boolean)
,
logout()
,
getLoggedInUserId()
public int getLoggedInUserId()
User.getById(DbControl, int)
to get the User
object.public int getLoggedInUserIdAdminInfo()
User.getById(DbControl, int)
to get the User
object.
Intended for administrative info only,
therefore does not update last access
time.public boolean isImpersonated()
impersonateLogin(int, String)
public void reloadPermissions()
public void reloadSettings(boolean onlyClientDefaultSettings, boolean saveCurrentUserSettings) throws BaseException
saveCurrentUserSettings
- Setting this to TRUE will save the current
user-specific settings before reloading them. This parameter is
ignored if onlyClientDefaultSettings
is true (This
feature is current not implemented)BaseException
- If the settings cannot be reloadedpublic int getActiveProjectId()
Project.getById(DbControl, int)
to get the Project
object.setActiveProject(Project)
public void setActiveProject(Project project) throws PermissionDeniedException, BaseException
Shareable
items will automatically be shared to the active project with delete
permission. The active project doesn't affect already existing items.project
- The project to make activePermissionDeniedException
- If the logged in user doesn't have
Permission.USE
permission for the projectBaseException
- If there is another errorgetActiveProjectId()
public int getProjectKeyId()
ProjectKey
that can be used to share an item to
the active project with full permission, or 0 if no project is active or
the logged in user only has read permission to the active project. Use
ProjectKey.getById(DbControl, int)
to get the ProjectKey
object.public boolean hasSystemPermission(Permission permission)
permission
- One of the system permission constants defined by the
Permission
enumerationpublic boolean hasPermission(Permission permission, Item itemType)
permission
- One of the permissions constants defined by the
Permission
enumerationitemType
- One of the item constants defined by the Item
enumerationpublic boolean isMemberOf(Group group)
group
- The group to checkpublic boolean isMemberOf(Role role)
role
- The role to checkpublic boolean isMemberOf(Project project)
project
- The project to checkpublic boolean isFriendOf(User user)
user
- The user to checkpublic Set<Integer> getRoles()
Set
containing role id:spublic Set<Integer> getGroups()
Set
containing group id:spublic Set<Integer> getFriends()
Set
containing user id:spublic Set<Integer> getProjects()
Set
containing project id:spublic Set<Integer> getItemKeys()
Set
containing item key id:spublic Set<Integer> getProjectKeys()
Set
containing project key id:spublic Object getSessionSetting(String name)
name
- The name of the settingpublic Object setSessionSetting(String name, Object value)
name
- The name of the settingvalue
- The new value of the setting, or null to remove the settingpublic String getUserClientSetting(String name)
name
- The name of the settingpublic String setUserClientSetting(String name, String value)
name
- The name of the settingvalue
- The new value of the setting, or null to remove the settingpublic String getUserDefaultSetting(String name)
name
- The name of the settingpublic String setUserDefaultSetting(String name, String value)
name
- The name of the settingvalue
- The new value of the setting, or null to remove the settingpublic String getClientDefaultSetting(String name)
name
- The name of the setting