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 Composites 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 Composites) 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.AccessRoleProviderNamedFilterWrapper,
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.
|
connADMIN_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 AppUsers 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 AppUsers that are in a particular
relationship-role with a target object. |
BaseFilter<A> |
getPersonInRoleFilter(java.lang.String... role_list)
Get a filter for
AppUsers 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, resetLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcanHaveRoleFromList, getAttribute, hasRelationship, hasRoleFromList, personHasRelationship, removeAttribute, setAttributegetContextpublic 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()
SessionServicegetLoginFactory 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()
SessionServicelogOut in interface SessionService<A extends AppUser>public final A getCurrentPerson()
SessionServicegetCurrentPerson in interface SessionService<A extends AppUser>public java.util.Set<java.lang.String> getStandardRoles()
SessionServicegetStandardRoles in interface SessionService<A extends AppUser>protected boolean canLogin(A person)
person - protected A lookupPerson()
public final boolean isAuthenticated()
SessionServiceSessionService.haveCurrentUser() could return true
provided it is called first.isAuthenticated in interface SessionService<A extends AppUser>public final boolean haveCurrentUser()
SessionServicehaveCurrentUser in interface SessionService<A extends AppUser>protected java.lang.Integer getPersonID()
haveCurrentUser() and getCurrentPerson()public void setCurrentPerson(A new_person)
SessionServicesetCurrentPerson in interface SessionService<A extends AppUser>public boolean isCurrentPerson(A person)
SessionServiceisCurrentPerson in interface SessionService<A extends AppUser>public void setCurrentPerson(int id)
SessionServicesetCurrentPerson in interface SessionService<A extends AppUser>public java.util.Date getAuthenticationTime()
SessionServicegetAuthenticationTime in interface SessionService<A extends AppUser>public void setAuthenticationTime(java.util.Date d)
SessionServicesetAuthenticationTime in interface SessionService<A extends AppUser>public java.lang.String getAuthenticationType()
SessionServicegetAuthenticationType in interface SessionService<A extends AppUser>public void setAuthenticationType(java.lang.String type)
SessionServicesetAuthenticationType in interface SessionService<A extends AppUser>public void setCurrentRoleToggle(java.util.Map<java.lang.String,java.lang.Boolean> toggleMap)
SessionServicesetCurrentRoleToggle 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()
SessionServicegetName in interface SessionService<A extends AppUser>public void cleanup()
AppContextCleanupAppContext 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 AppContextCleanuppublic 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
DataFaultpublic static void addRoleByID(AppContext c, int id, java.lang.String role) throws DataFault
DataFaultpublic void setRole(A user, java.lang.String role, boolean value) throws java.lang.UnsupportedOperationException
SessionServicesetRole in interface SessionService<A extends AppUser>java.lang.UnsupportedOperationExceptionpublic BaseFilter<A> getGlobalRoleFilter(java.lang.String role)
BaseFilter for all AppUsers 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)
SessionServicecanHaveRole in interface SessionService<A extends AppUser>public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Class<SessionService> getType()
AppContextServicegetType 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
SessionServiceBaseFilter 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 objectBaseFilterUnknownRelationshipExceptionpublic final <T extends DataObject> BaseFilter<T> getRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, BaseFilter<T> fallback)
SessionServiceBaseFilter 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.BaseFilterpublic final <T extends DataObject> BaseFilter<A> getPersonInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, T target) throws UnknownRelationshipException
SessionServiceBaseFilter representing the set of AppUsers that are in a particular
relationship-role with a target object.
A null target selects all AppUsers that have the specified role with any target matched by the
factories default DataObjectFactory.getDefaultRelationshipFilter().getPersonInRelationshipRoleFilter in interface SessionService<A extends AppUser>BaseFilterUnknownRelationshipExceptionpublic <T extends DataObject> BaseFilter<T> getTargetInRelationshipRoleFilter(DataObjectFactory<T> fac, java.lang.String role, A person) throws UnknownRelationshipException
SessionServiceBaseFilter representing the set of targets that a specified AppUser is in a particular
relationship-role with.getTargetInRelationshipRoleFilter in interface SessionService<A extends AppUser>BaseFilterUnknownRelationshipExceptionprotected <T extends DataObject> BaseFilter<T> makeRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, A person, BaseFilter<T> def) throws UnknownRelationshipException
Composites) 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.AccessRoleProviderNamedFilterProvider 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)UnknownRelationshipExceptionprotected <T extends DataObject> BaseFilter<A> makePersonInRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, T target) throws UnknownRelationshipException
UnknownRelationshipExceptionprotected <T extends DataObject> BaseFilter<T> makeDirectRelationshipRoleFilter(DataObjectFactory<T> fac2, java.lang.String role, A person, BaseFilter<T> def) throws UnknownRelationshipException
fac2 - role - UnknownRelationshipExceptionprotected <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
UnknownRelationshipExceptionpublic <T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role) throws UnknownRelationshipException
SessionServiceSessionService.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 - DataObjectFactorytarget - DataObject to test for relationshiprole - String role to testUnknownRelationshipExceptionpublic <T extends DataObject> boolean hasRelationship(DataObjectFactory<T> fac, T target, java.lang.String role, java.util.function.Supplier<java.lang.Boolean> fallback)
SessionServicehasRelationship in interface SessionService<A extends AppUser>fac - DataObjectFactorytarget - DataObject to test for relationshiprole - String role to testfallback - Supplier value to use if relationship undefinedpublic void setApplyToggle(boolean value)
SessionServicesetApplyToggle in interface SessionService<A extends AppUser>public boolean getApplyToggle()
SessionServicegetApplyToggle in interface SessionService<A extends AppUser>public BaseFilter<A> getPersonInRoleFilter(java.lang.String... role_list)
SessionServiceAppUsers 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)
SessionServiceaddSecurityContext in interface SessionService<A extends AppUser>