Class AclQueryUtils
Query
.
To build a query, sequentially proceed as follows:
- form your select clause and your jointures
- concatenate
formAclRestrictionClause(String)
orformNativeAclJoinClause(String)
in the jointure section - form where clause and add your constraints
- concatenate
formNativeAclRestrictionClause(SessionFactoryImplementor)
in the clause section (only for native queries) - bind all your parameters
- bind ACL-specific parameters with
addAclParameters(Query, Class)
to the query object
- Author:
- poirigui
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Alias used byformAclRestrictionClause(String, int)
andformNativeAclJoinClause(String)
for the object identityAclObjectIdentity
and the owner identityAclSid
.static final String
Alias used byformAclRestrictionClause(String, int)
andformNativeAclJoinClause(String)
for the object identityAclObjectIdentity
and the owner identityAclSid
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAclParameters
(Query query, Class<? extends Securable> aoiType) BindQuery
parameters to a join clause generated withformAclRestrictionClause(String)
and add ACL restriction parameters defined informAclRestrictionClause(String)
.static String
formAclRestrictionClause
(String aoiIdColumn) Create a HQL restriction clause with theBasePermission.READ
permission.static String
formAclRestrictionClause
(String aoiIdColumn, int mask) Create an HQL join clause forAclObjectIdentity
,AclGrantedAuthoritySid
and a restriction clause to limit the result only to objects the current user can access.static String
formNativeAclJoinClause
(String aoiIdColumn) Native SQL flavour of the ACL jointure.static String
formNativeAclRestrictionClause
(SessionFactoryImplementor sessionFactoryImplementor) Native flavour of the ACL restriction clause with aBasePermission.READ
permission.static String
formNativeAclRestrictionClause
(SessionFactoryImplementor sessionFactoryImplementor, int mask) Native flavour of the ACL restriction clause.
-
Field Details
-
AOI_ALIAS
Alias used byformAclRestrictionClause(String, int)
andformNativeAclJoinClause(String)
for the object identityAclObjectIdentity
and the owner identityAclSid
.- See Also:
-
SID_ALIAS
Alias used byformAclRestrictionClause(String, int)
andformNativeAclJoinClause(String)
for the object identityAclObjectIdentity
and the owner identityAclSid
.- See Also:
-
-
Constructor Details
-
AclQueryUtils
public AclQueryUtils()
-
-
Method Details
-
formAclRestrictionClause
Create a HQL restriction clause with theBasePermission.READ
permission.- See Also:
-
formAclRestrictionClause
Create an HQL join clause forAclObjectIdentity
,AclGrantedAuthoritySid
and a restriction clause to limit the result only to objects the current user can access.Ensure that you use
addAclParameters(Query, Class)
afterward to bind the query parameters.Important note: when using this, ensure that you have a
group by
clause in your query, otherwise entities with multiple ACL entries will be duplicated in the results.FIXME: this ACL jointure is really annoying because it is one-to-many, maybe handling everything in a sub-query would be preferable?
- Parameters:
aoiIdColumn
- column name to match against the ACL object identity, the object class is passed viaaddAclParameters(Query, Class)
afterwardmask
- a mask with requested permissions- Returns:
- clause to add to the query after any jointure
-
formNativeAclJoinClause
Native SQL flavour of the ACL jointure.Note: unlike the HQL version, this query uses
on
to restrict the jointure, so you can define thewhere
clause yourself.Important note: when using this, ensure that you have a
group by
clause in your query, otherwise entities with multiple ACL entries will be duplicated in the results.- Parameters:
aoiIdColumn
- column name to match against the ACL object identity, the object class is passed viaaddAclParameters(Query, Class)
afterward- See Also:
-
formNativeAclRestrictionClause
public static String formNativeAclRestrictionClause(SessionFactoryImplementor sessionFactoryImplementor) Native flavour of the ACL restriction clause with aBasePermission.READ
permission.- See Also:
-
formNativeAclRestrictionClause
public static String formNativeAclRestrictionClause(SessionFactoryImplementor sessionFactoryImplementor, int mask) Native flavour of the ACL restriction clause.- Parameters:
sessionFactoryImplementor
- a session factory implementor that will be used to adjust the SQL generated based on the dialectmask
- a mask with requested permissions- See Also:
-
addAclParameters
public static void addAclParameters(Query query, Class<? extends Securable> aoiType) throws QueryParameterException BindQuery
parameters to a join clause generated withformAclRestrictionClause(String)
and add ACL restriction parameters defined informAclRestrictionClause(String)
.This method also work for native queries formed with
formNativeAclJoinClause(String)
andformNativeAclRestrictionClause(SessionFactoryImplementor)
.- Parameters:
query
- aQuery
object that contains the join and restriction clausesaoiType
- the AOI type to be bound in the query- Throws:
QueryParameterException
- if any defined parameters are missing, which is typically due to a missing priorformAclRestrictionClause(String)
.
-