Add authorizer support to JNI wrapper1.
FossilOrigin-Name: 773f9873865b5277a6a682c4695f216bfe1ec05ed5e5a2a70aaa451934ba2dc0
This commit is contained in:
parent
9a26589940
commit
88c90a793e
@ -20,7 +20,8 @@ import org.sqlite.jni.annotation.*;
|
||||
public interface AuthorizerCallback extends CallbackProxy {
|
||||
/**
|
||||
Must function as described for the C-level
|
||||
sqlite3_set_authorizer() callback.
|
||||
sqlite3_set_authorizer() callback. If it throws, the error is
|
||||
converted to a db-level error and the exception is suppressed.
|
||||
*/
|
||||
int call(int opId, @Nullable String s1, @Nullable String s2,
|
||||
@Nullable String s3, @Nullable String s4);
|
||||
|
@ -1358,6 +1358,9 @@ public class Tester1 implements Runnable {
|
||||
authRc.value = SQLITE_DENY;
|
||||
int rc = execSql(db, false, "UPDATE t SET a=2");
|
||||
affirm( SQLITE_AUTH==rc );
|
||||
sqlite3_set_authorizer(db, null);
|
||||
rc = execSql(db, false, "UPDATE t SET a=2");
|
||||
affirm( 0==rc );
|
||||
// TODO: expand these tests considerably
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
@ -29,6 +29,111 @@ import org.sqlite.jni.capi.OutputPointer;
|
||||
public final class Sqlite implements AutoCloseable {
|
||||
private sqlite3 db;
|
||||
|
||||
public static final int OK = CApi.SQLITE_OK;
|
||||
public static final int ERROR = CApi.SQLITE_ERROR;
|
||||
public static final int INTERNAL = CApi.SQLITE_INTERNAL;
|
||||
public static final int PERM = CApi.SQLITE_PERM;
|
||||
public static final int ABORT = CApi.SQLITE_ABORT;
|
||||
public static final int BUSY = CApi.SQLITE_BUSY;
|
||||
public static final int LOCKED = CApi.SQLITE_LOCKED;
|
||||
public static final int NOMEM = CApi.SQLITE_NOMEM;
|
||||
public static final int READONLY = CApi.SQLITE_READONLY;
|
||||
public static final int INTERRUPT = CApi.SQLITE_INTERRUPT;
|
||||
public static final int IOERR = CApi.SQLITE_IOERR;
|
||||
public static final int CORRUPT = CApi.SQLITE_CORRUPT;
|
||||
public static final int NOTFOUND = CApi.SQLITE_NOTFOUND;
|
||||
public static final int FULL = CApi.SQLITE_FULL;
|
||||
public static final int CANTOPEN = CApi.SQLITE_CANTOPEN;
|
||||
public static final int PROTOCOL = CApi.SQLITE_PROTOCOL;
|
||||
public static final int EMPTY = CApi.SQLITE_EMPTY;
|
||||
public static final int SCHEMA = CApi.SQLITE_SCHEMA;
|
||||
public static final int TOOBIG = CApi.SQLITE_TOOBIG;
|
||||
public static final int CONSTRAINT = CApi. SQLITE_CONSTRAINT;
|
||||
public static final int MISMATCH = CApi.SQLITE_MISMATCH;
|
||||
public static final int MISUSE = CApi.SQLITE_MISUSE;
|
||||
public static final int NOLFS = CApi.SQLITE_NOLFS;
|
||||
public static final int AUTH = CApi.SQLITE_AUTH;
|
||||
public static final int FORMAT = CApi.SQLITE_FORMAT;
|
||||
public static final int RANGE = CApi.SQLITE_RANGE;
|
||||
public static final int NOTADB = CApi.SQLITE_NOTADB;
|
||||
public static final int NOTICE = CApi.SQLITE_NOTICE;
|
||||
public static final int WARNING = CApi.SQLITE_WARNING;
|
||||
public static final int ROW = CApi.SQLITE_ROW;
|
||||
public static final int DONE = CApi.SQLITE_DONE;
|
||||
public static final int ERROR_MISSING_COLLSEQ = CApi.SQLITE_ERROR_MISSING_COLLSEQ;
|
||||
public static final int ERROR_RETRY = CApi.SQLITE_ERROR_RETRY;
|
||||
public static final int ERROR_SNAPSHOT = CApi.SQLITE_ERROR_SNAPSHOT;
|
||||
public static final int IOERR_READ = CApi.SQLITE_IOERR_READ;
|
||||
public static final int IOERR_SHORT_READ = CApi.SQLITE_IOERR_SHORT_READ;
|
||||
public static final int IOERR_WRITE = CApi.SQLITE_IOERR_WRITE;
|
||||
public static final int IOERR_FSYNC = CApi.SQLITE_IOERR_FSYNC;
|
||||
public static final int IOERR_DIR_FSYNC = CApi.SQLITE_IOERR_DIR_FSYNC;
|
||||
public static final int IOERR_TRUNCATE = CApi.SQLITE_IOERR_TRUNCATE;
|
||||
public static final int IOERR_FSTAT = CApi.SQLITE_IOERR_FSTAT;
|
||||
public static final int IOERR_UNLOCK = CApi.SQLITE_IOERR_UNLOCK;
|
||||
public static final int IOERR_RDLOCK = CApi.SQLITE_IOERR_RDLOCK;
|
||||
public static final int IOERR_DELETE = CApi.SQLITE_IOERR_DELETE;
|
||||
public static final int IOERR_BLOCKED = CApi.SQLITE_IOERR_BLOCKED;
|
||||
public static final int IOERR_NOMEM = CApi.SQLITE_IOERR_NOMEM;
|
||||
public static final int IOERR_ACCESS = CApi.SQLITE_IOERR_ACCESS;
|
||||
public static final int IOERR_CHECKRESERVEDLOCK = CApi.SQLITE_IOERR_CHECKRESERVEDLOCK;
|
||||
public static final int IOERR_LOCK = CApi.SQLITE_IOERR_LOCK;
|
||||
public static final int IOERR_CLOSE = CApi.SQLITE_IOERR_CLOSE;
|
||||
public static final int IOERR_DIR_CLOSE = CApi.SQLITE_IOERR_DIR_CLOSE;
|
||||
public static final int IOERR_SHMOPEN = CApi.SQLITE_IOERR_SHMOPEN;
|
||||
public static final int IOERR_SHMSIZE = CApi.SQLITE_IOERR_SHMSIZE;
|
||||
public static final int IOERR_SHMLOCK = CApi.SQLITE_IOERR_SHMLOCK;
|
||||
public static final int IOERR_SHMMAP = CApi.SQLITE_IOERR_SHMMAP;
|
||||
public static final int IOERR_SEEK = CApi.SQLITE_IOERR_SEEK;
|
||||
public static final int IOERR_DELETE_NOENT = CApi.SQLITE_IOERR_DELETE_NOENT;
|
||||
public static final int IOERR_MMAP = CApi.SQLITE_IOERR_MMAP;
|
||||
public static final int IOERR_GETTEMPPATH = CApi.SQLITE_IOERR_GETTEMPPATH;
|
||||
public static final int IOERR_CONVPATH = CApi.SQLITE_IOERR_CONVPATH;
|
||||
public static final int IOERR_VNODE = CApi.SQLITE_IOERR_VNODE;
|
||||
public static final int IOERR_AUTH = CApi.SQLITE_IOERR_AUTH;
|
||||
public static final int IOERR_BEGIN_ATOMIC = CApi.SQLITE_IOERR_BEGIN_ATOMIC;
|
||||
public static final int IOERR_COMMIT_ATOMIC = CApi.SQLITE_IOERR_COMMIT_ATOMIC;
|
||||
public static final int IOERR_ROLLBACK_ATOMIC = CApi.SQLITE_IOERR_ROLLBACK_ATOMIC;
|
||||
public static final int IOERR_DATA = CApi.SQLITE_IOERR_DATA;
|
||||
public static final int IOERR_CORRUPTFS = CApi.SQLITE_IOERR_CORRUPTFS;
|
||||
public static final int LOCKED_SHAREDCACHE = CApi.SQLITE_LOCKED_SHAREDCACHE;
|
||||
public static final int LOCKED_VTAB = CApi.SQLITE_LOCKED_VTAB;
|
||||
public static final int BUSY_RECOVERY = CApi.SQLITE_BUSY_RECOVERY;
|
||||
public static final int BUSY_SNAPSHOT = CApi.SQLITE_BUSY_SNAPSHOT;
|
||||
public static final int BUSY_TIMEOUT = CApi.SQLITE_BUSY_TIMEOUT;
|
||||
public static final int CANTOPEN_NOTEMPDIR = CApi.SQLITE_CANTOPEN_NOTEMPDIR;
|
||||
public static final int CANTOPEN_ISDIR = CApi.SQLITE_CANTOPEN_ISDIR;
|
||||
public static final int CANTOPEN_FULLPATH = CApi.SQLITE_CANTOPEN_FULLPATH;
|
||||
public static final int CANTOPEN_CONVPATH = CApi.SQLITE_CANTOPEN_CONVPATH;
|
||||
public static final int CANTOPEN_SYMLINK = CApi.SQLITE_CANTOPEN_SYMLINK;
|
||||
public static final int CORRUPT_VTAB = CApi.SQLITE_CORRUPT_VTAB;
|
||||
public static final int CORRUPT_SEQUENCE = CApi.SQLITE_CORRUPT_SEQUENCE;
|
||||
public static final int CORRUPT_INDEX = CApi.SQLITE_CORRUPT_INDEX;
|
||||
public static final int READONLY_RECOVERY = CApi.SQLITE_READONLY_RECOVERY;
|
||||
public static final int READONLY_CANTLOCK = CApi.SQLITE_READONLY_CANTLOCK;
|
||||
public static final int READONLY_ROLLBACK = CApi.SQLITE_READONLY_ROLLBACK;
|
||||
public static final int READONLY_DBMOVED = CApi.SQLITE_READONLY_DBMOVED;
|
||||
public static final int READONLY_CANTINIT = CApi.SQLITE_READONLY_CANTINIT;
|
||||
public static final int READONLY_DIRECTORY = CApi.SQLITE_READONLY_DIRECTORY;
|
||||
public static final int ABORT_ROLLBACK = CApi.SQLITE_ABORT_ROLLBACK;
|
||||
public static final int CONSTRAINT_CHECK = CApi.SQLITE_CONSTRAINT_CHECK;
|
||||
public static final int CONSTRAINT_COMMITHOOK = CApi.SQLITE_CONSTRAINT_COMMITHOOK;
|
||||
public static final int CONSTRAINT_FOREIGNKEY = CApi.SQLITE_CONSTRAINT_FOREIGNKEY;
|
||||
public static final int CONSTRAINT_FUNCTION = CApi.SQLITE_CONSTRAINT_FUNCTION;
|
||||
public static final int CONSTRAINT_NOTNULL = CApi.SQLITE_CONSTRAINT_NOTNULL;
|
||||
public static final int CONSTRAINT_PRIMARYKEY = CApi.SQLITE_CONSTRAINT_PRIMARYKEY;
|
||||
public static final int CONSTRAINT_TRIGGER = CApi.SQLITE_CONSTRAINT_TRIGGER;
|
||||
public static final int CONSTRAINT_UNIQUE = CApi.SQLITE_CONSTRAINT_UNIQUE;
|
||||
public static final int CONSTRAINT_VTAB = CApi.SQLITE_CONSTRAINT_VTAB;
|
||||
public static final int CONSTRAINT_ROWID = CApi.SQLITE_CONSTRAINT_ROWID;
|
||||
public static final int CONSTRAINT_PINNED = CApi.SQLITE_CONSTRAINT_PINNED;
|
||||
public static final int CONSTRAINT_DATATYPE = CApi.SQLITE_CONSTRAINT_DATATYPE;
|
||||
public static final int NOTICE_RECOVER_WAL = CApi.SQLITE_NOTICE_RECOVER_WAL;
|
||||
public static final int NOTICE_RECOVER_ROLLBACK = CApi.SQLITE_NOTICE_RECOVER_ROLLBACK;
|
||||
public static final int WARNING_AUTOINDEX = CApi.SQLITE_WARNING_AUTOINDEX;
|
||||
public static final int AUTH_USER = CApi.SQLITE_AUTH_USER;
|
||||
public static final int OK_LOAD_PERMANENTLY = CApi.SQLITE_OK_LOAD_PERMANENTLY;
|
||||
|
||||
public static final int OPEN_READWRITE = CApi.SQLITE_OPEN_READWRITE;
|
||||
public static final int OPEN_CREATE = CApi.SQLITE_OPEN_CREATE;
|
||||
public static final int OPEN_EXRESCODE = CApi.SQLITE_OPEN_EXRESCODE;
|
||||
@ -108,10 +213,6 @@ public final class Sqlite implements AutoCloseable {
|
||||
/* We elide the UTF16_ALIGNED from this interface because it
|
||||
is irrelevant for the Java interface. */
|
||||
|
||||
public static final int DONE = CApi.SQLITE_DONE;
|
||||
public static final int BUSY = CApi.SQLITE_BUSY;
|
||||
public static final int LOCKED = CApi.SQLITE_LOCKED;
|
||||
|
||||
public static final int DENY = CApi.SQLITE_DENY;
|
||||
public static final int IGNORE = CApi.SQLITE_IGNORE;
|
||||
public static final int CREATE_INDEX = CApi.SQLITE_CREATE_INDEX;
|
||||
@ -1482,4 +1583,34 @@ public final class Sqlite implements AutoCloseable {
|
||||
}
|
||||
CApi.sqlite3_progress_handler( thisDb(), n, phc );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Callback for use with setAuthorizer().
|
||||
*/
|
||||
public interface Authorizer {
|
||||
/**
|
||||
Must function as described for the C-level
|
||||
sqlite3_set_authorizer() callback. If it throws, the error is
|
||||
converted to a db-level error and the exception is suppressed.
|
||||
*/
|
||||
int call(int opId, String s1, String s2, String s3, String s4);
|
||||
}
|
||||
|
||||
/**
|
||||
Analog to sqlite3_set_authorizer(), this sets the current
|
||||
authorizer callback, or clears if it passed null.
|
||||
*/
|
||||
public void setAuthorizer( Authorizer a ) {
|
||||
org.sqlite.jni.capi.AuthorizerCallback ac = null;
|
||||
if( null!=a ){
|
||||
ac = new org.sqlite.jni.capi.AuthorizerCallback(){
|
||||
@Override public int call(int opId, String s1, String s2, String s3, String s4){
|
||||
return a.call(opId, s1, s2, s3, s4);
|
||||
}
|
||||
};
|
||||
}
|
||||
checkRc( CApi.sqlite3_set_authorizer( thisDb(), ac ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -888,6 +888,30 @@ public class Tester2 implements Runnable {
|
||||
db.close();
|
||||
}
|
||||
|
||||
private void testAuthorizer(){
|
||||
final Sqlite db = openDb();
|
||||
final ValueHolder<Integer> counter = new ValueHolder<>(0);
|
||||
final ValueHolder<Integer> authRc = new ValueHolder<>(0);
|
||||
final Sqlite.Authorizer auth = new Sqlite.Authorizer(){
|
||||
public int call(int op, String s0, String s1, String s2, String s3){
|
||||
++counter.value;
|
||||
//outln("xAuth(): "+s0+" "+s1+" "+s2+" "+s3);
|
||||
return authRc.value;
|
||||
}
|
||||
};
|
||||
execSql(db, "CREATE TABLE t(a); INSERT INTO t(a) VALUES('a'),('b'),('c')");
|
||||
db.setAuthorizer(auth);
|
||||
execSql(db, "UPDATE t SET a=1");
|
||||
affirm( 1 == counter.value );
|
||||
authRc.value = Sqlite.DENY;
|
||||
int rc = execSql(db, false, "UPDATE t SET a=2");
|
||||
affirm( Sqlite.AUTH==rc );
|
||||
db.setAuthorizer(null);
|
||||
rc = execSql(db, false, "UPDATE t SET a=2");
|
||||
affirm( 0==rc );
|
||||
db.close();
|
||||
}
|
||||
|
||||
private void runTests(boolean fromThread) throws Exception {
|
||||
List<java.lang.reflect.Method> mlist = testMethods;
|
||||
affirm( null!=mlist );
|
||||
|
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Add\sprogress-handler\ssupport\sto\sJNI\swrapper1.\sCorrect\sthe\sreturn\stype\sof\sthe\sextended_result_codes()\sJNI\sbinding\sand\sexpose\sit\sto\swrapper1.
|
||||
D 2023-11-05T01:39:29.450
|
||||
C Add\sauthorizer\ssupport\sto\s\sJNI\swrapper1.
|
||||
D 2023-11-05T01:55:20.977
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -248,7 +248,7 @@ F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 0b1879852707f752512d4db9d7
|
||||
F ext/jni/src/org/sqlite/jni/annotation/package-info.java 977b374aed9d5853cbf3438ba3b0940abfa2ea4574f702a2448ee143b98ac3ca
|
||||
F ext/jni/src/org/sqlite/jni/capi/AbstractCollationCallback.java 1afa90d3f236f79cc7fcd2497e111992644f7596fbc8e8bcf7f1908ae00acd6c
|
||||
F ext/jni/src/org/sqlite/jni/capi/AggregateFunction.java 0b72cdff61533b564d65b63418129656daa9a9f30e7e7be982bd5ab394b1dbd0
|
||||
F ext/jni/src/org/sqlite/jni/capi/AuthorizerCallback.java 7ed409d5449684616cc924534e22ff6b07d361f12ad904b69ecb10e0568a8013
|
||||
F ext/jni/src/org/sqlite/jni/capi/AuthorizerCallback.java c045a5b47e02bb5f1af91973814a905f12048c428a3504fbc5266d1c1be3de5a
|
||||
F ext/jni/src/org/sqlite/jni/capi/AutoExtensionCallback.java 74cc4998a73d6563542ecb90804a3c4f4e828cb4bd69e61226d1a51f4646e759
|
||||
F ext/jni/src/org/sqlite/jni/capi/BusyHandlerCallback.java 7b8e19810c42b0ad21a04b5d8c804b32ee5905d137148703f16a75b612c380ca
|
||||
F ext/jni/src/org/sqlite/jni/capi/CApi.java a6d4fdd35e4fcfe95c61e343eb389cfaab3d5166e9670730aef14240a982b97b
|
||||
@ -269,7 +269,7 @@ F ext/jni/src/org/sqlite/jni/capi/SQLFunction.java 0d1e9afc9ff8a2adb94a155b72385
|
||||
F ext/jni/src/org/sqlite/jni/capi/SQLTester.java 09bee15aa0eedac68d767ae21d9a6a62a31ade59182a3ccbf036d6463d9e30b1
|
||||
F ext/jni/src/org/sqlite/jni/capi/ScalarFunction.java 93b9700fca4c68075ccab12fe0fbbc76c91cafc9f368e835b9bd7cd7732c8615
|
||||
F ext/jni/src/org/sqlite/jni/capi/TableColumnMetadata.java addf120e0e76e5be1ff2260daa7ce305ff9b5fafd64153a7a28e9d8f000a815f
|
||||
F ext/jni/src/org/sqlite/jni/capi/Tester1.java 909ebd23111762c878116ebacf73a848c8323fb46e8128eb3d99a85d48905444
|
||||
F ext/jni/src/org/sqlite/jni/capi/Tester1.java 89d3c4b2ffa9a7d3a125daae66167d29f64058702f65254b7d4a721e3868bd1b
|
||||
F ext/jni/src/org/sqlite/jni/capi/TraceV2Callback.java 0a25e117a0daae3394a77f24713e36d7b44c67d6e6d30e9e1d56a63442eef723
|
||||
F ext/jni/src/org/sqlite/jni/capi/UpdateHookCallback.java c8bdf7848e6599115d601bcc9427ff902cb33129b9be32870ac6808e04b6ae56
|
||||
F ext/jni/src/org/sqlite/jni/capi/ValueHolder.java 22d365746a78c5cd7ae10c39444eb7bbf1a819aad4bb7eb77b1edc47773a3950
|
||||
@ -296,9 +296,9 @@ F ext/jni/src/org/sqlite/jni/test-script-interpreter.md f9f25126127045d051e918fe
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/AggregateFunction.java d5c108b02afd3c63c9e5e53f71f85273c1bfdc461ae526e0a0bb2b25e4df6483
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/ScalarFunction.java 43c43adfb7866098aadaaca1620028a6ec82d5193149970019b1cce9eb59fb03
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/SqlFunction.java 2833afdb9af5c1949bb35f4c926a5351fba9d1cdf0996864caa7b47827a346c7
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/Sqlite.java 923c885609ca9e6793636fc17787d0058c80ce1d7ba5a69eb40e68cc299892d1
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/Sqlite.java 2397e70955de15f8fb65a7ed421365f018c099d16b8080f81c7553e4dae3d44f
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/SqliteException.java 982538ddb4c0719ef87dfa664cd137b09890b546029a7477810bd64d4c47ee35
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/Tester2.java 822cf3d66beb1efcac1792c8652cbebb80ae998275a33337de46fde1670e0008
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/Tester2.java 199b9fb56e06f808d5856494ca8840e9004ff939f27c7c6fda9a60858144f95d
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/ValueHolder.java 7b89a7391f771692c5b83b0a5b86266abe8d59f1c77d7a0eccc9b79f259d79af
|
||||
F ext/jni/src/org/sqlite/jni/wrapper1/WindowFunction.java c7d1452f9ff26175b3c19bbf273116cc2846610af68e01756d755f037fe7319f
|
||||
F ext/jni/src/tests/000-000-sanity.test c3427a0e0ac84d7cbe4c95fdc1cd4b61f9ddcf43443408f3000139478c4dc745
|
||||
@ -2142,8 +2142,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 6c584cf27179d16deee84e9699493cf29bebef123fa2a7493aad0324bead1618
|
||||
R dafa52fdba2c999e04b851e5ec6214ab
|
||||
P 6c0acfdce2160d8db261a59677cec571b6abc333481525b1ec975d98e88bec88
|
||||
R d2d319f241ba72795b6add1f6b68fc9e
|
||||
U stephan
|
||||
Z 824d9a7ed24ad4091f85bc7e5264c033
|
||||
Z a73e3653c86a5ad585af4f9360f1181a
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
6c0acfdce2160d8db261a59677cec571b6abc333481525b1ec975d98e88bec88
|
||||
773f9873865b5277a6a682c4695f216bfe1ec05ed5e5a2a70aaa451934ba2dc0
|
Loading…
Reference in New Issue
Block a user