A
- public abstract class AbstractSessionService<A extends AppUser> extends AbstractContexed implements SessionService<A>
SessionService
A config parameter of the form use_role.role-name defines a role-name mapping the value of the parameter is the actual role queried. A comma separated list of sufficient roles may also be specified.
A role of the form tag%rel[@name] is possessed by a user if that user has relationship (see below) rel against one of the records from factory constructed using tag. If the optional name-filter name is specified it must be one of the records that match that filter.
A role starting with @ denotes a named filter on the AppUser
that must match a
person for them to have the role.
The AppUserFactory
or its Composite
s can provide roles by implementing
StateRoleProvider
.
Relationships are configured via the ConfigService
by setting:
use_relationship.factory-tag.relationship
If this is a comma separated list it implies an OR of the component parts.
within this AND combinations can be specified as + separated terms. If both OR and AND combinations exist
the AND operator binds more tightly.
The factory (or its Composite
s) can implement AccessRoleProvider
to provide relationships.
Roles of the form field->remote_relationship denotes a remote filter joined via the reference field field A person has these relationships with the target object if they have the remote_relationship on the object the target references. The remote relationship must be unqualified.
Relationship names containing a period are qualified names the qualifier can be:
NamedFilterWrapper
wrapping the factory. Named filters resolve true/false depending
on whether any targets exist that match the filter.
RelationshipProvider
for the target.AccessRoleProvider
NamedFilterWrapper
,
RemoteAccessRoleProvider
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Modifier and Type | Field and Description |
---|---|
static Feature |
ALLOW_UNKNOWN_RELATIONSHIP_IN_OR_FEATURE |
static Feature |
APPLY_DEFAULT_PERSON_RELATIONSHIP_FILTER |
static Feature |
APPLY_DEFAULT_TARGET_RELATIONSHIP_FILTER |
static java.lang.String |
auth_time_tag |
static java.lang.String |
auth_type_tag |
static Feature |
CACHE_RELATIONSHIP_FEATURE |
static java.lang.String |
person_tag |
static java.lang.String |
ROLE_FIELD |
static java.lang.String |
ROLE_LIST_CONFIG |
static java.lang.String |
ROLE_PERSON_ID |
static java.lang.String |
ROLE_TABLE |
static Feature |
TOGGLE_ROLES_FEATURE |
static java.lang.String |
USE_ROLE_PREFIX
Property prefix to allow role name aliasing.
|
conn
ADMIN_ROLE
Constructor and Description |
---|
AbstractSessionService(AppContext c) |
Modifier and Type | Method and Description |
---|---|
static void |
addRoleByID(AppContext c,
int id,
java.lang.String role) |
void |
addSecurityContext(java.util.Map att)
Add context parameters for security logging.
|
protected void |
cacheRole(java.lang.String role)
like
setTempRole(String) but does not call flushRelationships()
internal use only |
boolean |
canHaveRole(A user,
java.lang.String role)
query the default role set for the specified user.
|
boolean |
canHaveRole(java.lang.String role)
Checks if this session can have the role (ignoring toggle values).
|
protected boolean |
canLogin(A person)
extension point for canLogin check.
|
void |
cleanup()
AppContext is being closed. |
void |
clearCurrentPerson()
clears all record of the current person.
|
void |
flushRelationships()
clear all cached relationships
|
boolean |
getApplyToggle()
are toggle roles currently enabled
|
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
|
protected java.lang.Class<? extends AppUserFactory> |
getDefaultFactoryClass() |
static java.util.Set<java.lang.String> |
getExplicitRoles(AppContext conn,
int id) |
BaseFilter<A> |
getGlobalRoleFilter(java.util.Set<java.lang.String> skip,
java.lang.String role) |
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
|
protected java.lang.String |
getLoginTable() |
java.lang.String |
getName()
Get the Name for the current user.
|
protected java.lang.Integer |
getPersonID()
Get the ID of the ccurrent person.
|
<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.Map<java.lang.String,java.lang.Boolean> |
getToggleMap() |
java.util.Set<java.lang.String> |
getToggleRoles()
Get the set of toggle roles this user is capable of assuming
|
java.lang.Class<SessionService> |
getType()
Returns the type of service the class should be registered under.
|
<T extends DataObject> |
hasRelationship(DataObjectFactory<T> fac,
T target,
java.lang.String role)
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 name)
Has this person a particular SAF role this is used for adding special
permissions to SAF users
|
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
|
protected A |
lookupPerson()
extracted method to look up person from the cached id.
|
protected <T extends DataObject> |
makeDirectPersonInRelationshipRoleFilter(DataObjectFactory<T> fac2,
java.lang.String role,
T target) |
protected <T extends DataObject> |
makeDirectRelationshipRoleFilter(DataObjectFactory<T> fac2,
java.lang.String role,
A person,
BaseFilter<T> def)
Make filter for objects in relation to a person for directly implemented roles
|
protected <T extends DataObject> |
makeNamedFilter(DataObjectFactory<T> fac2,
java.lang.String name)
look for a named filter from the factory or composites.
|
protected <T extends DataObject> |
makePersonInRelationshipRoleFilter(DataObjectFactory<T> fac2,
java.lang.String role,
T target) |
protected <T extends DataObject> |
makeRelationshipRoleFilter(DataObjectFactory<T> fac2,
java.lang.String role,
A person,
BaseFilter<T> def)
actually construct the filter.
|
java.util.Map<java.lang.String,java.lang.Boolean> |
makeToggleMap()
Create the initial map of toggle role statuses.
|
java.lang.String |
mapRoleName(java.lang.String name)
map role name to a comma separated list of alternative roles to check.
|
static boolean |
rawRoleQuery(AppContext conn,
int id,
java.lang.String role)
Perform a raw query of a users roles from the database
|
static void |
removeRoleByID(AppContext context,
int id,
java.lang.String role) |
void |
setApplyToggle(boolean value)
enable/disable the toggle checks for this 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 new_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> toggleMap)
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
|
static void |
setupRoleTable(AppContext ctx) |
protected boolean |
shortcutTestRole(java.lang.String role)
perform a non-cached role-check.
|
protected java.lang.Boolean |
testRole(java.lang.String role)
underlying check for role membership.
|
java.lang.Boolean |
toggleRole(java.lang.String name)
Toggle the sate of a role
return the new value of the toggle or null if its not a togglable role
|
java.lang.String |
toString() |
getContext, getLogger, resetLogger
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
canHaveRoleFromList, getAttribute, hasRelationship, hasRoleFromList, personHasRelationship, removeAttribute, setAttribute
getContext
public static final java.lang.String USE_ROLE_PREFIX
public static final Feature TOGGLE_ROLES_FEATURE
public static final Feature CACHE_RELATIONSHIP_FEATURE
public static final Feature APPLY_DEFAULT_PERSON_RELATIONSHIP_FILTER
public static final Feature APPLY_DEFAULT_TARGET_RELATIONSHIP_FILTER
public static final Feature ALLOW_UNKNOWN_RELATIONSHIP_IN_OR_FEATURE
public static final java.lang.String ROLE_LIST_CONFIG
public static final java.lang.String ROLE_PERSON_ID
public static final java.lang.String ROLE_FIELD
public static final java.lang.String ROLE_TABLE
public static final java.lang.String person_tag
public static final java.lang.String auth_time_tag
public static final java.lang.String auth_type_tag
public AbstractSessionService(AppContext c)
public void flushRelationships()
flushRelationships
in interface SessionService<A extends AppUser>
public static void setupRoleTable(AppContext ctx)
public AppUserFactory<A> getLoginFactory()
SessionService
getLoginFactory
in interface SessionService<A extends AppUser>
protected java.lang.String getLoginTable()
protected java.lang.Class<? extends AppUserFactory> getDefaultFactoryClass()
public final java.lang.Boolean getToggle(java.lang.String role)
getToggle
in interface SessionService<A extends AppUser>
role
- public void setToggle(java.lang.String name, boolean value)
setToggle
in interface SessionService<A extends AppUser>
name
- String role to setvalue
- boolean value to setpublic java.lang.Boolean toggleRole(java.lang.String name)
toggleRole
in interface SessionService<A extends AppUser>
name
- String role to togglepublic java.util.Map<java.lang.String,java.lang.Boolean> makeToggleMap()
public java.util.Map<java.lang.String,java.lang.Boolean> getToggleMap()
public final boolean hasRole(java.lang.String name)
hasRole
in interface SessionService<A extends AppUser>
name
- of role to be testedpublic java.lang.String mapRoleName(java.lang.String name)
mapRoleName
in interface SessionService<A extends AppUser>
name
- public java.util.Set<java.lang.String> getToggleRoles()
getToggleRoles
in interface SessionService<A extends AppUser>
public final boolean canHaveRole(java.lang.String role)
role
- protected boolean shortcutTestRole(java.lang.String role)
role
- protected java.lang.Boolean testRole(java.lang.String role)
role
- public void clearCurrentPerson()
clearCurrentPerson
in interface SessionService<A extends AppUser>
public void logOut()
SessionService
logOut
in interface SessionService<A extends AppUser>
public final A getCurrentPerson()
SessionService
getCurrentPerson
in interface SessionService<A extends AppUser>
public java.util.Set<java.lang.String> getStandardRoles()
SessionService
getStandardRoles
in interface SessionService<A extends AppUser>
protected boolean canLogin(A person)
person
- protected A lookupPerson()
public final boolean isAuthenticated()
SessionService
SessionService.haveCurrentUser()
could return true
provided it is called first.isAuthenticated
in interface SessionService<A extends AppUser>
public final boolean haveCurrentUser()
SessionService
haveCurrentUser
in interface SessionService<A extends AppUser>
protected java.lang.Integer getPersonID()
haveCurrentUser()
and getCurrentPerson()
public void setCurrentPerson(A new_person)
SessionService
setCurrentPerson
in interface SessionService<A extends AppUser>
public boolean isCurrentPerson(A person)
SessionService
isCurrentPerson
in interface SessionService<A extends AppUser>
public void setCurrentPerson(int id)
SessionService
setCurrentPerson
in interface SessionService<A extends AppUser>
public java.util.Date getAuthenticationTime()
SessionService
getAuthenticationTime
in interface SessionService<A extends AppUser>
public void setAuthenticationTime(java.util.Date d)
SessionService
setAuthenticationTime
in interface SessionService<A extends AppUser>
public java.lang.String getAuthenticationType()
SessionService
getAuthenticationType
in interface SessionService<A extends AppUser>
public void setAuthenticationType(java.lang.String type)
SessionService
setAuthenticationType
in interface SessionService<A extends AppUser>
public void setCurrentRoleToggle(java.util.Map<java.lang.String,java.lang.Boolean> toggleMap)
SessionService
setCurrentRoleToggle
in interface SessionService<A extends AppUser>
public void setTempRole(java.lang.String role)
setTempRole
in interface SessionService<A extends AppUser>
role
- protected void cacheRole(java.lang.String role)
setTempRole(String)
but does not call flushRelationships()
internal use onlyrole
- public java.lang.String getName()
SessionService
getName
in interface SessionService<A extends AppUser>
public void cleanup()
AppContextCleanup
AppContext
is being closed.
Only use this for cleanup that can't be handled by
normal garbage collection or for state which is never returned by reference.cleanup
in interface AppContextCleanup
public static boolean rawRoleQuery(AppContext conn, int id, java.lang.String role)
conn
- id
- role
- public static java.util.Set<java.lang.String> getExplicitRoles(AppContext conn, int id)
public static void removeRoleByID(AppContext context, int id, java.lang.String role) throws DataFault
DataFault
public static void addRoleByID(AppContext c, int id, java.lang.String role) throws DataFault
DataFault
public void setRole(A user, java.lang.String role, boolean value) throws java.lang.UnsupportedOperationException
SessionService
setRole
in interface SessionService<A extends AppUser>
java.lang.UnsupportedOperationException
public 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)getGlobalRoleFilter
in interface SessionService<A extends AppUser>
role
- public BaseFilter<A> getGlobalRoleFilter(java.util.Set<java.lang.String> skip, java.lang.String role)
public boolean canHaveRole(A user, java.lang.String role)
SessionService
canHaveRole
in interface SessionService<A extends AppUser>
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Class<SessionService> getType()
AppContextService
getType
in interface AppContextService<SessionService<A extends AppUser>>
public java.util.Locale getLocale()
getLocale
in interface SessionService<A extends AppUser>
public java.util.TimeZone getTimeZone()
getTimeZone
in interface SessionService<A extends AppUser>
public final <T extends DataObject> BaseFilter<T> getRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role) throws UnknownRelationshipException
SessionService
BaseFilter
representing the set of target objects that the current user has
a particular relationship-role with.getRelationshipRoleFilter
in interface SessionService<A extends AppUser>
fac
- DataObjectFactory
for target objectBaseFilter
UnknownRelationshipException
public final <T extends DataObject> BaseFilter<T> getRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, BaseFilter<T> fallback)
SessionService
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.getRelationshipRoleFilter
in interface SessionService<A extends AppUser>
fac
- DataObjectFactory
for target objectfallback
- BaseFilter
to use by default.BaseFilter
public final <T extends DataObject> BaseFilter<A> getPersonInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, T target) throws UnknownRelationshipException
SessionService
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()
.getPersonInRelationshipRoleFilter
in interface SessionService<A extends AppUser>
BaseFilter
UnknownRelationshipException
public <T extends DataObject> BaseFilter<T> getTargetInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, A person) throws UnknownRelationshipException
SessionService
BaseFilter
representing the set of targets that a specified AppUser
is in a particular
relationship-role with.getTargetInRelationshipRoleFilter
in interface SessionService<A extends AppUser>
BaseFilter
UnknownRelationshipException
protected <T extends DataObject> BaseFilter<T> makeRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, A person, BaseFilter<T> def) throws UnknownRelationshipException
Composite
s) can implement AccessRoleProvider
to provide roles.
Roles of the form field->remote_role denotes a remote filter
joined via the reference field field A person has these roles with the targer object
if they have the remote_role on the object the target references. The remote role must be unqualified.
Role names containing a period are qualified names the qualifier can be:
Composite
.RelationshipProvider
for the target.AccessRoleProvider
NamedFilterProvider
for the target.fac2
- target factoryrole
- relationship stringperson
- person to query (null for current person)def
- default query to use if no definition (pass null to throw exception)UnknownRelationshipException
protected <T extends DataObject> BaseFilter<A> makePersonInRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, T target) throws UnknownRelationshipException
UnknownRelationshipException
protected <T extends DataObject> BaseFilter<T> makeDirectRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, A person, BaseFilter<T> def) throws UnknownRelationshipException
fac2
- role
- UnknownRelationshipException
protected <T extends DataObject> BaseFilter<T> makeNamedFilter(DataObjectFactory<T> fac2, java.lang.String name)
protected <T extends DataObject> BaseFilter<A> makeDirectPersonInRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, T target) throws UnknownRelationshipException
UnknownRelationshipException
public <T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role) throws UnknownRelationshipException
SessionService
SessionService.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.hasRelationship
in interface SessionService<A extends AppUser>
fac
- DataObjectFactory
target
- DataObject
to test for relationshiprole
- String role to testUnknownRelationshipException
public <T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role, java.util.function.Supplier<java.lang.Boolean> fallback)
SessionService
hasRelationship
in interface SessionService<A extends AppUser>
fac
- DataObjectFactory
target
- DataObject
to test for relationshiprole
- String role to testfallback
- Supplier
value to use if relationship undefinedpublic void setApplyToggle(boolean value)
SessionService
setApplyToggle
in interface SessionService<A extends AppUser>
public boolean getApplyToggle()
SessionService
getApplyToggle
in interface SessionService<A extends AppUser>
public BaseFilter<A> getPersonInRoleFilter(java.lang.String... role_list)
SessionService
AppUser
s that can be in any of the specified global roles.
as defined in SessionService.canHaveRoleFromList(AppUser, String...)
getPersonInRoleFilter
in interface SessionService<A extends AppUser>
public void addSecurityContext(java.util.Map att)
SessionService
addSecurityContext
in interface SessionService<A extends AppUser>