A
- type of AppUserpublic interface SessionService<A extends AppUser> extends Contexed, AppContextService<SessionService<A>>
AppContextService
for managing session information.
This encodes all information about the current authenticated user, most importantly their
roles. The users may also have a database representation as an AppUser
object which can also be
stored in this service.
If no database representation of the users is required then the getLoginFactory should return null
but the getName and role methods can still be used.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ADMIN_ROLE
Default administrator role.
|
Modifier and Type | Method and Description |
---|---|
void |
addSecurityContext(java.util.Map att)
Add context parameters for security logging.
|
boolean |
canHaveRole(A user,
java.lang.String role)
query the default role set for the specified user.
|
default boolean |
canHaveRoleFromList(A user,
java.lang.String... roles) |
void |
clearCurrentPerson()
remove the current person
|
void |
flushRelationships()
clear the internal relationship cache as things may have changed
|
boolean |
getApplyToggle()
are toggle roles currently enabled
|
java.lang.Object |
getAttribute(java.lang.String key)
retrieve an object stored in the session.
|
java.util.Date |
getAuthenticationTime()
If there is a current user return the time they authenticated
This should only record a user-present authentication not API access via a token
|
java.lang.String |
getAuthenticationType()
Get the authentication type used for the session.
|
A |
getCurrentPerson()
get the current person if known
|
BaseFilter<A> |
getGlobalRoleFilter(java.lang.String role)
get a
BaseFilter for all AppUser s who
have access to a global role. |
java.util.Locale |
getLocale()
Get the Locale to use in the current context
|
AppUserFactory<A> |
getLoginFactory()
get the concrete factory class for the AppUser used by this application
|
java.lang.String |
getName()
Get the Name for the current user.
|
<T extends DataObject> |
getPersonInRelationshipRoleFilter(DataObjectFactory<T> fac,
java.lang.String role,
T target)
get a
BaseFilter representing the set of AppUser s that are in a particular
relationship-role with a target object. |
BaseFilter<A> |
getPersonInRoleFilter(java.lang.String... role_list)
Get a filter for
AppUser s that can be in any of the specified global roles. |
<T extends DataObject> |
getRelationshipRoleFilter(DataObjectFactory<T> fac,
java.lang.String role)
get a
BaseFilter representing the set of target objects that the current user has
a particular relationship-role with. |
<T extends DataObject> |
getRelationshipRoleFilter(DataObjectFactory<T> fac,
java.lang.String role,
BaseFilter<T> fallback)
get a
BaseFilter representing the set of target objects that the current user has
a particular relationship-role with. |
java.util.Set<java.lang.String> |
getStandardRoles()
Get the set of standard roles.
|
<T extends DataObject> |
getTargetInRelationshipRoleFilter(DataObjectFactory<T> fac,
java.lang.String role,
A person)
get a
BaseFilter representing the set of targets that a specified AppUser is in a particular
relationship-role with. |
java.util.TimeZone |
getTimeZone() |
java.lang.Boolean |
getToggle(java.lang.String role)
get the current State of a role toggle or null if not a toggle role
|
java.util.Set<java.lang.String> |
getToggleRoles()
Get the set of toggle roles for the current user.
|
<T extends DataObject> |
hasRelationship(DataObjectFactory<T> fac,
T target,
java.lang.String role)
Method to check relationships on a specified target object.
|
default <T extends DataObject> |
hasRelationship(DataObjectFactory<T> fac,
T target,
java.lang.String role,
boolean fallback)
Method to check relationships on a specified target object.
|
<T extends DataObject> |
hasRelationship(DataObjectFactory<T> fac,
T target,
java.lang.String role,
java.util.function.Supplier<java.lang.Boolean> fallback)
Method to check relationships on a specified target object.
|
boolean |
hasRole(java.lang.String role)
Does the current user have the specified role.
|
default boolean |
hasRoleFromList(java.lang.String... roles)
check for membership of any of the roles in list
|
boolean |
haveCurrentUser()
Can we generate an AppUser for this session.
|
boolean |
isAuthenticated()
Tests if the session has already authenticated.
|
boolean |
isCurrentPerson(A person)
does the current session correspond to the person.
|
void |
logOut()
Clear current person and any saved state
|
java.lang.String |
mapRoleName(java.lang.String role)
Perform role-name mapping.
|
default <T extends DataObject> |
personHasRelationship(A person,
DataObjectFactory<T> fac,
T target,
java.lang.String role,
java.util.function.Supplier<java.lang.Boolean> fallback)
Convenience method to query the relationships of a specified person rather than
the current user
Note this will not consider global roles unless the person matches the current person
|
void |
removeAttribute(java.lang.String key)
remove object from session
|
void |
setApplyToggle(boolean value)
enable/disable the toggle checks for this session
|
void |
setAttribute(java.lang.String key,
java.lang.Object value)
Store an object in the session.
|
void |
setAuthenticationTime(java.util.Date d)
Set the authentication time
|
void |
setAuthenticationType(java.lang.String type)
Set the authenticaiton type used for the session.
|
void |
setCurrentPerson(A person)
Set the current person
|
void |
setCurrentPerson(int id)
Set the current person by id
|
void |
setCurrentRoleToggle(java.util.Map<java.lang.String,java.lang.Boolean> toggle_map)
Remember the current role_map belonging to the current user.
|
void |
setRole(A user,
java.lang.String role,
boolean value)
request a role change for a specified user.
|
void |
setTempRole(java.lang.String role)
Set a temporary (not stored to database) role.
|
void |
setToggle(java.lang.String name,
boolean value)
Set the toggle state of a role
|
java.lang.Boolean |
toggleRole(java.lang.String name)
Toggle the state of a role
return the new value of the toggle or null if its not a togglable role
|
getContext
getType
cleanup
static final java.lang.String ADMIN_ROLE
java.lang.String getName()
boolean haveCurrentUser()
boolean hasRole(java.lang.String role)
role
- java.util.Set<java.lang.String> getToggleRoles()
java.lang.Boolean getToggle(java.lang.String role)
role
- void setToggle(java.lang.String name, boolean value)
name
- String role to setvalue
- boolean value to setvoid setApplyToggle(boolean value)
value
- boolean getApplyToggle()
java.lang.Boolean toggleRole(java.lang.String name)
name
- String role to togglevoid setCurrentRoleToggle(java.util.Map<java.lang.String,java.lang.Boolean> toggle_map)
toggle_map
- A getCurrentPerson()
void setCurrentPerson(A person)
person
- boolean isCurrentPerson(A person)
person
- void setCurrentPerson(int id)
id
- void clearCurrentPerson()
java.util.Date getAuthenticationTime()
void setAuthenticationTime(java.util.Date d)
d
- java.lang.String getAuthenticationType()
void setAuthenticationType(java.lang.String type)
type
- void logOut()
AppUserFactory<A> getLoginFactory()
default boolean hasRoleFromList(java.lang.String... roles)
role_list
- void setRole(A user, java.lang.String role, boolean value) throws java.lang.UnsupportedOperationException
user
- role
- value
- java.lang.UnsupportedOperationException
void setTempRole(java.lang.String role)
role
- boolean canHaveRole(A user, java.lang.String role)
user
- role
- BaseFilter<A> getGlobalRoleFilter(java.lang.String role)
BaseFilter
for all AppUser
s who
have access to a global role.
This is the same selection as {@link #canHaveRole(AppUser, String)role
- default boolean canHaveRoleFromList(A user, java.lang.String... roles)
void setAttribute(java.lang.String key, java.lang.Object value)
AppContext
might have a shorter lifetime.
tkey
- value
- void removeAttribute(java.lang.String key)
key
- java.lang.Object getAttribute(java.lang.String key)
key
- java.util.Locale getLocale()
java.util.Set<java.lang.String> getStandardRoles()
java.util.TimeZone getTimeZone()
java.lang.String mapRoleName(java.lang.String role)
role
- specific role requests<T extends DataObject> BaseFilter<T> getRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role) throws UnknownRelationshipException
BaseFilter
representing the set of target objects that the current user has
a particular relationship-role with.fac
- DataObjectFactory
for target objectrole
- BaseFilter
UnknownRelationshipException
<T extends DataObject> BaseFilter<T> getRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, BaseFilter<T> fallback)
BaseFilter
representing the set of target objects that the current user has
a particular relationship-role with.
If the named relationship is defined it is used to narrow the selection of the fallback filter.
Otherwise just the fallback filter is returned.fac
- DataObjectFactory
for target objectrole
- fallback
- BaseFilter
to use by default.BaseFilter
<T extends DataObject> BaseFilter<A> getPersonInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, T target) throws UnknownRelationshipException
BaseFilter
representing the set of AppUser
s that are in a particular
relationship-role with a target object.
A null target selects all AppUser
s that have the specified role with any target matched by the
factories default DataObjectFactory.getDefaultRelationshipFilter()
.fac
- role
- target
- BaseFilter
UnknownRelationshipException
BaseFilter<A> getPersonInRoleFilter(java.lang.String... role_list)
AppUser
s that can be in any of the specified global roles.
as defined in canHaveRoleFromList(AppUser, String...)
role_list
- <T extends DataObject> BaseFilter<T> getTargetInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, A person) throws UnknownRelationshipException
BaseFilter
representing the set of targets that a specified AppUser
is in a particular
relationship-role with.fac
- role
- person
- BaseFilter
UnknownRelationshipException
<T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role) throws UnknownRelationshipException
getRelationshipRoleFilter(DataObjectFactory, String)
is sufficient for this
in combination with DataObjectFactory.matches(BaseFilter, DataObject)
but
adding a method to SessionService
reduces code duplication and adds to possibility of caching the results.fac
- DataObjectFactory
target
- DataObject
to test for relationshiprole
- String role to testUnknownRelationshipException
default <T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role, boolean fallback)
fac
- DataObjectFactory
target
- DataObject
to test for relationshiprole
- String role to testfallback
- boolean value to use if relationship undefined<T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role, java.util.function.Supplier<java.lang.Boolean> fallback)
fac
- DataObjectFactory
target
- DataObject
to test for relationshiprole
- String role to testfallback
- Supplier
value to use if relationship undefineddefault <T extends DataObject> boolean personHasRelationship(A person, DataObjectFactory<T> fac, T target, java.lang.String role, java.util.function.Supplier<java.lang.Boolean> fallback)
T
- person
- fac
- target
- role
- fallback
- boolean isAuthenticated()
haveCurrentUser()
could return true
provided it is called first.void flushRelationships()
void addSecurityContext(java.util.Map att)
att
-