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 StringAlias used byformAclRestrictionClause(String, int)andformNativeAclJoinClause(String)for the object identityAclObjectIdentityand the owner identityAclSid.static final StringAlias used byformAclRestrictionClause(String, int)andformNativeAclJoinClause(String)for the object identityAclObjectIdentityand the owner identityAclSid. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAclParameters(Query query, Class<? extends Securable> aoiType) BindQueryparameters to a join clause generated withformAclRestrictionClause(String)and add ACL restriction parameters defined informAclRestrictionClause(String).static StringformAclRestrictionClause(String aoiIdColumn) Create an HQL restriction clause with theBasePermission.READpermission.static StringformAclRestrictionClause(String aoiIdColumn, int mask) Create an HQL join clause forAclObjectIdentity,AclGrantedAuthoritySidand a restriction clause to limit the result only to objects the current user can access.static StringformNativeAclJoinClause(String aoiIdColumn) Native SQL flavour of the ACL jointure.static StringformNativeAclRestrictionClause(SessionFactoryImplementor sessionFactoryImplementor) Native flavour of the ACL restriction clause with aBasePermission.READpermission.static StringformNativeAclRestrictionClause(SessionFactoryImplementor sessionFactoryImplementor, int mask) Native flavour of the ACL restriction clause.static booleanIndicate if the ACL query requires acount(distinct ...)clause.static booleanIndicate if the ACL query requires agroup byclause.
-
Field Details
-
AOI_ALIAS
Alias used byformAclRestrictionClause(String, int)andformNativeAclJoinClause(String)for the object identityAclObjectIdentityand the owner identityAclSid.- See Also:
-
SID_ALIAS
Alias used byformAclRestrictionClause(String, int)andformNativeAclJoinClause(String)for the object identityAclObjectIdentityand the owner identityAclSid.- See Also:
-
-
Constructor Details
-
AclQueryUtils
public AclQueryUtils()
-
-
Method Details
-
requiresCountDistinct
public static boolean requiresCountDistinct()Indicate if the ACL query requires acount(distinct ...)clause.FIXME: remove the need for a distinct altogether by using a sub-query to apply ACLs (see #784)
-
requiresGroupBy
public static boolean requiresGroupBy()Indicate if the ACL query requires agroup byclause.FIXME: remove the need for a count distinct altogether by using a sub-query to apply ACLs (see #784)
-
formAclRestrictionClause
Create an HQL restriction clause with theBasePermission.READpermission.- See Also:
-
formAclRestrictionClause
Create an HQL join clause forAclObjectIdentity,AclGrantedAuthoritySidand 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 byclause in your query, otherwise entities with multiple ACL entries will be duplicated in the results. You can userequiresGroupBy()to tell if agroup byclause is required andrequiresCountDistinct()when counting 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
onto restrict the jointure, so you can define thewhereclause yourself.Important note: when using this, ensure that you have a
group byclause 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.READpermission.- 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 BindQueryparameters 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- aQueryobject 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).
-