1
1
/*
2
- * Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2
+ * Copyright 2004, 2005, 2006, 2017 Acegi Technology Pty Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
30
30
31
31
import javax .sql .DataSource ;
32
32
33
+ import org .springframework .core .convert .ConversionException ;
34
+ import org .springframework .core .convert .ConversionService ;
35
+ import org .springframework .core .convert .support .DefaultConversionService ;
33
36
import org .springframework .jdbc .core .JdbcTemplate ;
34
37
import org .springframework .jdbc .core .PreparedStatementSetter ;
35
38
import org .springframework .jdbc .core .ResultSetExtractor ;
78
81
*/
79
82
public class BasicLookupStrategy implements LookupStrategy {
80
83
81
- public final static String DEFAULT_SELECT_CLAUSE = "select acl_object_identity.object_id_identity, "
84
+ private final static String DEFAULT_SELECT_CLAUSE_COLUMNS = "select acl_object_identity.object_id_identity, "
82
85
+ "acl_entry.ace_order, "
83
86
+ "acl_object_identity.id as acl_id, "
84
87
+ "acl_object_identity.parent_object, "
@@ -92,13 +95,19 @@ public class BasicLookupStrategy implements LookupStrategy {
92
95
+ "acl_sid.sid as ace_sid, "
93
96
+ "acli_sid.principal as acl_principal, "
94
97
+ "acli_sid.sid as acl_sid, "
95
- + "acl_class.class "
96
- + "from acl_object_identity "
98
+ + "acl_class.class " ;
99
+ private final static String DEFAULT_SELECT_CLAUSE_ACL_CLASS_ID_TYPE_COLUMN = ", acl_class.class_id_type " ;
100
+ private final static String DEFAULT_SELECT_CLAUSE_FROM = "from acl_object_identity "
97
101
+ "left join acl_sid acli_sid on acli_sid.id = acl_object_identity.owner_sid "
98
102
+ "left join acl_class on acl_class.id = acl_object_identity.object_id_class "
99
103
+ "left join acl_entry on acl_object_identity.id = acl_entry.acl_object_identity "
100
104
+ "left join acl_sid on acl_entry.sid = acl_sid.id " + "where ( " ;
101
105
106
+ public final static String DEFAULT_SELECT_CLAUSE = DEFAULT_SELECT_CLAUSE_COLUMNS + DEFAULT_SELECT_CLAUSE_FROM ;
107
+
108
+ public final static String DEFAULT_ACL_CLASS_ID_SELECT_CLAUSE = DEFAULT_SELECT_CLAUSE_COLUMNS +
109
+ DEFAULT_SELECT_CLAUSE_ACL_CLASS_ID_TYPE_COLUMN + DEFAULT_SELECT_CLAUSE_FROM ;
110
+
102
111
private final static String DEFAULT_LOOKUP_KEYS_WHERE_CLAUSE = "(acl_object_identity.id = ?)" ;
103
112
104
113
private final static String DEFAULT_LOOKUP_IDENTITIES_WHERE_CLAUSE = "(acl_object_identity.object_id_identity = ? and acl_class.class = ?)" ;
@@ -126,6 +135,8 @@ public class BasicLookupStrategy implements LookupStrategy {
126
135
private String lookupObjectIdentitiesWhereClause = DEFAULT_LOOKUP_IDENTITIES_WHERE_CLAUSE ;
127
136
private String orderByClause = DEFAULT_ORDER_BY_CLAUSE ;
128
137
138
+ private AclClassIdUtils aclClassIdUtils ;
139
+
129
140
// ~ Constructors
130
141
// ===================================================================================================
131
142
@@ -161,9 +172,9 @@ public BasicLookupStrategy(DataSource dataSource, AclCache aclCache,
161
172
this .aclCache = aclCache ;
162
173
this .aclAuthorizationStrategy = aclAuthorizationStrategy ;
163
174
this .grantingStrategy = grantingStrategy ;
175
+ this .aclClassIdUtils = new AclClassIdUtils ();
164
176
fieldAces .setAccessible (true );
165
177
fieldAcl .setAccessible (true );
166
-
167
178
}
168
179
169
180
// ~ Methods
@@ -383,10 +394,9 @@ public void setValues(PreparedStatement ps) throws SQLException {
383
394
// No need to check for nulls, as guaranteed non-null by
384
395
// ObjectIdentity.getIdentifier() interface contract
385
396
String identifier = oid .getIdentifier ().toString ();
386
- long id = (Long .valueOf (identifier )).longValue ();
387
397
388
398
// Inject values
389
- ps .setLong ((2 * i ) + 1 , id );
399
+ ps .setString ((2 * i ) + 1 , identifier );
390
400
ps .setString ((2 * i ) + 2 , type );
391
401
i ++;
392
402
}
@@ -537,6 +547,18 @@ public final void setOrderByClause(String orderByClause) {
537
547
this .orderByClause = orderByClause ;
538
548
}
539
549
550
+ public final void setAclClassIdSupported (boolean aclClassIdSupported ) {
551
+ if (aclClassIdSupported ) {
552
+ Assert .isTrue (this .selectClause .equals (DEFAULT_SELECT_CLAUSE ), "Cannot set aclClassIdSupported and override the select clause; "
553
+ + "just override the select clause" );
554
+ this .selectClause = DEFAULT_ACL_CLASS_ID_SELECT_CLAUSE ;
555
+ }
556
+ }
557
+
558
+ public final void setAclClassIdUtils (AclClassIdUtils aclClassIdUtils ) {
559
+ this .aclClassIdUtils = aclClassIdUtils ;
560
+ }
561
+
540
562
// ~ Inner Classes
541
563
// ==================================================================================================
542
564
@@ -602,6 +624,7 @@ public Set<Long> extractData(ResultSet rs) throws SQLException {
602
624
* @param rs the ResultSet focused on a current row
603
625
*
604
626
* @throws SQLException if something goes wrong converting values
627
+ * @throws ConversionException if can't convert to the desired Java type
605
628
*/
606
629
private void convertCurrentResultIntoObject (Map <Serializable , Acl > acls ,
607
630
ResultSet rs ) throws SQLException {
@@ -612,9 +635,12 @@ private void convertCurrentResultIntoObject(Map<Serializable, Acl> acls,
612
635
613
636
if (acl == null ) {
614
637
// Make an AclImpl and pop it into the Map
638
+
639
+ // If the Java type is a String, check to see if we can convert it to the target id type, e.g. UUID.
640
+ Serializable identifier = (Serializable ) rs .getObject ("object_id_identity" );
641
+ identifier = aclClassIdUtils .identifierFrom (identifier , rs );
615
642
ObjectIdentity objectIdentity = new ObjectIdentityImpl (
616
- rs .getString ("class" ), Long .valueOf (rs
617
- .getLong ("object_id_identity" )));
643
+ rs .getString ("class" ), identifier );
618
644
619
645
Acl parentAcl = null ;
620
646
long parentAclId = rs .getLong ("parent_object" );
0 commit comments